From cca27a238931ca17b0da569c9a4039e89c09a916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Fri, 17 Nov 2023 22:41:02 +0100 Subject: [PATCH] test: Add test to ensure the base application has the same defaults as the Symfony Application (#203) --- .../BaseApplication/BaseApplicationTest.php | 60 +++++++++++++++++++ .../BaseApplication/MinimalApplication.php | 34 +++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tests/Application/BaseApplication/BaseApplicationTest.php create mode 100644 tests/Application/BaseApplication/MinimalApplication.php diff --git a/tests/Application/BaseApplication/BaseApplicationTest.php b/tests/Application/BaseApplication/BaseApplicationTest.php new file mode 100644 index 0000000..12de8ed --- /dev/null +++ b/tests/Application/BaseApplication/BaseApplicationTest.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Fidry\Console\Tests\Application\BaseApplication; + +use Fidry\Console\Application\BaseApplication; +use Fidry\Console\Bridge\Application\SymfonyApplication; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Application as SymfonyNativeApplication; + +#[CoversClass(BaseApplication::class)] +final class BaseApplicationTest extends TestCase +{ + public function test_it_shares_defaults_with_the_symfony_application(): void + { + $application = new MinimalApplication(); + $bridgedSymfonyApp = new SymfonyApplication($application); + + $symfonyApp = new SymfonyNativeApplication( + $application->getName(), + $application->getVersion(), + ); + + self::assertApplicationsHaveSameState($symfonyApp, $bridgedSymfonyApp); + } + + private static function assertApplicationsHaveSameState( + SymfonyNativeApplication $expected, + SymfonyNativeApplication $actual, + ): void { + self::assertEquals( + self::getApplicationState($expected), + self::getApplicationState($actual), + ); + } + + /** @psalm-suppress InternalMethod */ + private static function getApplicationState(SymfonyNativeApplication $application): array + { + return [ + 'name' => $application->getName(), + 'version' => $application->getVersion(), + 'longVersion' => $application->getLongVersion(), + 'catchExceptions' => $application->areExceptionsCaught(), + 'autoExit' => $application->isAutoExitEnabled(), + 'singleCommand' => $application->isSingleCommand(), + ]; + } +} diff --git a/tests/Application/BaseApplication/MinimalApplication.php b/tests/Application/BaseApplication/MinimalApplication.php new file mode 100644 index 0000000..943b0a6 --- /dev/null +++ b/tests/Application/BaseApplication/MinimalApplication.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Fidry\Console\Tests\Application\BaseApplication; + +use Fidry\Console\Application\BaseApplication; + +final class MinimalApplication extends BaseApplication +{ + public function getName(): string + { + return 'MinimalApp'; + } + + public function getVersion(): string + { + return 'v1.0.0-dev'; + } + + public function getCommands(): array + { + return []; + } +}