-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add test to ensure the base application has the same defaults a…
…s the Symfony Application (#203)
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 []; | ||
} | ||
} |