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 []; + } +}