Skip to content

Commit

Permalink
chore: Simplify generated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Apr 3, 2024
1 parent 4bae84b commit 45424c4
Show file tree
Hide file tree
Showing 80 changed files with 97 additions and 396 deletions.
27 changes: 16 additions & 11 deletions bin/generate-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
add_test(['enabled:hello', '--context', 'production'], 'EnabledInProduction');
add_test(['list', '--raw', '--format', 'txt', '--short'], 'ListTest', skipOnBinary: true);
add_test(['parallel:sleep', '--sleep5', '0', '--sleep7', '0', '--sleep10', '0'], 'ParallelSleepTest');
add_test(['symfony:greet', 'World', '--french', 'COUCOU', '--punctuation', '!' ], 'SymfonyGreetTest', skipOnBinary: true);
add_test(['symfony:greet', 'World', '--french', 'COUCOU', '--punctuation', '!'], 'SymfonyGreetTest', skipOnBinary: true);
add_test(['symfony:hello'], 'SymfonyHelloTest', skipOnBinary: true);
// In /tmp
add_test(['completion', 'bash'], 'NoConfigCompletionTest', '/tmp');
Expand Down Expand Up @@ -174,6 +174,8 @@ function add_test(array $args, string $class, ?string $cwd = null, bool $needRem
);
$process->run();

$err = OutputCleaner::cleanOutput($process->getErrorOutput());

$code = strtr($template, [
'{{ class_name }}' => $class,
'{{ task }}' => $args[0] ?? 'no task',
Expand All @@ -184,18 +186,25 @@ function add_test(array $args, string $class, ?string $cwd = null, bool $needRem
'{{ skip-on-binary }}' => match ($skipOnBinary) {
true => <<<'PHP'
if (self::$binary) {
$this->markTestSkipped('This test is not compatible with the binary version of Castor.');
}
if (self::$binary) {
$this->markTestSkipped('This test is not compatible with the binary version of Castor.');
}

PHP,
PHP,
default => '',
},
'{{ error-assertion }}' => match ((bool) $err) {
true => <<<'PHP'
$this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput());
PHP,
default => <<<'PHP'
$this->assertSame('', $process->getErrorOutput());
PHP,
},
]);

file_put_contents(__DIR__ . '/../tests/Examples/Generated/' . $class . '.php', $code);
file_put_contents(__DIR__ . '/../tests/Examples/Generated/' . $class . '.php.output.txt', OutputCleaner::cleanOutput($process->getOutput()));
$err = OutputCleaner::cleanOutput($process->getErrorOutput());
if ($err) {
file_put_contents(__DIR__ . '/../tests/Examples/Generated/' . $class . '.php.err.txt', $err);
}
Expand All @@ -217,10 +226,6 @@ public function test(): void

$this->assertSame({{ exitCode }}, $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());
}
{{ error-assertion }}
}
}
4 changes: 2 additions & 2 deletions examples/symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand('hello', 'Says hello from a symfony application')]
#[AsSymfonyTask(name: 'symfony:hello', console: [PHP_BINARY, __FILE__])] // We need to force PHP binary to support windows
#[AsSymfonyTask(name: 'symfony:hello', console: [\PHP_BINARY, __FILE__])] // We need to force PHP binary to support windows
class HelloCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -27,7 +27,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

#[AsCommand('greet')]
#[AsSymfonyTask(name: 'symfony:greet', console: [PHP_BINARY, __FILE__])] // We need to force PHP binary to support windows
#[AsSymfonyTask(name: 'symfony:greet', console: [\PHP_BINARY, __FILE__])] // We need to force PHP binary to support windows
class GreetCommand extends Command
{
protected function configure(): void
Expand Down
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ArgPassthruExpanded.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ArgsAnotherArgsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ArgsArgsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ArgsAutocompleteArgumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ArgsPassthruTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/AutocompleteInvalidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$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());
}
$this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/BarBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/CacheComplexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/CacheSimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/CdDirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ContextContextDoNotExistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$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());
}
$this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ContextContextDynamicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ContextContextInfoForcedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ContextContextMyDefaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ContextContextPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ContextContextProductionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ContextContextRunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ContextContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ContextContextWithTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ContextGeneratorArg2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$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());
}
$this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ContextGeneratorArgTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$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());
}
$this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/ContextGeneratorNotCallableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$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());
}
$this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/EnabledInProduction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/EnvEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/EventListenerMyTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertSame('', $process->getErrorOutput());
}
}
6 changes: 1 addition & 5 deletions tests/Examples/Generated/FailureAllowFailureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public function test(): void

$this->assertSame(0, $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());
}
$this->assertStringEqualsFile(__FILE__ . '.err.txt', $process->getErrorOutput());
}
}
Loading

0 comments on commit 45424c4

Please sign in to comment.