22
33require_once __DIR__ .'/../../../bootstrap/unit.php ' ;
44
5- function removeTrailingSpaces ( string $ output ): string
5+ class lime_no_colorizer extends lime_colorizer
66{
7- return preg_replace ("/ * \n/ " , "\n" , $ output );
7+ public function __construct ()
8+ {
9+ }
810}
911
10- function whenExecuteHarnessWithFilesWillHaveResultAndOutput ( $ test , $ files , $ expectedOverallSucceed , $ expectedOutput , $ message )
12+ class lime_harnessTest
1113{
12- $ harness = new lime_harness ();
13- $ harness ->output ->colorizer = new lime_no_colorizer ();
14+ private $ test ;
1415
15- $ harness ->register ($ files );
16+ public function __construct ()
17+ {
18+ $ this ->test = new lime_test ();
19+ }
1620
17- ob_start ();
18- $ allTestsSucceed = $ harness -> run ();
19- $ output = ob_get_clean ( );
21+ private function whenExecuteHarnessWithFilesWillHaveResultAndOutput ( $ message , $ files , $ expectedOverallSucceed , $ expectedOutput )
22+ {
23+ $ this -> test -> info ( $ message );
2024
21- $ test -> is ( $ expectedOverallSucceed , $ allTestsSucceed , $ message );
25+ $ harness = $ this -> makeHarnessWithFiles ( $ files );
2226
23- $ test ->is (removeTrailingSpaces ($ output ), $ expectedOutput , 'test harness result output ' );
24- }
27+ ob_start ();
28+ $ allTestsSucceed = $ harness ->run ();
29+ $ output = ob_get_clean ();
2530
26- class lime_no_colorizer extends lime_colorizer
27- {
28- public function __construct ()
31+ $ this ->test ->is ($ expectedOverallSucceed , $ allTestsSucceed , 'overall test ' .($ expectedOverallSucceed ? 'succeed ' : 'failed ' ));
32+
33+ $ this ->test ->is ($ this ->removeTrailingSpaces ($ output ), $ expectedOutput , 'test harness result output ' );
34+ }
35+
36+ private function makeHarnessWithFiles ($ files ): lime_harness
2937 {
38+ $ harness = new lime_harness ();
39+ $ harness ->output ->colorizer = new lime_no_colorizer ();
40+
41+ $ harness ->register ($ files );
42+
43+ return $ harness ;
3044 }
31- }
3245
33- $ test = new lime_test (12 );
34-
35- $ files = [
36- __DIR__ .'/fixtures/failed.php ' ,
37- __DIR__ .'/fixtures/failed_with_plan_less_than_total.php ' ,
38- __DIR__ .'/fixtures/failed_with_plan_more_than_total.php ' ,
39- __DIR__ .'/fixtures/pass.php ' ,
40- __DIR__ .'/fixtures/pass_with_plan_less_than_total.php ' ,
41- __DIR__ .'/fixtures/pass_with_plan_more_than_total.php ' ,
42- ];
43- $ expectedOverallSucceed = false ;
44- $ expectedOutput = <<<'EOF'
45- test/unit/vendor/lime/fixtures/failed................................not ok
46- Failed tests: 1
47- test/unit/vendor/lime/fixtures/failed_with_plan_less_than_total......not ok
48- Looks like you planned 1 test but ran 1 extra.
49- Failed tests: 1
50- test/unit/vendor/lime/fixtures/failed_with_plan_more_than_total......not ok
51- Looks like you planned 2 tests but only ran 1.
52- Failed tests: 1
53- test/unit/vendor/lime/fixtures/pass..................................ok
54- test/unit/vendor/lime/fixtures/pass_with_plan_less_than_total........dubious
55- Test returned status 255
56- Looks like you planned 1 test but ran 1 extra.
57- test/unit/vendor/lime/fixtures/pass_with_plan_more_than_total........dubious
58- Test returned status 255
59- Looks like you planned 2 tests but only ran 1.
60- Failed Test Stat Total Fail Errors List of Failed
61- --------------------------------------------------------------------------
62- it/vendor/lime/fixtures/failed 1 1 1 0 1
63- iled_with_plan_less_than_total 1 2 1 0 1
64- iled_with_plan_more_than_total 1 1 1 0 1
65- pass_with_plan_less_than_total 255 2 0 0
66- pass_with_plan_more_than_total 255 1 0 0
67- Failed 5/6 test scripts, 16.67% okay. 5/10 subtests failed, 50.00% okay.
46+ private function removeTrailingSpaces (string $ output ): string
47+ {
48+ return preg_replace ("/ * \n/ " , "\n" , $ output );
49+ }
6850
69- EOF;
70- $ message = 'with at least one failed test file will fail the overall test suite ' ;
71- whenExecuteHarnessWithFilesWillHaveResultAndOutput ($ test , $ files , $ expectedOverallSucceed , $ expectedOutput , $ message );
51+ public function run (): void
52+ {
53+ foreach ($ this ->provideTestCases () as $ parameters ) {
54+ $ this ->whenExecuteHarnessWithFilesWillHaveResultAndOutput (...$ parameters );
55+ }
56+ }
7257
58+ private function provideTestCases ()
59+ {
60+ yield [
61+ /* name */ 'with all tests passes without error and exception will succeed the overall test suite ' ,
62+ /* files */ [
63+ __DIR__ .'/fixtures/pass.php ' ,
64+ ],
65+ /* expectedOverallSucceed */ true ,
66+ /* expectedOutput */ <<<'EOF'
67+ test/unit/vendor/lime/fixtures/pass..................................ok
68+ All tests successful.
69+ Files=1, Tests=1
7370
74- $ files = [__DIR__ .'/fixtures/pass_with_plan_less_than_total.php ' ];
75- $ expectedOverallSucceed = false ;
76- $ expectedOutput = <<<'EOF'
71+ EOF
72+ ];
73+
74+ yield [
75+ /* name */ 'with at least one test file that not follow the plan will fail the overall test suite ' ,
76+ /* files */ [
77+ __DIR__ .'/fixtures/pass_with_plan_less_than_total.php ' ,
78+ ],
79+ /* expectedOverallSucceed */ false ,
80+ /* expectedOutput */ <<<'EOF'
7781test/unit/vendor/lime/fixtures/pass_with_plan_less_than_total........dubious
7882 Test returned status 255
7983 Looks like you planned 1 test but ran 1 extra.
@@ -82,14 +86,16 @@ public function __construct()
8286pass_with_plan_less_than_total 255 2 0 0
8387Failed 1/1 test scripts, 0.00% okay. 0/2 subtests failed, 100.00% okay.
8488
85- EOF;
86- $ message = 'with at least one test file that not follow the plan will fail the overall test suite ' ;
87- whenExecuteHarnessWithFilesWillHaveResultAndOutput ($ test , $ files , $ expectedOverallSucceed , $ expectedOutput , $ message );
88-
89+ EOF
90+ ];
8991
90- $ files = [__DIR__ .'/fixtures/pass_with_one_error.php ' ];
91- $ expectedOverallSucceed = false ;
92- $ expectedOutput = <<<'EOF'
92+ yield [
93+ /* name */ 'with at least one error will fail the overall test suite ' ,
94+ /* files */ [
95+ __DIR__ .'/fixtures/pass_with_one_error.php ' ,
96+ ],
97+ /* expectedOverallSucceed */ false ,
98+ /* expectedOutput */ <<<'EOF'
9399test/unit/vendor/lime/fixtures/pass_with_one_error...................errors
94100 Errors:
95101 - Notice: some user error message
@@ -98,14 +104,16 @@ public function __construct()
98104e/fixtures/pass_with_one_error 1 1 0 1
99105Failed 1/1 test scripts, 0.00% okay. 0/1 subtests failed, 100.00% okay.
100106
101- EOF;
102- $ message = 'with at least one error will fail the overall test suite ' ;
103- whenExecuteHarnessWithFilesWillHaveResultAndOutput ($ test , $ files , $ expectedOverallSucceed , $ expectedOutput , $ message );
104-
107+ EOF
108+ ];
105109
106- $ files = [__DIR__ .'/fixtures/pass_with_one_throw_exception.php ' ];
107- $ expectedOverallSucceed = false ;
108- $ expectedOutput = <<<'EOF'
110+ yield [
111+ /* name */ 'with at least one thrown Exception will fail the overall test suite ' ,
112+ /* files */ [
113+ __DIR__ .'/fixtures/pass_with_one_throw_exception.php ' ,
114+ ],
115+ /* expectedOverallSucceed */ false ,
116+ /* expectedOutput */ <<<'EOF'
109117test/unit/vendor/lime/fixtures/pass_with_one_throw_exception.........errors
110118 Errors:
111119 - LogicException: some exception message
@@ -114,26 +122,16 @@ public function __construct()
114122/pass_with_one_throw_exception 1 0 0 1
115123Failed 1/1 test scripts, 0.00% okay. 0/0 subtests failed, 0.00% okay.
116124
117- EOF;
118- $ message = 'with at least one thrown Exception will fail the overall test suite ' ;
119- whenExecuteHarnessWithFilesWillHaveResultAndOutput ($ test , $ files , $ expectedOverallSucceed , $ expectedOutput , $ message );
120-
121-
122- $ files = [__DIR__ .'/fixtures/pass.php ' ];
123- $ expectedOverallSucceed = true ;
124- $ expectedOutput = <<<'EOF'
125- test/unit/vendor/lime/fixtures/pass..................................ok
126- All tests successful.
127- Files=1, Tests=1
125+ EOF
126+ ];
128127
129- EOF;
130- $ message = 'with all tests passes without error and exception will succeed the overall test suite ' ;
131- whenExecuteHarnessWithFilesWillHaveResultAndOutput ($ test , $ files , $ expectedOverallSucceed , $ expectedOutput , $ message );
132-
133-
134- $ files = [__DIR__ .'/fixtures/pass_with_one_parse_error.php ' ];
135- $ expectedOverallSucceed = false ;
136- $ expectedOutput = <<<'EOF'
128+ yield [
129+ /* name */ 'with parse error will fail the overall test suite ' ,
130+ /* files */ [
131+ __DIR__ .'/fixtures/pass_with_one_parse_error.php ' ,
132+ ],
133+ /* expectedOverallSucceed */ false ,
134+ /* expectedOutput */ <<<'EOF'
137135test/unit/vendor/lime/fixtures/pass_with_one_parse_error.............errors
138136 Errors:
139137 - Missing test report. It is probably due to a Parse error.
@@ -142,6 +140,48 @@ public function __construct()
142140ures/pass_with_one_parse_error 255 0 0 1
143141Failed 1/1 test scripts, 0.00% okay. 0/0 subtests failed, 0.00% okay.
144142
145- EOF;
146- $ message = 'with parse error will fail the overall test suite ' ;
147- whenExecuteHarnessWithFilesWillHaveResultAndOutput ($ test , $ files , $ expectedOverallSucceed , $ expectedOutput , $ message );
143+ EOF
144+ ];
145+
146+ yield [
147+ /* name */ 'with at least one failed test file will fail the overall test suite ' ,
148+ /* files */ [
149+ __DIR__ .'/fixtures/failed.php ' ,
150+ __DIR__ .'/fixtures/failed_with_plan_less_than_total.php ' ,
151+ __DIR__ .'/fixtures/failed_with_plan_more_than_total.php ' ,
152+ __DIR__ .'/fixtures/pass.php ' ,
153+ __DIR__ .'/fixtures/pass_with_plan_less_than_total.php ' ,
154+ __DIR__ .'/fixtures/pass_with_plan_more_than_total.php ' ,
155+ ],
156+ /* expectedOverallSucceed */ false ,
157+ /* expectedOutput */ <<<'EOF'
158+ test/unit/vendor/lime/fixtures/failed................................not ok
159+ Failed tests: 1
160+ test/unit/vendor/lime/fixtures/failed_with_plan_less_than_total......not ok
161+ Looks like you planned 1 test but ran 1 extra.
162+ Failed tests: 1
163+ test/unit/vendor/lime/fixtures/failed_with_plan_more_than_total......not ok
164+ Looks like you planned 2 tests but only ran 1.
165+ Failed tests: 1
166+ test/unit/vendor/lime/fixtures/pass..................................ok
167+ test/unit/vendor/lime/fixtures/pass_with_plan_less_than_total........dubious
168+ Test returned status 255
169+ Looks like you planned 1 test but ran 1 extra.
170+ test/unit/vendor/lime/fixtures/pass_with_plan_more_than_total........dubious
171+ Test returned status 255
172+ Looks like you planned 2 tests but only ran 1.
173+ Failed Test Stat Total Fail Errors List of Failed
174+ --------------------------------------------------------------------------
175+ it/vendor/lime/fixtures/failed 1 1 1 0 1
176+ iled_with_plan_less_than_total 1 2 1 0 1
177+ iled_with_plan_more_than_total 1 1 1 0 1
178+ pass_with_plan_less_than_total 255 2 0 0
179+ pass_with_plan_more_than_total 255 1 0 0
180+ Failed 5/6 test scripts, 16.67% okay. 5/10 subtests failed, 50.00% okay.
181+
182+ EOF
183+ ];
184+ }
185+ }
186+
187+ (new lime_harnessTest ())->run ();
0 commit comments