|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony MakerBundle package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\MakerBundle\Tests\Test; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Bundle\MakerBundle\ConsoleStyle; |
| 16 | +use Symfony\Bundle\MakerBundle\DependencyBuilder; |
| 17 | +use Symfony\Bundle\MakerBundle\Generator; |
| 18 | +use Symfony\Bundle\MakerBundle\InputConfiguration; |
| 19 | +use Symfony\Bundle\MakerBundle\MakerInterface; |
| 20 | +use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; |
| 21 | +use Symfony\Component\Console\Command\Command; |
| 22 | +use Symfony\Component\Console\Input\InputInterface; |
| 23 | +use Symfony\Component\Routing\Route; |
| 24 | +use Symfony\Component\Security\Core\Authorization\Voter\Voter; |
| 25 | + |
| 26 | +class MakerTestDetailsTest extends TestCase |
| 27 | +{ |
| 28 | + public function testAddExtraDependencies(): void |
| 29 | + { |
| 30 | + $details = new MakerTestDetails($this->createMock(MakerInterface::class)); |
| 31 | + |
| 32 | + $details->addExtraDependencies('twig'); |
| 33 | + |
| 34 | + self::assertSame(['twig'], $details->getExtraDependencies()); |
| 35 | + |
| 36 | + $details->addExtraDependencies('ux', 'mercure'); |
| 37 | + |
| 38 | + self::assertSame(['twig', 'ux', 'mercure'], $details->getExtraDependencies()); |
| 39 | + } |
| 40 | + |
| 41 | + public function testAddRequiredPackageVersions(): void |
| 42 | + { |
| 43 | + $details = new MakerTestDetails($this->createMock(MakerInterface::class)); |
| 44 | + |
| 45 | + $details->addRequiredPackageVersion('twig', '4.x'); |
| 46 | + |
| 47 | + self::assertSame([['name' => 'twig', 'version_constraint' => '4.x']], $details->getRequiredPackageVersions()); |
| 48 | + |
| 49 | + $details->addRequiredPackageVersion('maker', '1.x'); |
| 50 | + self::assertSame([ |
| 51 | + ['name' => 'twig', 'version_constraint' => '4.x'], |
| 52 | + ['name' => 'maker', 'version_constraint' => '1.x'], |
| 53 | + ], $details->getRequiredPackageVersions()); |
| 54 | + } |
| 55 | + |
| 56 | + public function testGetDependencies(): void |
| 57 | + { |
| 58 | + $details = new MakerTestDetails(new TestMakerFixture()); |
| 59 | + |
| 60 | + $details->addExtraDependencies('twig'); |
| 61 | + |
| 62 | + self::assertSame(['security', 'router', 'twig'], $details->getDependencies()); |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +/** |
| 67 | + * @method string getCommandDescription() |
| 68 | + */ |
| 69 | +class TestMakerFixture implements MakerInterface |
| 70 | +{ |
| 71 | + public function configureDependencies(DependencyBuilder $dependencies): void |
| 72 | + { |
| 73 | + $dependencies->addClassDependency(Voter::class, 'security'); |
| 74 | + $dependencies->addClassDependency(Route::class, 'router', devDependency: true); |
| 75 | + } |
| 76 | + |
| 77 | + public static function getCommandName(): string |
| 78 | + { |
| 79 | + return 'test'; |
| 80 | + } |
| 81 | + |
| 82 | + public function configureCommand(Command $command, InputConfiguration $inputConfig) |
| 83 | + { |
| 84 | + } |
| 85 | + |
| 86 | + public function interact(InputInterface $input, ConsoleStyle $io, Command $command) |
| 87 | + { |
| 88 | + } |
| 89 | + |
| 90 | + public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) |
| 91 | + { |
| 92 | + } |
| 93 | +} |
0 commit comments