FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
phpbench/tests/Example/CommandsTest.php at program-executor · phpbench/phpbench · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
phpbench
/
phpbench
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
133
Star
2k
Code
Issues
28
Pull requests
10
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
phpbench
/
tests
/
Example
/
CommandsTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
108 lines (94 loc) · 3.36 KB
Breadcrumbs
phpbench
/
tests
/
Example
/
CommandsTest.php
Copy path
File metadata and controls
108 lines (94 loc) · 3.36 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
<?php
namespace
PhpBench
\
Tests
\
Example
;
use
Generator
;
use
PhpBench
\
Console
\
Application
;
use
PhpBench
\
Extension
\
ConsoleExtension
;
use
PhpBench
\
Extension
\
RunnerExtension
;
use
PhpBench
\
PhpBench
;
use
PhpBench
\
Tests
\
IntegrationTestCase
;
use
PhpBench
\
Tests
\
Util
\
Approval
;
use
RuntimeException
;
use
Symfony
\
Component
\
Console
\
Input
\
StringInput
;
use
function
json_last_error_msg
;
class
CommandsTest
extends
IntegrationTestCase
{
protected
function
setUp
():
void
{
$
this
->
workspace
()->
reset
();
}
/**
* @dataProvider provideCommand
*/
public
function
testCommand
(
string
$
path
):
void
{
$
this
->
createExample
();
$
approval
= Approval::
create
(
$
path
,
3
);
$
commands
=
array_map
(
function
(
string
$
command
) {
if
(
0
!==
strpos
(
$
command
,
'
phpbench
'
)) {
throw
new
RuntimeException
(
sprintf
(
'
Command test command must start with `phpbench`, got "%s"
'
,
$
command
));
}
return
substr
(
$
command
,
strlen
(
'
phpbench
'
));
},
explode
(
"\n"
,
trim
(
$
approval
->
getSection
(
1
))));
$
jsonString
=
$
approval
->
getSection
(
0
);
$
decoded
=
json_decode
(
$
jsonString
,
true
);
if
(
null
===
$
decoded
) {
throw
new
RuntimeException
(
sprintf
(
'
Could not decode JSON: %s: %s
'
,
$
jsonString
,
json_last_error_msg
()));
}
$
this
->
workspace
()->
put
(
'
phpbench.json
'
,
json_encode
(
array_merge
([
RunnerExtension::
PARAM_ENABLED_PROVIDERS
=> [],
ConsoleExtension::
PARAM_OUTPUT_STREAM
=>
$
this
->
workspace
()->
path
(
'
output
'
),
ConsoleExtension::
PARAM_ERROR_STREAM
=>
'
php://temp
'
,
],
$
decoded
)));
foreach
(
$
commands
as
$
command
) {
$
input
=
new
StringInput
(
$
command
);
$
container
= PhpBench::
loadContainer
(
$
input
,
$
this
->
workspace
()->
path
());
$
application
=
$
container
->
get
(Application::class);
assert
(
$
application
instanceof
Application);
$
application
->
setAutoExit
(
false
);
$
application
->
run
(
$
input
,
$
container
->
get
(ConsoleExtension::
SERVICE_OUTPUT_STD
));
}
$
output
=
$
this
->
workspace
()->
getContents
(
'
output
'
);
// hack to ignore the suite dates
$
output
=
preg_replace
(
'
{[0-9]{4}-[0-9]{2}-[0-9]{2}}
'
,
'
xxxx-xx-xx
'
,
$
output
);
$
output
=
preg_replace
(
'
{[0-9]{2}:[0-9]{2}:[0-9]{2}}
'
,
'
xx-xx-xx
'
,
$
output
);
$
output
=
preg_replace
(
'
{#[a-z0-9]{40}}
'
,
'
E3X6AeMdP7L9E7E0X0A7McP1L8E1EdXbAbMbP7La
'
,
$
output
);
$
output
=
str_replace
(
getcwd
(),
'
/path/to
'
,
$
output
);
$
approval
->
approve
(
$
output
);
}
/**
* @return Generator<mixed>
*/
public
function
provideCommand
():
Generator
{
/** @phpstan-ignore-next-line */
foreach
(
glob
(
__DIR__
.
'
/../../examples/Command/*
'
)
as
$
file
) {
yield
[
$
file
,
];
}
}
private
function
createExample
():
void
{
$
this
->
workspace
()->
put
(
'
NothingBench.php
'
,
<<<'EOT'
<?php
class NothingBench { public function benchNothing(): void {}}
EOT
);
$
this
->
workspace
()->
put
(
'
MultipleSubjects.php
'
,
<<<'EOT'
<?php
class MultipleSubjectBench {
public function benchSubject1(): void {}
public function benchSubject2(): void {}
public function benchSubject3(): void {}
}
EOT
);
}
}
Back
|
FazBrowse Home
|
New Git URL