From 38e62003ce638783e259d5881fedb2ca63c9b0b6 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Wed, 10 Apr 2024 00:51:00 +0200 Subject: [PATCH 1/7] fix(test): exit code of lime test -- add proof of current behaviour --- lib/vendor/lime/lime.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/vendor/lime/lime.php b/lib/vendor/lime/lime.php index c09016fb2..f3e69df13 100644 --- a/lib/vendor/lime/lime.php +++ b/lib/vendor/lime/lime.php @@ -952,8 +952,7 @@ function lime_shutdown() ); ob_start(); - // see http://trac.symfony-project.org/ticket/5437 for the explanation on the weird "cd" thing - passthru(sprintf('cd & %s %s 2>&1', escapeshellarg($this->php_cli), escapeshellarg($test_file)), $return); + $return = $this->executePhpFile($test_file); ob_end_clean(); unlink($test_file); @@ -1123,6 +1122,20 @@ public function get_failed_files() { return isset($this->stats['failed_files']) ? $this->stats['failed_files'] : array(); } + + /** + * The command fails if the path to php interpreter contains spaces. + * The only workaround is adding a "nop" command call before the quoted command. + * The weird "cd &". + * + * see http://trac.symfony-project.org/ticket/5437 + */ + public function executePhpFile(string $phpFile): int + { + passthru(sprintf('cd & %s %s 2>&1', escapeshellarg($this->php_cli), escapeshellarg($phpFile)), $return); + + return $return; + } } class lime_coverage extends lime_registration @@ -1186,8 +1199,7 @@ public function process($files) EOF; file_put_contents($tmp_file, $tmp); ob_start(); - // see http://trac.symfony-project.org/ticket/5437 for the explanation on the weird "cd" thing - passthru(sprintf('cd & %s %s 2>&1', escapeshellarg($this->harness->php_cli), escapeshellarg($tmp_file)), $return); + $return = $this->harness->executePhpFile($tmp_file); $retval = ob_get_clean(); if (0 != $return) // test exited without success From 04d0339ca0f9db4071bd263c46201a8df4c43a1c Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Wed, 10 Apr 2024 00:52:20 +0200 Subject: [PATCH 2/7] fixup! fix(test): exit code of lime test -- add proof of current behaviour --- test/unit/vendor/lime/fixtures/failed.php | 7 + .../failed_with_plan_less_than_total.php | 8 + .../failed_with_plan_more_than_total.php | 7 + test/unit/vendor/lime/fixtures/pass.php | 7 + .../lime/fixtures/pass_with_one_error.php | 13 + .../fixtures/pass_with_one_parse_error.php | 7 + .../pass_with_one_throw_exception.php | 9 + .../pass_with_plan_less_than_total.php | 8 + .../pass_with_plan_more_than_total.php | 7 + test/unit/vendor/lime/fixtures/skip.php | 7 + .../vendor/lime/fixtures/skip_with_plan.php | 7 + test/unit/vendor/lime/lime_harnessTest.php | 261 ++++++++++++++++++ test/unit/vendor/lime/lime_testTest.php | 178 ++++++++++++ test/unit/vendor/lime/tools/TestCase.php | 39 +++ .../vendor/lime/tools/lime_no_colorizer.php | 8 + 15 files changed, 573 insertions(+) create mode 100644 test/unit/vendor/lime/fixtures/failed.php create mode 100644 test/unit/vendor/lime/fixtures/failed_with_plan_less_than_total.php create mode 100644 test/unit/vendor/lime/fixtures/failed_with_plan_more_than_total.php create mode 100644 test/unit/vendor/lime/fixtures/pass.php create mode 100644 test/unit/vendor/lime/fixtures/pass_with_one_error.php create mode 100644 test/unit/vendor/lime/fixtures/pass_with_one_parse_error.php create mode 100644 test/unit/vendor/lime/fixtures/pass_with_one_throw_exception.php create mode 100644 test/unit/vendor/lime/fixtures/pass_with_plan_less_than_total.php create mode 100644 test/unit/vendor/lime/fixtures/pass_with_plan_more_than_total.php create mode 100644 test/unit/vendor/lime/fixtures/skip.php create mode 100644 test/unit/vendor/lime/fixtures/skip_with_plan.php create mode 100644 test/unit/vendor/lime/lime_harnessTest.php create mode 100644 test/unit/vendor/lime/lime_testTest.php create mode 100644 test/unit/vendor/lime/tools/TestCase.php create mode 100644 test/unit/vendor/lime/tools/lime_no_colorizer.php diff --git a/test/unit/vendor/lime/fixtures/failed.php b/test/unit/vendor/lime/fixtures/failed.php new file mode 100644 index 000000000..bd0186881 --- /dev/null +++ b/test/unit/vendor/lime/fixtures/failed.php @@ -0,0 +1,7 @@ +is(false, true); diff --git a/test/unit/vendor/lime/fixtures/failed_with_plan_less_than_total.php b/test/unit/vendor/lime/fixtures/failed_with_plan_less_than_total.php new file mode 100644 index 000000000..47e0c69f8 --- /dev/null +++ b/test/unit/vendor/lime/fixtures/failed_with_plan_less_than_total.php @@ -0,0 +1,8 @@ +is(false, true); +$test->is(true, true); diff --git a/test/unit/vendor/lime/fixtures/failed_with_plan_more_than_total.php b/test/unit/vendor/lime/fixtures/failed_with_plan_more_than_total.php new file mode 100644 index 000000000..7bf7da135 --- /dev/null +++ b/test/unit/vendor/lime/fixtures/failed_with_plan_more_than_total.php @@ -0,0 +1,7 @@ +is(false, true); diff --git a/test/unit/vendor/lime/fixtures/pass.php b/test/unit/vendor/lime/fixtures/pass.php new file mode 100644 index 000000000..93afc9a6e --- /dev/null +++ b/test/unit/vendor/lime/fixtures/pass.php @@ -0,0 +1,7 @@ +is(true, true); diff --git a/test/unit/vendor/lime/fixtures/pass_with_one_error.php b/test/unit/vendor/lime/fixtures/pass_with_one_error.php new file mode 100644 index 000000000..4491a9a80 --- /dev/null +++ b/test/unit/vendor/lime/fixtures/pass_with_one_error.php @@ -0,0 +1,13 @@ + true, +]); + +trigger_error('some user error message', E_USER_ERROR); + +$test->is(true, true); diff --git a/test/unit/vendor/lime/fixtures/pass_with_one_parse_error.php b/test/unit/vendor/lime/fixtures/pass_with_one_parse_error.php new file mode 100644 index 000000000..39535fef4 --- /dev/null +++ b/test/unit/vendor/lime/fixtures/pass_with_one_parse_error.php @@ -0,0 +1,7 @@ +is(true, true); diff --git a/test/unit/vendor/lime/fixtures/pass_with_plan_less_than_total.php b/test/unit/vendor/lime/fixtures/pass_with_plan_less_than_total.php new file mode 100644 index 000000000..13d7600b8 --- /dev/null +++ b/test/unit/vendor/lime/fixtures/pass_with_plan_less_than_total.php @@ -0,0 +1,8 @@ +is(true, true); +$test->is(true, true); diff --git a/test/unit/vendor/lime/fixtures/pass_with_plan_more_than_total.php b/test/unit/vendor/lime/fixtures/pass_with_plan_more_than_total.php new file mode 100644 index 000000000..6c0d577cc --- /dev/null +++ b/test/unit/vendor/lime/fixtures/pass_with_plan_more_than_total.php @@ -0,0 +1,7 @@ +is(true, true); diff --git a/test/unit/vendor/lime/fixtures/skip.php b/test/unit/vendor/lime/fixtures/skip.php new file mode 100644 index 000000000..215bfe70e --- /dev/null +++ b/test/unit/vendor/lime/fixtures/skip.php @@ -0,0 +1,7 @@ +skip('some skip message'); diff --git a/test/unit/vendor/lime/fixtures/skip_with_plan.php b/test/unit/vendor/lime/fixtures/skip_with_plan.php new file mode 100644 index 000000000..6447ce880 --- /dev/null +++ b/test/unit/vendor/lime/fixtures/skip_with_plan.php @@ -0,0 +1,7 @@ +skip('some skip message', $plan); diff --git a/test/unit/vendor/lime/lime_harnessTest.php b/test/unit/vendor/lime/lime_harnessTest.php new file mode 100644 index 000000000..1ba5d3890 --- /dev/null +++ b/test/unit/vendor/lime/lime_harnessTest.php @@ -0,0 +1,261 @@ +output->colorizer = new lime_no_colorizer(); + + return $harness; + } + + private function whenExecuteHarnessWithOneFileWillHaveStatusCodeAndOutput($name, $expectedOverallSucceed, $expectedOutput) + { + $this->info($name); + + $harness = $this->makeHarness(); + + $harness->register([ + __DIR__."/fixtures/$name.php", + ]); + + $this->assertHarnessWithExitStatusAndOutput($harness, $expectedOverallSucceed, $expectedOutput); + } + + private function assertHarnessWithExitStatusAndOutput(lime_harness $harness, $expectedOverallSucceed, string $expectedOutput) + { + ob_start(); + $allTestsSucceed = $harness->run(); + $output = ob_get_clean(); + + $this->is($expectedOverallSucceed, $allTestsSucceed, 'expect overall test '.($expectedOverallSucceed ? 'succeed' : 'failed')); + + $this->is($this->removeTrailingSpaces($output), $expectedOutput, 'test harness result output'); + } + + private function removeTrailingSpaces(string $output): string + { + return preg_replace("/ *\n/", "\n", $output); + } + + public function testOnlyOneTestFile(): void + { + foreach ($this->provideOnlyOneTestFile() as $parameters) { + $this->whenExecuteHarnessWithOneFileWillHaveStatusCodeAndOutput(...$parameters); + } + } + + private function provideOnlyOneTestFile(): iterable + { + yield [ + /* name */ 'pass', + /* expectedOverallSucceed */ true, + /* expectedOutput */ <<<'EOF' +test/unit/vendor/lime/fixtures/pass..................................ok + All tests successful. + Files=1, Tests=1 + +EOF + ]; + + yield [ + /* name */ 'pass_with_plan_less_than_total', + /* expectedOverallSucceed */ false, + /* expectedOutput */ <<<'EOF' +test/unit/vendor/lime/fixtures/pass_with_plan_less_than_total........dubious + Test returned status 255 + Looks like you planned 1 test but ran 1 extra. +Failed Test Stat Total Fail Errors List of Failed +-------------------------------------------------------------------------- +pass_with_plan_less_than_total 255 2 0 0 +Failed 1/1 test scripts, 0.00% okay. 0/2 subtests failed, 100.00% okay. + +EOF + ]; + + yield [ + /* name */ 'pass_with_plan_more_than_total', + /* expectedOverallSucceed */ false, + /* expectedOutput */ <<<'EOF' +test/unit/vendor/lime/fixtures/pass_with_plan_more_than_total........dubious + Test returned status 255 + Looks like you planned 2 tests but only ran 1. +Failed Test Stat Total Fail Errors List of Failed +-------------------------------------------------------------------------- +pass_with_plan_more_than_total 255 1 0 0 +Failed 1/1 test scripts, 0.00% okay. 1/2 subtests failed, 50.00% okay. + +EOF + ]; + + yield [ + /* name */ 'pass_with_one_error', + /* expectedOverallSucceed */ false, + /* expectedOutput */ <<<'EOF' +test/unit/vendor/lime/fixtures/pass_with_one_error...................errors + Errors: + - Notice: some user error message +Failed Test Stat Total Fail Errors List of Failed +-------------------------------------------------------------------------- +e/fixtures/pass_with_one_error 0 1 0 1 +Failed 1/1 test scripts, 0.00% okay. 0/1 subtests failed, 100.00% okay. + +EOF + ]; + + yield [ + /* name */ 'pass_with_one_throw_exception', + /* expectedOverallSucceed */ false, + /* expectedOutput */ <<<'EOF' +test/unit/vendor/lime/fixtures/pass_with_one_throw_exception.........errors + Errors: + - LogicException: some exception message +Failed Test Stat Total Fail Errors List of Failed +-------------------------------------------------------------------------- +/pass_with_one_throw_exception 0 0 0 1 +Failed 1/1 test scripts, 0.00% okay. 0/0 subtests failed, 0.00% okay. + +EOF + ]; + + yield [ + /* name */ 'pass_with_one_parse_error', + /* expectedOverallSucceed */ false, + /* expectedOutput */ <<<'EOF' +test/unit/vendor/lime/fixtures/pass_with_one_parse_error.............dubious + Test returned status 255 + Failed tests: 0 +Failed Test Stat Total Fail Errors List of Failed +-------------------------------------------------------------------------- +ures/pass_with_one_parse_error 255 1 1 0 0 +Failed 1/1 test scripts, 0.00% okay. 1/0 subtests failed, 0.00% okay. + +EOF + ]; + + yield [ + /* name */ 'skip', + /* expectedOverallSucceed */ true, + /* expectedOutput */ <<<'EOF' +test/unit/vendor/lime/fixtures/skip..................................ok + All tests successful. + Files=1, Tests=1 + +EOF + ]; + + yield [ + /* name */ 'skip_with_plan', + /* expectedOverallSucceed */ true, + /* expectedOutput */ <<<'EOF' +test/unit/vendor/lime/fixtures/skip_with_plan........................ok + All tests successful. + Files=1, Tests=2 + +EOF + ]; + + yield [ + /* name */ 'failed', + /* expectedOverallSucceed */ false, + /* expectedOutput */ <<<'EOF' +test/unit/vendor/lime/fixtures/failed................................not ok + Failed tests: 1 +Failed Test Stat Total Fail Errors List of Failed +-------------------------------------------------------------------------- +it/vendor/lime/fixtures/failed 0 1 1 0 1 +Failed 1/1 test scripts, 0.00% okay. 1/1 subtests failed, 0.00% okay. + +EOF + ]; + + yield [ + /* name */ 'failed_with_plan_less_than_total', + /* expectedOverallSucceed */ false, + /* expectedOutput */ <<<'EOF' +test/unit/vendor/lime/fixtures/failed_with_plan_less_than_total......dubious + Test returned status 255 + Looks like you planned 1 test but ran 1 extra. + Failed tests: 1 +Failed Test Stat Total Fail Errors List of Failed +-------------------------------------------------------------------------- +iled_with_plan_less_than_total 255 2 1 0 1 +Failed 1/1 test scripts, 0.00% okay. 1/2 subtests failed, 50.00% okay. + +EOF + ]; + + yield [ + /* name */ 'failed_with_plan_more_than_total', + /* expectedOverallSucceed */ false, + /* expectedOutput */ <<<'EOF' +test/unit/vendor/lime/fixtures/failed_with_plan_more_than_total......dubious + Test returned status 255 + Looks like you planned 2 tests but only ran 1. + Failed tests: 1 +Failed Test Stat Total Fail Errors List of Failed +-------------------------------------------------------------------------- +iled_with_plan_more_than_total 255 1 1 0 1 +Failed 1/1 test scripts, 0.00% okay. 2/2 subtests failed, 0.00% okay. + +EOF + ]; + } + + public function test_registerFilesWithGlob_thenRunThemAll(): void + { + $harness = $this->makeHarness(); + + $harness->register_glob(__DIR__."/fixtures/*.php"); + + $this->assertHarnessWithExitStatusAndOutput($harness, false, <<<'EOF' +test/unit/vendor/lime/fixtures/failed................................not ok + Failed tests: 1 +test/unit/vendor/lime/fixtures/failed_with_plan_less_than_total......dubious + Test returned status 255 + Looks like you planned 1 test but ran 1 extra. + Failed tests: 1 +test/unit/vendor/lime/fixtures/failed_with_plan_more_than_total......dubious + Test returned status 255 + Looks like you planned 2 tests but only ran 1. + Failed tests: 1 +test/unit/vendor/lime/fixtures/pass..................................ok +test/unit/vendor/lime/fixtures/pass_with_one_error...................errors + Errors: + - Notice: some user error message +test/unit/vendor/lime/fixtures/pass_with_one_parse_error.............dubious + Test returned status 255 + Failed tests: 0 +test/unit/vendor/lime/fixtures/pass_with_one_throw_exception.........errors + Errors: + - LogicException: some exception message +test/unit/vendor/lime/fixtures/pass_with_plan_less_than_total........dubious + Test returned status 255 + Looks like you planned 1 test but ran 1 extra. +test/unit/vendor/lime/fixtures/pass_with_plan_more_than_total........dubious + Test returned status 255 + Looks like you planned 2 tests but only ran 1. +test/unit/vendor/lime/fixtures/skip..................................ok +test/unit/vendor/lime/fixtures/skip_with_plan........................ok +Failed Test Stat Total Fail Errors List of Failed +-------------------------------------------------------------------------- +it/vendor/lime/fixtures/failed 0 1 1 0 1 +iled_with_plan_less_than_total 255 2 1 0 1 +iled_with_plan_more_than_total 255 1 1 0 1 +e/fixtures/pass_with_one_error 0 1 0 1 +ures/pass_with_one_parse_error 255 1 1 0 0 +/pass_with_one_throw_exception 0 0 0 1 +pass_with_plan_less_than_total 255 2 0 0 +pass_with_plan_more_than_total 255 1 0 0 +Failed 8/11 test scripts, 27.27% okay. 6/14 subtests failed, 57.14% okay. + +EOF); + } +} + +(new lime_harnessTest())->run(); diff --git a/test/unit/vendor/lime/lime_testTest.php b/test/unit/vendor/lime/lime_testTest.php new file mode 100644 index 000000000..24dec6536 --- /dev/null +++ b/test/unit/vendor/lime/lime_testTest.php @@ -0,0 +1,178 @@ +info($name); + + ob_start(); + $exitCode = (new lime_harness())->executePhpFile(__DIR__.'/fixtures/'.$name.'.php'); + $output = ob_get_clean(); + + $this->is($exitCode, $expectedStatusCode, 'with test '.$name.' will exit with status code '.$expectedStatusCode); + + $this->is($this->removeTrailingSpaces($output), $expectedOutput, 'test '.$name.' output'); + } + + private function removeTrailingSpaces(string $output): string + { + return preg_replace("/ *\n/", "\n", $output); + } + + public function testFiles() + { + foreach ($this->provideTestCases() as $parameters) { + $this->whenExecutePhpFileWillHaveStatusCodeAndOutput(...$parameters); + } + } + + private function provideTestCases() + { + yield [ + /* name */ 'pass', + /* expectedStatusCode */ 0, + /* expectedOutput */ <<<'EOF' +ok 1 +1..1 +# Looks like everything went fine. + +EOF + ]; + + yield [ + /* name */ 'failed', + /* expectedStatusCode */ 0, + /* expectedOutput */ <<<'EOF' +not ok 1 +# Failed test (./test/unit/vendor/lime/fixtures/failed.php at line 7) +# got: false +# expected: true +1..1 +# Looks like you failed 1 tests of 1. + +EOF + ]; + + yield [ + /* name */ 'failed_with_plan_less_than_total', + /* expectedStatusCode */ 0, + /* expectedOutput */ <<<'EOF' +1..1 +not ok 1 +# Failed test (./test/unit/vendor/lime/fixtures/failed_with_plan_less_than_total.php at line 7) +# got: false +# expected: true +ok 2 +# Looks like you planned 1 tests but ran 1 extra. +# Looks like you failed 1 tests of 2. + +EOF + ]; + + yield [ + /* name */ 'failed_with_plan_more_than_total', + /* expectedStatusCode */ 0, + /* expectedOutput */ <<<'EOF' +1..2 +not ok 1 +# Failed test (./test/unit/vendor/lime/fixtures/failed_with_plan_more_than_total.php at line 7) +# got: false +# expected: true +# Looks like you planned 2 tests but only ran 1. +# Looks like you failed 1 tests of 1. + +EOF + ]; + + yield [ + /* name */ 'pass_with_plan_less_than_total', + /* expectedStatusCode */ 0, + /* expectedOutput */ <<<'EOF' +1..1 +ok 1 +ok 2 +# Looks like you planned 1 tests but ran 1 extra. + +EOF + ]; + + yield [ + /* name */ 'pass_with_plan_more_than_total', + /* expectedStatusCode */ 0, + /* expectedOutput */ <<<'EOF' +1..2 +ok 1 +# Looks like you planned 2 tests but only ran 1. + +EOF + ]; + + yield [ + /* name */ 'pass_with_one_error', + /* expectedStatusCode */ 0, + /* expectedOutput */ <<<'EOF' + + + Notice: some user error message + (in test/unit/vendor/lime/fixtures/pass_with_one_error.php on line + 11) + + +Exception trace: + at test/unit/vendor/lime/fixtures/pass_with_one_error.php:11 + trigger_error() at test/unit/vendor/lime/fixtures/pass_with_one_error.php:11 + +ok 1 +1..1 +# Looks like everything went fine. + +EOF + ]; + + yield [ + /* name */ 'pass_with_one_throw_exception', + /* expectedStatusCode */ 0, + /* expectedOutput */ <<<'EOF' + + + LogicException: some exception message + (in + test/unit/vendor/lime/fixtures/pass_with_one_throw_exception.php + on line 7) + + +# Looks like everything went fine. + +EOF + ]; + + yield [ + /* name */ 'skip', + /* expectedStatusCode */ 0, + /* expectedOutput */ <<<'EOF' +ok 1 # SKIP some skip message +1..1 +# Looks like everything went fine. + +EOF + ]; + + yield [ + /* name */ 'skip_with_plan', + /* expectedStatusCode */ 0, + /* expectedOutput */ <<<'EOF' +1..2 +ok 1 # SKIP some skip message +ok 2 # SKIP some skip message +# Looks like everything went fine. + +EOF + ]; + } +} + +(new lime_testTest())->run(); diff --git a/test/unit/vendor/lime/tools/TestCase.php b/test/unit/vendor/lime/tools/TestCase.php new file mode 100644 index 000000000..933222ae3 --- /dev/null +++ b/test/unit/vendor/lime/tools/TestCase.php @@ -0,0 +1,39 @@ +test = new lime_test(); + } + + public function run(): void + { + foreach ($this->findAllTests() as $methodName) { + $this->test->diag($methodName); + + $this->$methodName(); + } + } + + private function findAllTests(): iterable + { + foreach (get_class_methods($this) as $methodName) { + if (0 === strpos($methodName, 'test')) { + yield $methodName; + } + } + } + + protected function info($message): void + { + $this->test->info($message); + } + + protected function is($expected, $actual, $message = ''): void + { + $this->test->is($expected, $actual, $message); + } +} diff --git a/test/unit/vendor/lime/tools/lime_no_colorizer.php b/test/unit/vendor/lime/tools/lime_no_colorizer.php new file mode 100644 index 000000000..9bc5f45df --- /dev/null +++ b/test/unit/vendor/lime/tools/lime_no_colorizer.php @@ -0,0 +1,8 @@ + Date: Wed, 10 Apr 2024 20:29:08 +0200 Subject: [PATCH 3/7] fixup! fix(test): exit code of lime test -- add proof of current behaviour --- test/unit/vendor/lime/lime_harnessTest.php | 25 +++++++++------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/test/unit/vendor/lime/lime_harnessTest.php b/test/unit/vendor/lime/lime_harnessTest.php index 1ba5d3890..4d961d97f 100644 --- a/test/unit/vendor/lime/lime_harnessTest.php +++ b/test/unit/vendor/lime/lime_harnessTest.php @@ -14,19 +14,6 @@ private function makeHarness(): lime_harness return $harness; } - private function whenExecuteHarnessWithOneFileWillHaveStatusCodeAndOutput($name, $expectedOverallSucceed, $expectedOutput) - { - $this->info($name); - - $harness = $this->makeHarness(); - - $harness->register([ - __DIR__."/fixtures/$name.php", - ]); - - $this->assertHarnessWithExitStatusAndOutput($harness, $expectedOverallSucceed, $expectedOutput); - } - private function assertHarnessWithExitStatusAndOutput(lime_harness $harness, $expectedOverallSucceed, string $expectedOutput) { ob_start(); @@ -45,8 +32,16 @@ private function removeTrailingSpaces(string $output): string public function testOnlyOneTestFile(): void { - foreach ($this->provideOnlyOneTestFile() as $parameters) { - $this->whenExecuteHarnessWithOneFileWillHaveStatusCodeAndOutput(...$parameters); + foreach ($this->provideOnlyOneTestFile() as [$name, $expectedOverallSucceed, $expectedOutput]) { + $this->info($name); + + $harness = $this->makeHarness(); + + $harness->register([ + __DIR__."/fixtures/$name.php", + ]); + + $this->assertHarnessWithExitStatusAndOutput($harness, $expectedOverallSucceed, $expectedOutput); } } From 77e027d2cce9f5af8685e1ce69a1e72a870e9fbb Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Wed, 10 Apr 2024 20:32:13 +0200 Subject: [PATCH 4/7] fixup! fix(test): exit code of lime test -- add proof of current behaviour --- test/unit/vendor/lime/lime_harnessTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/vendor/lime/lime_harnessTest.php b/test/unit/vendor/lime/lime_harnessTest.php index 4d961d97f..ba6429a43 100644 --- a/test/unit/vendor/lime/lime_harnessTest.php +++ b/test/unit/vendor/lime/lime_harnessTest.php @@ -14,7 +14,7 @@ private function makeHarness(): lime_harness return $harness; } - private function assertHarnessWithExitStatusAndOutput(lime_harness $harness, $expectedOverallSucceed, string $expectedOutput) + private function assertHarnessWithOverallSucceedAndOutput(lime_harness $harness, $expectedOverallSucceed, string $expectedOutput) { ob_start(); $allTestsSucceed = $harness->run(); @@ -41,7 +41,7 @@ public function testOnlyOneTestFile(): void __DIR__."/fixtures/$name.php", ]); - $this->assertHarnessWithExitStatusAndOutput($harness, $expectedOverallSucceed, $expectedOutput); + $this->assertHarnessWithOverallSucceedAndOutput($harness, $expectedOverallSucceed, $expectedOutput); } } @@ -208,7 +208,7 @@ public function test_registerFilesWithGlob_thenRunThemAll(): void $harness->register_glob(__DIR__."/fixtures/*.php"); - $this->assertHarnessWithExitStatusAndOutput($harness, false, <<<'EOF' + $this->assertHarnessWithOverallSucceedAndOutput($harness, false, <<<'EOF' test/unit/vendor/lime/fixtures/failed................................not ok Failed tests: 1 test/unit/vendor/lime/fixtures/failed_with_plan_less_than_total......dubious From 4523808934ecc5841757b0d1c5dbbd684d54c16f Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Wed, 10 Apr 2024 20:51:01 +0200 Subject: [PATCH 5/7] configure php-cs-fixer --- .php-cs-fixer.dist.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index fccc2b3f9..b4df1a67a 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -5,6 +5,7 @@ ->in(__DIR__.'/lib') ->in(__DIR__.'/data/bin') ->in(__DIR__.'/test') + ->in(__DIR__.'/test/unit/vendor') ->append([__FILE__]) // Exclude PHP classes templates/generators, which are not valid PHP files ->exclude('task/generator/skeleton/') @@ -21,6 +22,9 @@ // Exclude generated files (single files) ->notPath('unit/config/fixtures/sfDefineEnvironmentConfigHandler/prefix_result.php') ->notPath('unit/config/fixtures/sfFilterConfigHandler/result.php') + + // Exclude files with expected parsing error + ->notPath('lime/fixtures/pass_with_one_parse_error.php') ; $config = new PhpCsFixer\Config(); From 54a52f8af7edfc7e41e0c590926b99e46f87e289 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Wed, 10 Apr 2024 20:52:11 +0200 Subject: [PATCH 6/7] execute CS fixer --- .../lime/fixtures/pass_with_one_throw_exception.php | 1 - test/unit/vendor/lime/lime_harnessTest.php | 11 ++++++++--- test/unit/vendor/lime/lime_testTest.php | 5 +++++ test/unit/vendor/lime/tools/TestCase.php | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/test/unit/vendor/lime/fixtures/pass_with_one_throw_exception.php b/test/unit/vendor/lime/fixtures/pass_with_one_throw_exception.php index 98e61707e..826e345c1 100644 --- a/test/unit/vendor/lime/fixtures/pass_with_one_throw_exception.php +++ b/test/unit/vendor/lime/fixtures/pass_with_one_throw_exception.php @@ -5,5 +5,4 @@ $test = new lime_test(); throw new LogicException('some exception message'); - $test->is(true, true); diff --git a/test/unit/vendor/lime/lime_harnessTest.php b/test/unit/vendor/lime/lime_harnessTest.php index ba6429a43..162c23074 100644 --- a/test/unit/vendor/lime/lime_harnessTest.php +++ b/test/unit/vendor/lime/lime_harnessTest.php @@ -4,6 +4,11 @@ require_once __DIR__.'/tools/TestCase.php'; require_once __DIR__.'/tools/lime_no_colorizer.php'; +/** + * @internal + * + * @coversNothing + */ class lime_harnessTest extends TestCase { private function makeHarness(): lime_harness @@ -38,7 +43,7 @@ public function testOnlyOneTestFile(): void $harness = $this->makeHarness(); $harness->register([ - __DIR__."/fixtures/$name.php", + __DIR__."/fixtures/{$name}.php", ]); $this->assertHarnessWithOverallSucceedAndOutput($harness, $expectedOverallSucceed, $expectedOutput); @@ -202,11 +207,11 @@ private function provideOnlyOneTestFile(): iterable ]; } - public function test_registerFilesWithGlob_thenRunThemAll(): void + public function testRegisterFilesWithGlobThenRunThemAll(): void { $harness = $this->makeHarness(); - $harness->register_glob(__DIR__."/fixtures/*.php"); + $harness->register_glob(__DIR__.'/fixtures/*.php'); $this->assertHarnessWithOverallSucceedAndOutput($harness, false, <<<'EOF' test/unit/vendor/lime/fixtures/failed................................not ok diff --git a/test/unit/vendor/lime/lime_testTest.php b/test/unit/vendor/lime/lime_testTest.php index 24dec6536..f14f8f4d0 100644 --- a/test/unit/vendor/lime/lime_testTest.php +++ b/test/unit/vendor/lime/lime_testTest.php @@ -3,6 +3,11 @@ require_once __DIR__.'/../../../bootstrap/unit.php'; require_once __DIR__.'/tools/TestCase.php'; +/** + * @internal + * + * @coversNothing + */ class lime_testTest extends TestCase { private function whenExecutePhpFileWillHaveStatusCodeAndOutput($name, $expectedStatusCode, $expectedOutput) diff --git a/test/unit/vendor/lime/tools/TestCase.php b/test/unit/vendor/lime/tools/TestCase.php index 933222ae3..fa262401f 100644 --- a/test/unit/vendor/lime/tools/TestCase.php +++ b/test/unit/vendor/lime/tools/TestCase.php @@ -14,7 +14,7 @@ public function run(): void foreach ($this->findAllTests() as $methodName) { $this->test->diag($methodName); - $this->$methodName(); + $this->{$methodName}(); } } From 7dccdd1e09cd02d5e6e3afbb7219f596b798bbfb Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Wed, 10 Apr 2024 21:03:25 +0200 Subject: [PATCH 7/7] Allow having pretty method name for test cases --- .php-cs-fixer.dist.php | 1 + test/unit/vendor/lime/lime_harnessTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index b4df1a67a..a7a7c49f0 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -33,6 +33,7 @@ '@PhpCsFixer' => true, '@Symfony' => true, 'array_syntax' => ['syntax' => 'short'], + 'php_unit_method_casing' => false, ]) ->setCacheFile('.cache/php-cs-fixer.cache') ->setFinder($finder) diff --git a/test/unit/vendor/lime/lime_harnessTest.php b/test/unit/vendor/lime/lime_harnessTest.php index 162c23074..5dfb4d122 100644 --- a/test/unit/vendor/lime/lime_harnessTest.php +++ b/test/unit/vendor/lime/lime_harnessTest.php @@ -207,7 +207,7 @@ private function provideOnlyOneTestFile(): iterable ]; } - public function testRegisterFilesWithGlobThenRunThemAll(): void + public function test_registerFilesWithGlob_thenRunThemAll(): void { $harness = $this->makeHarness();