Skip to content

Commit

Permalink
test: Add test to ensure the base application has the same defaults a…
Browse files Browse the repository at this point in the history
…s the Symfony Application (#203)
  • Loading branch information
theofidry authored Nov 17, 2023
1 parent 8930c7f commit cca27a2
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/Application/BaseApplication/BaseApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/*
* This file is part of the Fidry\Console package.
*
* (c) Théo FIDRY <[email protected]>
*
* 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(),
];
}
}
34 changes: 34 additions & 0 deletions tests/Application/BaseApplication/MinimalApplication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the Fidry\Console package.
*
* (c) Théo FIDRY <[email protected]>
*
* 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 [];
}
}

0 comments on commit cca27a2

Please sign in to comment.