From ee2c9a44c878fe976b25739ed81e10fa60f6efe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Sat, 9 Mar 2024 09:03:32 +0100 Subject: [PATCH 1/4] tests: simplify CdDirectoryTest --- bin/generate-tests.php | 1 - tests/Examples/{ => Generated}/CdDirectoryTest.php | 11 +++++------ .../{ => Generated}/CdDirectoryTest.php.output.txt | 0 3 files changed, 5 insertions(+), 7 deletions(-) rename tests/Examples/{ => Generated}/CdDirectoryTest.php (66%) rename tests/Examples/{ => Generated}/CdDirectoryTest.php.output.txt (100%) diff --git a/bin/generate-tests.php b/bin/generate-tests.php index bb986ab7..133238e9 100755 --- a/bin/generate-tests.php +++ b/bin/generate-tests.php @@ -60,7 +60,6 @@ 'castor:watcher:linux', 'castor:watcher:windows', // Customized tests - 'cd:directory', 'fingerprint:task-with-a-fingerprint-and-force', 'fingerprint:task-with-a-fingerprint', 'fingerprint:task-with-complete-fingerprint-check', diff --git a/tests/Examples/CdDirectoryTest.php b/tests/Examples/Generated/CdDirectoryTest.php similarity index 66% rename from tests/Examples/CdDirectoryTest.php rename to tests/Examples/Generated/CdDirectoryTest.php index 41335222..adcd1930 100644 --- a/tests/Examples/CdDirectoryTest.php +++ b/tests/Examples/Generated/CdDirectoryTest.php @@ -1,21 +1,20 @@ runTask(['cd:directory']); + $this->assertSame(0, $process->getExitCode()); - $output = OutputCleaner::cleanOutput($process->getOutput()); - $this->assertStringEqualsFile(__FILE__ . '.output.txt', $output); + $this->assertStringEqualsFile(__FILE__ . '.output.txt', $process->getOutput()); if (file_exists(__FILE__ . '.err.txt')) { - $this->assertStringEqualsFile(__FILE__ . '.err.txt', OutputCleaner::cleanOutput($process->getErrorOutput())); + $this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput()); } else { $this->assertSame('', $process->getErrorOutput()); } diff --git a/tests/Examples/CdDirectoryTest.php.output.txt b/tests/Examples/Generated/CdDirectoryTest.php.output.txt similarity index 100% rename from tests/Examples/CdDirectoryTest.php.output.txt rename to tests/Examples/Generated/CdDirectoryTest.php.output.txt From 2a8ce2783d96a49931209f901244c9327749840b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Sat, 9 Mar 2024 09:10:17 +0100 Subject: [PATCH 2/4] chore: Move slow tests to a dedicated NS --- tests/{ => Slow}/CompileCommandTest.php | 2 +- tests/{ => Slow}/RepackCommandTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename tests/{ => Slow}/CompileCommandTest.php (98%) rename tests/{ => Slow}/RepackCommandTest.php (98%) diff --git a/tests/CompileCommandTest.php b/tests/Slow/CompileCommandTest.php similarity index 98% rename from tests/CompileCommandTest.php rename to tests/Slow/CompileCommandTest.php index ced2552d..628cd266 100644 --- a/tests/CompileCommandTest.php +++ b/tests/Slow/CompileCommandTest.php @@ -1,6 +1,6 @@ Date: Sat, 9 Mar 2024 09:13:51 +0100 Subject: [PATCH 3/4] chore: move OutputCleaner in the helper NS --- bin/generate-tests.php | 2 +- tests/{ => Helper}/OutputCleaner.php | 4 ++-- tests/TaskTestCase.php | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) rename tests/{ => Helper}/OutputCleaner.php (90%) diff --git a/bin/generate-tests.php b/bin/generate-tests.php index 133238e9..687a07e8 100755 --- a/bin/generate-tests.php +++ b/bin/generate-tests.php @@ -5,8 +5,8 @@ use Castor\Console\ApplicationFactory; use Castor\PlatformUtil; +use Castor\Tests\Helper\OutputCleaner; use Castor\Tests\Helper\WebServerHelper; -use Castor\Tests\OutputCleaner; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Filesystem\Filesystem; diff --git a/tests/OutputCleaner.php b/tests/Helper/OutputCleaner.php similarity index 90% rename from tests/OutputCleaner.php rename to tests/Helper/OutputCleaner.php index 0f3b6cce..8761816a 100644 --- a/tests/OutputCleaner.php +++ b/tests/Helper/OutputCleaner.php @@ -1,6 +1,6 @@ Date: Sat, 9 Mar 2024 09:42:35 +0100 Subject: [PATCH 4/4] chore: add tests for context validation --- bin/generate-tests.php | 12 +++++++++- .../Generated/ContextGeneratorArg2Test.php | 22 +++++++++++++++++++ .../ContextGeneratorArg2Test.php.err.txt | 8 +++++++ .../ContextGeneratorArg2Test.php.output.txt | 0 .../Generated/ContextGeneratorArgTest.php | 22 +++++++++++++++++++ .../ContextGeneratorArgTest.php.err.txt | 8 +++++++ .../ContextGeneratorArgTest.php.output.txt | 0 .../ContextGeneratorNotCallableTest.php | 22 +++++++++++++++++++ ...ontextGeneratorNotCallableTest.php.err.txt | 8 +++++++ ...extGeneratorNotCallableTest.php.output.txt | 0 .../Generated/NoDefaultContextTest.php | 22 +++++++++++++++++++ .../NoDefaultContextTest.php.err.txt | 6 +++++ .../NoDefaultContextTest.php.output.txt | 0 .../Generated/TwoDefaultContextTest.php | 22 +++++++++++++++++++ .../TwoDefaultContextTest.php.err.txt | 8 +++++++ .../TwoDefaultContextTest.php.output.txt | 0 .../broken/context-generator-arg-2/castor.php | 10 +++++++++ .../broken/context-generator-arg/castor.php | 10 +++++++++ .../context-generator-not-callable/castor.php | 9 ++++++++ .../broken/no-default-context/castor.php | 16 ++++++++++++++ .../broken/two-default-context/castor.php | 16 ++++++++++++++ tests/TaskTestCase.php | 2 +- 22 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 tests/Examples/Generated/ContextGeneratorArg2Test.php create mode 100644 tests/Examples/Generated/ContextGeneratorArg2Test.php.err.txt create mode 100644 tests/Examples/Generated/ContextGeneratorArg2Test.php.output.txt create mode 100644 tests/Examples/Generated/ContextGeneratorArgTest.php create mode 100644 tests/Examples/Generated/ContextGeneratorArgTest.php.err.txt create mode 100644 tests/Examples/Generated/ContextGeneratorArgTest.php.output.txt create mode 100644 tests/Examples/Generated/ContextGeneratorNotCallableTest.php create mode 100644 tests/Examples/Generated/ContextGeneratorNotCallableTest.php.err.txt create mode 100644 tests/Examples/Generated/ContextGeneratorNotCallableTest.php.output.txt create mode 100644 tests/Examples/Generated/NoDefaultContextTest.php create mode 100644 tests/Examples/Generated/NoDefaultContextTest.php.err.txt create mode 100644 tests/Examples/Generated/NoDefaultContextTest.php.output.txt create mode 100644 tests/Examples/Generated/TwoDefaultContextTest.php create mode 100644 tests/Examples/Generated/TwoDefaultContextTest.php.err.txt create mode 100644 tests/Examples/Generated/TwoDefaultContextTest.php.output.txt create mode 100644 tests/Examples/fixtures/broken/context-generator-arg-2/castor.php create mode 100644 tests/Examples/fixtures/broken/context-generator-arg/castor.php create mode 100644 tests/Examples/fixtures/broken/context-generator-not-callable/castor.php create mode 100644 tests/Examples/fixtures/broken/no-default-context/castor.php create mode 100644 tests/Examples/fixtures/broken/two-default-context/castor.php diff --git a/bin/generate-tests.php b/bin/generate-tests.php index 687a07e8..af439573 100755 --- a/bin/generate-tests.php +++ b/bin/generate-tests.php @@ -10,6 +10,7 @@ use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Finder\Finder; use Symfony\Component\Process\Process; use function Symfony\Component\String\u; @@ -106,6 +107,15 @@ add_test($args, $class); } +$dirs = (new Finder()) + ->in($basePath = __DIR__ . '/../tests/Examples/fixtures/broken') + ->depth(1) +; +foreach ($dirs as $dir) { + $class = u($dir->getRelativePath())->camel()->title()->append('Test')->toString(); + add_test([], $class, '{{ base }}/tests/Examples/fixtures/broken/' . $dir->getRelativePath()); +} + add_test(['parallel:sleep', '--sleep5', '0', '--sleep7', '0', '--sleep10', '0'], 'ParallelSleepTest'); add_test(['context:context', '--context', 'run'], 'ContextContextRunTest'); add_test(['context:context', '--context', 'my_default', '-v'], 'ContextContextMyDefaultTest'); @@ -128,7 +138,7 @@ function add_test(array $args, string $class, ?string $cwd = null) $process = new Process( [\PHP_BINARY, __DIR__ . '/castor', '--no-ansi', ...$args], - cwd: $cwd ?: __DIR__ . '/../', + cwd: $cwd ? str_replace('{{ base }}', __DIR__ . '/..', $cwd) : __DIR__ . '/..', env: [ 'COLUMNS' => 120, 'ENDPOINT' => $_SERVER['ENDPOINT'], diff --git a/tests/Examples/Generated/ContextGeneratorArg2Test.php b/tests/Examples/Generated/ContextGeneratorArg2Test.php new file mode 100644 index 00000000..995c4c27 --- /dev/null +++ b/tests/Examples/Generated/ContextGeneratorArg2Test.php @@ -0,0 +1,22 @@ +runTask([], '{{ base }}/tests/Examples/fixtures/broken/context-generator-arg-2'); + + $this->assertSame(1, $process->getExitCode()); + $this->assertStringEqualsFile(__FILE__ . '.output.txt', $process->getOutput()); + if (file_exists(__FILE__ . '.err.txt')) { + $this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput()); + } else { + $this->assertSame('', $process->getErrorOutput()); + } + } +} diff --git a/tests/Examples/Generated/ContextGeneratorArg2Test.php.err.txt b/tests/Examples/Generated/ContextGeneratorArg2Test.php.err.txt new file mode 100644 index 00000000..648c0e88 --- /dev/null +++ b/tests/Examples/Generated/ContextGeneratorArg2Test.php.err.txt @@ -0,0 +1,8 @@ + +In FunctionFinder.php line 218: + + Function "gen()" is not properly configured: + The context generator "foo" must not have arguments. + Defined in "castor.php" line 7. + + diff --git a/tests/Examples/Generated/ContextGeneratorArg2Test.php.output.txt b/tests/Examples/Generated/ContextGeneratorArg2Test.php.output.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/Examples/Generated/ContextGeneratorArgTest.php b/tests/Examples/Generated/ContextGeneratorArgTest.php new file mode 100644 index 00000000..b9051317 --- /dev/null +++ b/tests/Examples/Generated/ContextGeneratorArgTest.php @@ -0,0 +1,22 @@ +runTask([], '{{ base }}/tests/Examples/fixtures/broken/context-generator-arg'); + + $this->assertSame(1, $process->getExitCode()); + $this->assertStringEqualsFile(__FILE__ . '.output.txt', $process->getOutput()); + if (file_exists(__FILE__ . '.err.txt')) { + $this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput()); + } else { + $this->assertSame('', $process->getErrorOutput()); + } + } +} diff --git a/tests/Examples/Generated/ContextGeneratorArgTest.php.err.txt b/tests/Examples/Generated/ContextGeneratorArgTest.php.err.txt new file mode 100644 index 00000000..84f73c03 --- /dev/null +++ b/tests/Examples/Generated/ContextGeneratorArgTest.php.err.txt @@ -0,0 +1,8 @@ + +In FunctionFinder.php line 209: + + Function "gen()" is not properly configured: + The contexts generator must not have arguments. + Defined in "castor.php" line 7. + + diff --git a/tests/Examples/Generated/ContextGeneratorArgTest.php.output.txt b/tests/Examples/Generated/ContextGeneratorArgTest.php.output.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/Examples/Generated/ContextGeneratorNotCallableTest.php b/tests/Examples/Generated/ContextGeneratorNotCallableTest.php new file mode 100644 index 00000000..c6ce84ed --- /dev/null +++ b/tests/Examples/Generated/ContextGeneratorNotCallableTest.php @@ -0,0 +1,22 @@ +runTask([], '{{ base }}/tests/Examples/fixtures/broken/context-generator-not-callable'); + + $this->assertSame(1, $process->getExitCode()); + $this->assertStringEqualsFile(__FILE__ . '.output.txt', $process->getOutput()); + if (file_exists(__FILE__ . '.err.txt')) { + $this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput()); + } else { + $this->assertSame('', $process->getErrorOutput()); + } + } +} diff --git a/tests/Examples/Generated/ContextGeneratorNotCallableTest.php.err.txt b/tests/Examples/Generated/ContextGeneratorNotCallableTest.php.err.txt new file mode 100644 index 00000000..30497925 --- /dev/null +++ b/tests/Examples/Generated/ContextGeneratorNotCallableTest.php.err.txt @@ -0,0 +1,8 @@ + +In FunctionFinder.php line 214: + + Function "gen()" is not properly configured: + The context generator "foo" is not callable. + Defined in "castor.php" line 6. + + diff --git a/tests/Examples/Generated/ContextGeneratorNotCallableTest.php.output.txt b/tests/Examples/Generated/ContextGeneratorNotCallableTest.php.output.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/Examples/Generated/NoDefaultContextTest.php b/tests/Examples/Generated/NoDefaultContextTest.php new file mode 100644 index 00000000..fe7286d0 --- /dev/null +++ b/tests/Examples/Generated/NoDefaultContextTest.php @@ -0,0 +1,22 @@ +runTask([], '{{ base }}/tests/Examples/fixtures/broken/no-default-context'); + + $this->assertSame(1, $process->getExitCode()); + $this->assertStringEqualsFile(__FILE__ . '.output.txt', $process->getOutput()); + if (file_exists(__FILE__ . '.err.txt')) { + $this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput()); + } else { + $this->assertSame('', $process->getErrorOutput()); + } + } +} diff --git a/tests/Examples/Generated/NoDefaultContextTest.php.err.txt b/tests/Examples/Generated/NoDefaultContextTest.php.err.txt new file mode 100644 index 00000000..8400d780 --- /dev/null +++ b/tests/Examples/Generated/NoDefaultContextTest.php.err.txt @@ -0,0 +1,6 @@ + +In ContextRegistry.php line XXXX: + + Since there are multiple contexts "one", "two", you must set a "default: true" context. + + diff --git a/tests/Examples/Generated/NoDefaultContextTest.php.output.txt b/tests/Examples/Generated/NoDefaultContextTest.php.output.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/Examples/Generated/TwoDefaultContextTest.php b/tests/Examples/Generated/TwoDefaultContextTest.php new file mode 100644 index 00000000..77667b72 --- /dev/null +++ b/tests/Examples/Generated/TwoDefaultContextTest.php @@ -0,0 +1,22 @@ +runTask([], '{{ base }}/tests/Examples/fixtures/broken/two-default-context'); + + $this->assertSame(1, $process->getExitCode()); + $this->assertStringEqualsFile(__FILE__ . '.output.txt', $process->getOutput()); + if (file_exists(__FILE__ . '.err.txt')) { + $this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput()); + } else { + $this->assertSame('', $process->getErrorOutput()); + } + } +} diff --git a/tests/Examples/Generated/TwoDefaultContextTest.php.err.txt b/tests/Examples/Generated/TwoDefaultContextTest.php.err.txt new file mode 100644 index 00000000..c5612419 --- /dev/null +++ b/tests/Examples/Generated/TwoDefaultContextTest.php.err.txt @@ -0,0 +1,8 @@ + +In ContextRegistry.php line XXXX: + + Function "two()" is not properly configured: + You cannot define two contexts with the same name "default". There is one already defined in "castor.php:7". + Defined in "castor.php" line 13. + + diff --git a/tests/Examples/Generated/TwoDefaultContextTest.php.output.txt b/tests/Examples/Generated/TwoDefaultContextTest.php.output.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/Examples/fixtures/broken/context-generator-arg-2/castor.php b/tests/Examples/fixtures/broken/context-generator-arg-2/castor.php new file mode 100644 index 00000000..f2f6c873 --- /dev/null +++ b/tests/Examples/fixtures/broken/context-generator-arg-2/castor.php @@ -0,0 +1,10 @@ + fn ($a) => new Context(); +} diff --git a/tests/Examples/fixtures/broken/context-generator-arg/castor.php b/tests/Examples/fixtures/broken/context-generator-arg/castor.php new file mode 100644 index 00000000..1ec3584c --- /dev/null +++ b/tests/Examples/fixtures/broken/context-generator-arg/castor.php @@ -0,0 +1,10 @@ + 'not a callable'; +} diff --git a/tests/Examples/fixtures/broken/no-default-context/castor.php b/tests/Examples/fixtures/broken/no-default-context/castor.php new file mode 100644 index 00000000..7e87b35c --- /dev/null +++ b/tests/Examples/fixtures/broken/no-default-context/castor.php @@ -0,0 +1,16 @@ + 120, ...$extraEnv,