Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feat/sf-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Nov 17, 2023
2 parents 97bd5b2 + cca27a2 commit da392af
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 da392af

Please sign in to comment.