|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Sofascore\PurgatoryBundle\Tests\Maker; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 8 | +use PHPUnit\Framework\Attributes\TestWith; |
| 9 | +use Sofascore\PurgatoryBundle\Maker\MakeRouteProvider; |
| 10 | +use Sofascore\PurgatoryBundle\Tests\Functional\AbstractKernelTestCase; |
| 11 | +use Symfony\Bundle\FrameworkBundle\Console\Application; |
| 12 | +use Symfony\Component\Console\Tester\CommandTester; |
| 13 | +use Symfony\Component\Filesystem\Filesystem; |
| 14 | + |
| 15 | +#[CoversClass(MakeRouteProvider::class)] |
| 16 | +final class MakeRouteProviderTest extends AbstractKernelTestCase |
| 17 | +{ |
| 18 | + private string|false $colSize; |
| 19 | + private CommandTester $command; |
| 20 | + |
| 21 | + protected function setUp(): void |
| 22 | + { |
| 23 | + $this->colSize = getenv('COLUMNS'); |
| 24 | + putenv('COLUMNS=300'); |
| 25 | + |
| 26 | + self::initializeApplication(['test_case' => 'TestApplication', 'config' => 'app_config.yaml']); |
| 27 | + |
| 28 | + $this->command = new CommandTester((new Application(self::$kernel))->find('make:purgatory-provider')); |
| 29 | + } |
| 30 | + |
| 31 | + protected function tearDown(): void |
| 32 | + { |
| 33 | + putenv($this->colSize ? 'COLUMNS='.$this->colSize : 'COLUMNS'); |
| 34 | + |
| 35 | + unset( |
| 36 | + $this->colSize, |
| 37 | + $this->command, |
| 38 | + ); |
| 39 | + |
| 40 | + (new Filesystem())->remove(__DIR__.'/../Functional/TestApplication/Generated/'); |
| 41 | + |
| 42 | + parent::tearDown(); |
| 43 | + } |
| 44 | + |
| 45 | + #[TestWith([ |
| 46 | + 'input' => ['PlaneRouteProvider', 'Plane', 'no'], |
| 47 | + 'expected' => 'PlaneRouteProvider', |
| 48 | + ])] |
| 49 | + #[TestWith([ |
| 50 | + 'input' => ['Plane', 'Plane', 'no'], |
| 51 | + 'expected' => 'PlaneRouteProvider', |
| 52 | + ])] |
| 53 | + #[TestWith([ |
| 54 | + 'input' => ['ShipBuild', 'Ship', 'yes', '0'], |
| 55 | + 'expected' => 'ShipBuildRouteProvider', |
| 56 | + ])] |
| 57 | + #[TestWith([ |
| 58 | + 'input' => ['VehicleFix', 'Vehicle', 'yes', '1,2'], |
| 59 | + 'expected' => 'VehicleFixRouteProvider', |
| 60 | + ])] |
| 61 | + #[TestWith([ |
| 62 | + 'input' => ['AnimalCompetition', 'Animal', '1', 'yes', '0,1,2'], |
| 63 | + 'expected' => 'AnimalCompetitionRouteProvider', |
| 64 | + ])] |
| 65 | + public function testGenerateRouteProvider(array $input, string $expected): void |
| 66 | + { |
| 67 | + $this->command->setInputs([implode(\PHP_EOL, $input).\PHP_EOL]); |
| 68 | + $this->command->execute([], ['interactive' => true]); |
| 69 | + |
| 70 | + self::assertFileExists(__DIR__."/../Functional/TestApplication/Generated/Purgatory/RouteProvider/$expected.php"); |
| 71 | + self::assertFileEquals( |
| 72 | + expected: __DIR__."/Expected/$expected.txt", |
| 73 | + actual: __DIR__."/../Functional/TestApplication/Generated/Purgatory/RouteProvider/$expected.php", |
| 74 | + ); |
| 75 | + } |
| 76 | +} |
0 commit comments