FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
phpinfo/tests/TextParserTest.php at main · stechstudio/phpinfo · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
stechstudio
/
phpinfo
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
89
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
phpinfo
/
tests
/
TextParserTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
166 lines (127 loc) · 4.93 KB
Breadcrumbs
phpinfo
/
tests
/
TextParserTest.php
Copy path
File metadata and controls
166 lines (127 loc) · 4.93 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
use
STS
\
Phpinfo
\
Info
;
use
STS
\
Phpinfo
\
Parsers
\
TextParser
;
use
STS
\
Phpinfo
\
PhpInfo
;
function
textInfo
():
PhpInfo
{
static
$
info
=
null
;
return
$
info
??= Info::
fromText
(
file_get_contents
(
__DIR__
.
'
/fixtures/cli-php83.txt
'
)
);
}
it
(
'
can detect text content
'
,
function
() {
$
text
=
file_get_contents
(
__DIR__
.
'
/fixtures/cli-php83.txt
'
);
expect
(TextParser::
canParse
(
$
text
))->
toBeTrue
()
->
and
(TextParser::
canParse
(
'
not phpinfo
'
))->
toBeFalse
()
->
and
(TextParser::
canParse
(
''
))->
toBeFalse
();
});
it
(
'
rejects invalid content
'
,
function
() {
Info::
fromText
(
'
not phpinfo content
'
);
})->
throws
(InvalidArgumentException::class);
it
(
'
returns phpinfo instance
'
,
function
() {
expect
(
textInfo
())->
toBeInstanceOf
(PhpInfo::class);
});
it
(
'
parses php version
'
,
function
() {
expect
(
textInfo
()->
version
())
->
not
->
toBeEmpty
()
->
toMatch
(
'
/^\d+\.\d+\.\d+/
'
);
});
it
(
'
parses modules
'
,
function
() {
$
modules
=
textInfo
()->
modules
();
expect
(
$
modules
->
count
())->
toBeGreaterThan
(
5
)
->
and
(
$
modules
->
first
()->
name
())->
toBe
(
'
General
'
);
});
it
(
'
has general module with configs
'
,
function
() {
$
general
=
textInfo
()->
module
(
'
General
'
);
expect
(
$
general
)->
not
->
toBeNull
()
->
and
(
$
general
->
configs
()->
count
())->
toBeGreaterThan
(
0
);
});
it
(
'
has case insensitive module lookup
'
,
function
() {
$
name
=
textInfo
()->
modules
()->
skip
(
1
)->
first
()->
name
();
expect
(
textInfo
()->
hasModule
(
$
name
))->
toBeTrue
()
->
and
(
textInfo
()->
hasModule
(
strtolower
(
$
name
)))->
toBeTrue
()
->
and
(
textInfo
()->
hasModule
(
strtoupper
(
$
name
)))->
toBeTrue
();
});
it
(
'
returns null for missing module
'
,
function
() {
expect
(
textInfo
()->
module
(
'
nonexistent_module_xyz
'
))->
toBeNull
()
->
and
(
textInfo
()->
hasModule
(
'
nonexistent_module_xyz
'
))->
toBeFalse
();
});
it
(
'
parses configs
'
,
function
() {
expect
(
textInfo
()->
configs
()->
count
())->
toBeGreaterThan
(
50
);
});
it
(
'
can query individual configs
'
,
function
() {
expect
(
textInfo
()->
hasConfig
(
'
System
'
))->
toBeTrue
()
->
and
(
textInfo
()->
config
(
'
System
'
))->
not
->
toBeNull
();
});
it
(
'
returns null for missing config
'
,
function
() {
expect
(
textInfo
()->
config
(
'
nonexistent_config_xyz
'
))->
toBeNull
()
->
and
(
textInfo
()->
hasConfig
(
'
nonexistent_config_xyz
'
))->
toBeFalse
();
});
it
(
'
has working convenience methods
'
,
function
() {
$
os
=
textInfo
()->
os
();
$
hostname
=
textInfo
()->
hostname
();
expect
(
$
os
)->
not
->
toBeNull
()
->
and
(
$
hostname
)->
not
->
toBeNull
()
->
and
(
textInfo
()->
config
(
'
System
'
))->
toStartWith
(
$
os
);
});
it
(
'
handles local and master values
'
,
function
() {
$
config
=
textInfo
()->
configs
()->
first
(
fn
(
$
c
) =>
$
c
->
hasMasterValue
());
if
(
$
config
) {
expect
(
textInfo
()->
config
(
$
config
->
name
(),
'
local
'
))->
not
->
toBeNull
();
}
expect
(
true
)->
toBeTrue
();
});
it
(
'
parses groups with headings
'
,
function
() {
$
groupWithHeadings
=
null
;
foreach
(
textInfo
()->
modules
()
as
$
module
) {
foreach
(
$
module
->
groups
()
as
$
group
) {
if
(
$
group
->
hasHeadings
()) {
$
groupWithHeadings
=
$
group
;
break
2
;
}
}
}
if
(
$
groupWithHeadings
) {
expect
(
$
groupWithHeadings
->
headings
()->
count
())->
toBeGreaterThan
(
0
)
->
and
(
$
groupWithHeadings
->
heading
(
0
))->
not
->
toBeNull
();
}
expect
(
true
)->
toBeTrue
();
});
it
(
'
parses credits
'
,
function
() {
$
credits
=
textInfo
()->
module
(
'
PHP Credits
'
);
expect
(
$
credits
)->
not
->
toBeNull
()
->
and
(
$
credits
->
name
())->
not
->
toBeEmpty
()
->
and
(
$
credits
->
groups
()->
count
())->
toBeGreaterThan
(
0
);
});
it
(
'
parses license
'
,
function
() {
$
license
=
textInfo
()->
module
(
'
PHP License
'
);
expect
(
$
license
)->
not
->
toBeNull
()
->
and
(
$
license
->
name
())->
not
->
toBeEmpty
()
->
and
(
$
license
->
groups
()->
count
())->
toBeGreaterThan
(
0
);
});
it
(
'
is json serializable
'
,
function
() {
$
json
=
json_encode
(
textInfo
());
$
data
=
json_decode
(
$
json
,
true
);
expect
(
$
json
)->
not
->
toBeFalse
()
->
and
(
$
data
)->
toHaveKeys
([
'
version
'
,
'
modules
'
])
->
and
(
$
data
[
'
modules
'
])->
toBeArray
()->
not
->
toBeEmpty
();
});
it
(
'
has unique module keys
'
,
function
() {
$
keys
=
textInfo
()->
modules
()->
map
(
fn
(
$
m
) =>
$
m
->
key
());
expect
(
$
keys
->
unique
()->
count
())->
toBe
(
$
keys
->
count
());
});
it
(
'
handles crlf line endings
'
,
function
() {
$
text
=
file_get_contents
(
__DIR__
.
'
/fixtures/cli-php83.txt
'
);
$
info
= Info::
fromText
(
str_replace
(
"\n"
,
"\r\n"
,
$
text
));
expect
(
$
info
->
version
())->
not
->
toBeEmpty
()
->
and
(
$
info
->
modules
()->
count
())->
toBeGreaterThan
(
5
);
});
it
(
'
produces consistent results with html parser
'
,
function
() {
$
htmlInfo
= Info::
fromHtml
(
file_get_contents
(
__DIR__
.
'
/fixtures/html-php83.html
'
)
);
expect
(
$
htmlInfo
->
version
())->
toBe
(
textInfo
()->
version
())
->
and
(
$
htmlInfo
->
module
(
'
General
'
))->
not
->
toBeNull
()
->
and
(
textInfo
()->
module
(
'
General
'
))->
not
->
toBeNull
()
->
and
(
$
htmlInfo
->
config
(
'
System
'
))->
toBe
(
textInfo
()->
config
(
'
System
'
));
});
Back
|
FazBrowse Home
|
New Git URL