From a59ea752e0953b22c4a21db77b98ea824567ba66 Mon Sep 17 00:00:00 2001 From: poprazvan17 Date: Wed, 2 Aug 2023 14:48:05 +0300 Subject: [PATCH 1/5] implemented phpUnit tests, phpcs and psalm --- .github/workflows/cs-tests.yml | 46 +++++++++ .github/workflows/static-analysis.yml | 46 +++++++++ .github/workflows/unit-tests.yaml | 47 +++++++++ .gitignore | 4 +- README.md | 3 + composer.json | 25 ++++- phpcs.xml | 20 ++++ phpunit.xml | 10 ++ psalm.xml | 15 +++ src/Command/ExecuteFixturesCommand.php | 30 ++---- src/Command/ListFixturesCommand.php | 40 +++----- src/ConfigProvider.php | 8 +- src/Exception/NotFoundException.php | 6 +- src/Factory/ExecuteFixturesCommandFactory.php | 16 ++-- src/Factory/ListFixturesCommandFactory.php | 11 ++- test/Command/ExecuteFixturesCommandTest.php | 61 ++++++++++++ test/Command/ListFixturesCommandTest.php | 58 +++++++++++ test/ConfigProviderTest.php | 38 ++++++++ test/Exception/NotFoundExceptionTest.php | 28 ++++++ .../ExecuteFixturesCommandFactoryTest.php | 96 +++++++++++++++++++ .../ListFixturesCommandFactoryTest.php | 61 ++++++++++++ 21 files changed, 595 insertions(+), 74 deletions(-) create mode 100644 .github/workflows/cs-tests.yml create mode 100644 .github/workflows/static-analysis.yml create mode 100644 .github/workflows/unit-tests.yaml create mode 100644 phpcs.xml create mode 100644 phpunit.xml create mode 100644 psalm.xml create mode 100644 test/Command/ExecuteFixturesCommandTest.php create mode 100644 test/Command/ListFixturesCommandTest.php create mode 100644 test/ConfigProviderTest.php create mode 100644 test/Exception/NotFoundExceptionTest.php create mode 100644 test/Factory/ExecuteFixturesCommandFactoryTest.php create mode 100644 test/Factory/ListFixturesCommandFactoryTest.php diff --git a/.github/workflows/cs-tests.yml b/.github/workflows/cs-tests.yml new file mode 100644 index 0000000..3da9965 --- /dev/null +++ b/.github/workflows/cs-tests.yml @@ -0,0 +1,46 @@ +on: + - push + +name: Run phpcs checks + +jobs: + mutation: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + tools: composer:v2, cs2pr + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v3 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + - name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run phpcs checks + run: vendor/bin/phpcs diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..74550fc --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,46 @@ +on: + - push + +name: Run static analysis + +jobs: + mutation: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + tools: composer:v2, cs2pr + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v3 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + - name: Install dependencies with composer + run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run static analysis + run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4 diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml new file mode 100644 index 0000000..d2ab8e7 --- /dev/null +++ b/.github/workflows/unit-tests.yaml @@ -0,0 +1,47 @@ +on: + - push + +name: Run PHPUnit tests + +jobs: + mutation: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + tools: composer:v2, cs2pr + coverage: none + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v3 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + + - name: Install dependencies with composer + run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run PHPUnit tests + run: vendor/bin/phpunit --colors=always diff --git a/.gitignore b/.gitignore index c624b8c..e0b1315 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ composer.lock .idea/ .DS_Store -/src/.DS_Store \ No newline at end of file +/src/.DS_Store +.phpunit.result.cache +.phpcs-cache diff --git a/README.md b/README.md index 9576854..4039c1a 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,9 @@ [![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-data-fixtures)](https://github.com/dotkernel/dot-data-fixtures/stargazers) [![GitHub license](https://img.shields.io/github/license/dotkernel/dot-data-fixtures)](https://github.com/dotkernel/dot-data-fixtures/blob/1.0/LICENSE) +[![Build Static](https://github.com/dotkernel/dot-data-fixtures/actions/workflows/static-analysis.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-data-fixtures/actions/workflows/static-analysis.yml) + +[![SymfonyInsight](https://insight.symfony.com/projects/6bac345c-9548-47ec-ab4a-25773a98ed03/big.svg)](https://insight.symfony.com/projects/6bac345c-9548-47ec-ab4a-25773a98ed03) This package provides a CLI interface for interacting with doctrine/data-fixtures. diff --git a/composer.json b/composer.json index 653ece9..26a6f14 100644 --- a/composer.json +++ b/composer.json @@ -20,15 +20,34 @@ "mezzio" ], "require": { - "php": "~7.4.0 || ~8.0.0 || ~8.1.0", - "doctrine/data-fixtures": "^1.5" + "php": "~8.1.0 || ~8.2.0", + "doctrine/data-fixtures": "^1.5", + "doctrine/orm": "*" }, "require-dev": { - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^10.2", + "laminas/laminas-coding-standard": "^2.5", + "vimeo/psalm": "^5.13" }, "autoload": { "psr-4": { "Dot\\DataFixtures\\": "src" } + }, + "scripts": { + "check": [ + "@cs-check", + "@test" + ], + "cs-check": "phpcs", + "cs-fix": "phpcbf", + "test": "phpunit --colors=always", + "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", + "static-analysis": "psalm --shepherd --stats" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..1efe663 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + src + test + + + + diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..eff747d --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,10 @@ + + + + + ./test + + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..df50202 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/src/Command/ExecuteFixturesCommand.php b/src/Command/ExecuteFixturesCommand.php index ca4f57e..74778e5 100644 --- a/src/Command/ExecuteFixturesCommand.php +++ b/src/Command/ExecuteFixturesCommand.php @@ -1,48 +1,39 @@ entityManager = $entityManager; - $this->path = $path; + $this->path = $path; } - /** - * @return void - */ protected function configure(): void { $this->setName(self::$defaultName) @@ -56,11 +47,6 @@ protected function configure(): void ); } - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return int - */ protected function execute(InputInterface $input, OutputInterface $output): int { $loader = new Loader(); @@ -79,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $executor->execute($fixtures, true); foreach ($fixtures as $fixture) { - $output->writeln(sprintf('Executing %s ', get_class($fixture))); + $output->writeln(sprintf('Executing %s ', $fixture::class)); } $output->writeln("Fixtures have been loaded."); diff --git a/src/Command/ListFixturesCommand.php b/src/Command/ListFixturesCommand.php index 13974ed..323029e 100644 --- a/src/Command/ListFixturesCommand.php +++ b/src/Command/ListFixturesCommand.php @@ -1,33 +1,26 @@ path = $path; } - /** - * @return void - */ protected function configure(): void { $this->setName(self::$defaultName)->setDescription('List all available fixtures.'); } - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return int - */ protected function execute(InputInterface $input, OutputInterface $output): int { $loader = new Loader(); $loader->loadFromDirectory($this->path); - $rows = []; + $rows = []; + $commandName = ExecuteFixturesCommand::getDefaultName(); + foreach ($loader->getFixtures() as $fixture) { $reflectionClass = new ReflectionClass($fixture); - $lastUpdatedAt = DateTimeImmutable::createFromFormat('U', filemtime($reflectionClass->getFileName())); + $lastUpdatedAt = DateTimeImmutable::createFromFormat( + 'U', + (string) filemtime($reflectionClass->getFileName()) + ); $rows[] = [ - 'namespace' => $reflectionClass->getName(), - 'command' => ExecuteFixturesCommand::getDefaultName() . ' --class=' . $reflectionClass->getShortName(), + 'namespace' => $reflectionClass->getName(), + 'command' => $commandName . ' --class=' . $reflectionClass->getShortName(), 'last_updated_at' => $lastUpdatedAt->format('Y-m-d H:i:s'), ]; } diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 2b606cc..48e30dc 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -9,10 +9,6 @@ use Dot\DataFixtures\Factory\ExecuteFixturesCommandFactory; use Dot\DataFixtures\Factory\ListFixturesCommandFactory; -/** - * Class ConfigProvider - * @package Dot\DataFixtures - */ class ConfigProvider { /** @@ -35,9 +31,9 @@ public function __invoke(): array public function getDependencies(): array { return [ - 'factories' => [ + 'factories' => [ ExecuteFixturesCommand::class => ExecuteFixturesCommandFactory::class, - ListFixturesCommand::class => ListFixturesCommandFactory::class, + ListFixturesCommand::class => ListFixturesCommandFactory::class, ], ]; } diff --git a/src/Exception/NotFoundException.php b/src/Exception/NotFoundException.php index 2f43a57..a62d4b4 100644 --- a/src/Exception/NotFoundException.php +++ b/src/Exception/NotFoundException.php @@ -1,15 +1,11 @@ has(EntityManager::class)) { + if (! $container->has(EntityManager::class)) { throw new NotFoundException('EntityManager not found.'); } diff --git a/src/Factory/ListFixturesCommandFactory.php b/src/Factory/ListFixturesCommandFactory.php index ac5f23a..6fe9945 100644 --- a/src/Factory/ListFixturesCommandFactory.php +++ b/src/Factory/ListFixturesCommandFactory.php @@ -1,16 +1,23 @@ executeFixturesCommandMock = $this->createMock(ExecuteFixturesCommand::class); + $this->entityManager = $this->createMock(EntityManager::class); + } + + public function testCreateCommand(): void + { + $this->assertInstanceOf(ExecuteFixturesCommand::class, $this->executeFixturesCommandMock); + } + + /** + * @throws ReflectionException + * @throws Exception + */ + public function testCommandWillExecute(): void + { + $configuration = $this->createMock(Configuration::class); + $connection = $this->createMock(Connection::class); + $entityManager = $this->createMock(EntityManager::class); + $entityManager->method('getConnection')->willReturn($connection); + $connection->method('getConfiguration')->willReturn($configuration); + $command = new ExecuteFixturesCommand($entityManager, 'fixtures:execute'); + $reflection = new ReflectionMethod(ExecuteFixturesCommand::class, 'execute'); + + $result = $reflection->invoke( + $command, + new ArgvInput(), + new BufferedOutput() + ); + $this->assertSame($result, Command::SUCCESS); + } +} diff --git a/test/Command/ListFixturesCommandTest.php b/test/Command/ListFixturesCommandTest.php new file mode 100644 index 0000000..876053b --- /dev/null +++ b/test/Command/ListFixturesCommandTest.php @@ -0,0 +1,58 @@ +listFixturesCommandMock = $this->createMock(ListFixturesCommand::class); + } + + public function testCreate(): void + { + $this->assertInstanceOf(ListFixturesCommand::class, $this->listFixturesCommandMock); + } + + /** + * @throws ReflectionException + */ + public function testCommandWillExecute(): void + { + $command = new ListFixturesCommand('test'); + $reflection = new ReflectionMethod(ListFixturesCommand::class, 'execute'); + + $result = $reflection->invoke( + $command, + new ArgvInput(), + new BufferedOutput() + ); + $this->assertSame($result, Command::SUCCESS); + } + + public function testFunctions(): void + { + $command = new ListFixturesCommand('test'); + $defaultName = $command->getName(); + $description = $command->getDescription(); + $this->assertSame('fixtures:list', $defaultName); + $this->assertSame('List all available fixtures.', $description); + } +} diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php new file mode 100644 index 0000000..a9d7c23 --- /dev/null +++ b/test/ConfigProviderTest.php @@ -0,0 +1,38 @@ +config = (new ConfigProvider())(); + } + + public function testHasDependencies(): void + { + $this->assertArrayHasKey('dependencies', $this->config); + } + + public function testDependenciesHasFactories(): void + { + $this->assertArrayHasKey('factories', $this->config['dependencies']); + + $factories = $this->config['dependencies']['factories']; + $this->assertArrayHasKey(ExecuteFixturesCommand::class, $factories); + $this->assertSame(ExecuteFixturesCommandFactory::class, $factories[ExecuteFixturesCommand::class]); + $this->assertArrayHasKey(ListFixturesCommand::class, $factories); + $this->assertSame(ListFixturesCommandFactory::class, $factories[ListFixturesCommand::class]); + } +} diff --git a/test/Exception/NotFoundExceptionTest.php b/test/Exception/NotFoundExceptionTest.php new file mode 100644 index 0000000..713e5f9 --- /dev/null +++ b/test/Exception/NotFoundExceptionTest.php @@ -0,0 +1,28 @@ +exceptionMock = $this->createMock(NotFoundException::class); + } + + public function testCreate() + { + $this->assertInstanceOf(NotFoundException::class, $this->exceptionMock); + } +} diff --git a/test/Factory/ExecuteFixturesCommandFactoryTest.php b/test/Factory/ExecuteFixturesCommandFactoryTest.php new file mode 100644 index 0000000..b057be4 --- /dev/null +++ b/test/Factory/ExecuteFixturesCommandFactoryTest.php @@ -0,0 +1,96 @@ +container = $this->createMock(ContainerInterface::class); + } + + /** + * @throws Exception + * @throws NotFoundException + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function testWillNotCreateServiceWithoutEntityManager(): void + { + $this->container->expects($this->once()) + ->method('has') + ->with(EntityManager::class) + ->willReturn(false); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('EntityManager not found.'); + (new ExecuteFixturesCommandFactory())($this->container); + } + + /** + * @throws NotFoundException + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function testWillNotCreateServiceWithoutPath(): void + { + $this->container->method('has')->willReturnMap([ + [EntityManager::class, true], + ['config', true], + ]); + $this->container->method('get') + ->with('config') + ->willReturn(null); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Key `fixtures` not found in doctrine configuration.'); + (new ExecuteFixturesCommandFactory())($this->container); + } + + /** + * @throws NotFoundExceptionInterface + * @throws NotFoundException + * @throws ContainerExceptionInterface + * @throws Exception + */ + public function testPath(): void + { + $configuration = $this->createMock(Configuration::class); + $connection = $this->createMock(Connection::class); + $entityManager = $this->createMock(EntityManager::class); + $this->container->method('has')->willReturnMap([ + [EntityManager::class, true], + ['config', true], + ]); + + $this->container->method('get')->willReturnMap([ + [EntityManager::class, $entityManager], + ['config', ['doctrine' => ['fixtures' => 'fixtures:list']]], + ]); + + $entityManager->method('getConnection')->willReturn($connection); + $connection->method('getConfiguration')->willReturn($configuration); + $factory = (new ExecuteFixturesCommandFactory())($this->container); + $this->assertInstanceOf(ExecuteFixturesCommand::class, $factory); + $path = $this->container->get('config')['doctrine']['fixtures']; + $this->assertSame('fixtures:list', $path); + } +} diff --git a/test/Factory/ListFixturesCommandFactoryTest.php b/test/Factory/ListFixturesCommandFactoryTest.php new file mode 100644 index 0000000..87ff945 --- /dev/null +++ b/test/Factory/ListFixturesCommandFactoryTest.php @@ -0,0 +1,61 @@ +container = $this->createMock(ContainerInterface::class); + } + + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws NotFoundException + */ + public function testWithoutConfig(): void + { + $this->container->expects($this->once()) + ->method('get') + ->with('config') + ->willReturn(null); + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Key `fixtures` not found in doctrine configuration.'); + $factory = (new ListFixturesCommandFactory())($this->container); + $this->assertInstanceOf(ListFixturesCommand::class, $factory); + } + + /** + * @throws ContainerExceptionInterface + * @throws NotFoundException + * @throws NotFoundExceptionInterface + */ + public function testPathWithConfig(): void + { + $this->container->method('get') + ->with('config') + ->willReturn(['doctrine' => ['fixtures' => 'fixtures:list']]); + $factory = (new ListFixturesCommandFactory())($this->container); + $this->assertInstanceOf(ListFixturesCommand::class, $factory); + $path = $this->container->get('config')['doctrine']['fixtures']; + $this->assertSame('fixtures:list', $path); + } +} From e11f8f5f88a3d269009671ae31254941439d8918 Mon Sep 17 00:00:00 2001 From: poprazvan17 Date: Tue, 8 Aug 2023 16:17:09 +0300 Subject: [PATCH 2/5] implemented phpUnit tests, phpcs and psalm --- README.md | 5 +- composer.json | 8 +- phpunit.xml | 7 +- src/Command/ExecuteFixturesCommand.php | 31 ++++--- src/Command/ListFixturesCommand.php | 17 ++-- src/ConfigProvider.php | 15 ++-- src/Factory/ExecuteFixturesCommandFactory.php | 26 +++++- src/Factory/ListFixturesCommandFactory.php | 10 ++- test/Command/ExecuteFixturesCommandTest.php | 77 +++++++++++----- test/Command/ListFixturesCommandTest.php | 56 +++++++++--- .../ExecuteFixturesCommandFactoryTest.php | 90 ++++++++++++++++++- .../ListFixturesCommandFactoryTest.php | 26 ++++-- 12 files changed, 290 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 4039c1a..8ed4050 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # dot-data-fixtures ![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-data-fixtures) - -![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-data-fixtures/1.0.0) +![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-data-fixtures/1.1.0) [![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-data-fixtures)](https://github.com/dotkernel/dot-data-fixtures/issues) [![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-data-fixtures)](https://github.com/dotkernel/dot-data-fixtures/network) @@ -18,7 +17,7 @@ This package provides a CLI interface for interacting with doctrine/data-fixture **Executing fixtures will **append** data to the tables.** ### Requirements -- PHP >= 7.4 +- PHP >= 8.1 - doctrine/data-fixtures => 1.5 ## Installation diff --git a/composer.json b/composer.json index 26a6f14..63850a0 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,12 @@ }, "autoload": { "psr-4": { - "Dot\\DataFixtures\\": "src" + "Dot\\DataFixtures\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "DotTest\\DataFixtures\\": "test/" } }, "scripts": { @@ -46,6 +51,7 @@ "static-analysis": "psalm --shepherd --stats" }, "config": { + "sort-packages": true, "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } diff --git a/phpunit.xml b/phpunit.xml index eff747d..07d292a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,12 @@ + bootstrap="vendor/autoload.php" + displayDetailsOnTestsThatTriggerDeprecations="true" + displayDetailsOnTestsThatTriggerErrors="true" + displayDetailsOnTestsThatTriggerNotices="true" + displayDetailsOnTestsThatTriggerWarnings="true" + > ./test diff --git a/src/Command/ExecuteFixturesCommand.php b/src/Command/ExecuteFixturesCommand.php index 74778e5..c854478 100644 --- a/src/Command/ExecuteFixturesCommand.php +++ b/src/Command/ExecuteFixturesCommand.php @@ -23,14 +23,25 @@ class ExecuteFixturesCommand extends Command protected static $defaultName = 'fixtures:execute'; private EntityManager $entityManager; + private Loader $loader; + private ORMPurger $purger; + private ORMExecutor $executor; private string $path; - public function __construct(EntityManager $entityManager, string $path) - { + public function __construct( + EntityManager $entityManager, + Loader $loader, + ORMPurger $purger, + ORMExecutor $executor, + string $path + ) { parent::__construct(self::$defaultName); $this->entityManager = $entityManager; + $this->loader = $loader; + $this->purger = $purger; + $this->executor = $executor; $this->path = $path; } @@ -49,20 +60,18 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $loader = new Loader(); - $purger = new ORMPurger($this->entityManager); - - $executor = new ORMExecutor($this->entityManager, $purger); + $this->purger->setEntityManager($this->entityManager); + $this->executor->setPurger($this->purger); - if ($input->getOption('class') === false) { - $loader->loadFromDirectory($this->path); + if (empty($input->getOptions())) { + $this->loader->loadFromDirectory($this->path); } else { - $loader->loadFromFile($this->path . DIRECTORY_SEPARATOR . $input->getOption('class') . '.php'); + $this->loader->loadFromFile($this->path . DIRECTORY_SEPARATOR . $input->getOption('class') . '.php'); } - $fixtures = $loader->getFixtures(); + $fixtures = $this->loader->getFixtures(); - $executor->execute($fixtures, true); + $this->executor->execute($fixtures, true); foreach ($fixtures as $fixture) { $output->writeln(sprintf('Executing %s ', $fixture::class)); diff --git a/src/Command/ListFixturesCommand.php b/src/Command/ListFixturesCommand.php index 323029e..9273609 100644 --- a/src/Command/ListFixturesCommand.php +++ b/src/Command/ListFixturesCommand.php @@ -5,7 +5,9 @@ namespace Dot\DataFixtures\Command; use DateTimeImmutable; +use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Loader; +use Doctrine\Common\DataFixtures\Purger\ORMPurger; use ReflectionClass; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; @@ -19,13 +21,19 @@ class ListFixturesCommand extends Command /** @var string */ protected static $defaultName = 'fixtures:list'; + protected Loader $loader; + protected ORMPurger $purger; + protected ORMExecutor $executor; private string $path; - public function __construct(string $path) + public function __construct(Loader $loader, ORMPurger $purger, ORMExecutor $executor, string $path) { parent::__construct(self::$defaultName); - $this->path = $path; + $this->loader = $loader; + $this->purger = $purger; + $this->executor = $executor; + $this->path = $path; } protected function configure(): void @@ -35,13 +43,12 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $loader = new Loader(); - $loader->loadFromDirectory($this->path); + $this->loader->loadFromDirectory($this->path); $rows = []; $commandName = ExecuteFixturesCommand::getDefaultName(); - foreach ($loader->getFixtures() as $fixture) { + foreach ($this->loader->getFixtures() as $fixture) { $reflectionClass = new ReflectionClass($fixture); $lastUpdatedAt = DateTimeImmutable::createFromFormat( 'U', diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 48e30dc..0196995 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -9,25 +9,20 @@ use Dot\DataFixtures\Factory\ExecuteFixturesCommandFactory; use Dot\DataFixtures\Factory\ListFixturesCommandFactory; +use function getcwd; + class ConfigProvider { - /** - * Returns the configuration array - * - * @return array - */ public function __invoke(): array { return [ 'dependencies' => $this->getDependencies(), + 'doctrine' => [ + 'fixtures' => getcwd() . '/data/doctrine/fixtures', + ], ]; } - /** - * Returns the container dependencies - * - * @return array - */ public function getDependencies(): array { return [ diff --git a/src/Factory/ExecuteFixturesCommandFactory.php b/src/Factory/ExecuteFixturesCommandFactory.php index f77d980..a0ff327 100644 --- a/src/Factory/ExecuteFixturesCommandFactory.php +++ b/src/Factory/ExecuteFixturesCommandFactory.php @@ -4,6 +4,9 @@ namespace Dot\DataFixtures\Factory; +use Doctrine\Common\DataFixtures\Executor\ORMExecutor; +use Doctrine\Common\DataFixtures\Loader; +use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Doctrine\ORM\EntityManager; use Dot\DataFixtures\Command\ExecuteFixturesCommand; use Dot\DataFixtures\Exception\NotFoundException; @@ -17,7 +20,8 @@ class ExecuteFixturesCommandFactory { /** * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface|NotFoundException + * @throws NotFoundException + * @throws NotFoundExceptionInterface */ public function __invoke(ContainerInterface $container): ExecuteFixturesCommand { @@ -25,11 +29,29 @@ public function __invoke(ContainerInterface $container): ExecuteFixturesCommand throw new NotFoundException('EntityManager not found.'); } + if (! $container->has(ORMPurger::class)) { + throw new NotFoundException('ORMPurger not found. '); + } + + if (! $container->has(Loader::class)) { + throw new NotFoundException('Loader not found. '); + } + + if (! $container->has(ORMExecutor::class)) { + throw new NotFoundException('ORMExecutor not found. '); + } + $path = $container->get('config')['doctrine']['fixtures'] ?? null; if (! is_string($path)) { throw new NotFoundException('Key `fixtures` not found in doctrine configuration.'); } - return new ExecuteFixturesCommand($container->get(EntityManager::class), $path); + return new ExecuteFixturesCommand( + $container->get(EntityManager::class), + $container->get(Loader::class), + $container->get(ORMPurger::class), + $container->get(ORMExecutor::class), + $path + ); } } diff --git a/src/Factory/ListFixturesCommandFactory.php b/src/Factory/ListFixturesCommandFactory.php index 6fe9945..e696de7 100644 --- a/src/Factory/ListFixturesCommandFactory.php +++ b/src/Factory/ListFixturesCommandFactory.php @@ -4,6 +4,9 @@ namespace Dot\DataFixtures\Factory; +use Doctrine\Common\DataFixtures\Executor\ORMExecutor; +use Doctrine\Common\DataFixtures\Loader; +use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Dot\DataFixtures\Command\ListFixturesCommand; use Dot\DataFixtures\Exception\NotFoundException; use Psr\Container\ContainerExceptionInterface; @@ -26,6 +29,11 @@ public function __invoke(ContainerInterface $container): ListFixturesCommand throw new NotFoundException('Key `fixtures` not found in doctrine configuration.'); } - return new ListFixturesCommand($path); + return new ListFixturesCommand( + $container->get(Loader::class), + $container->get(ORMPurger::class), + $container->get(ORMExecutor::class), + $path + ); } } diff --git a/test/Command/ExecuteFixturesCommandTest.php b/test/Command/ExecuteFixturesCommandTest.php index c55fb2d..2fe88b5 100644 --- a/test/Command/ExecuteFixturesCommandTest.php +++ b/test/Command/ExecuteFixturesCommandTest.php @@ -4,12 +4,15 @@ namespace DotTest\DataFixtures\Command; +use Doctrine\Common\DataFixtures\Executor\ORMExecutor; +use Doctrine\Common\DataFixtures\Loader; +use Doctrine\Common\DataFixtures\Purger\ORMPurger; +use Doctrine\Common\EventManager; use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManager; use Dot\DataFixtures\Command\ExecuteFixturesCommand; use PHPUnit\Framework\MockObject\Exception; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use ReflectionException; use ReflectionMethod; @@ -17,45 +20,75 @@ use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\BufferedOutput; +use function getcwd; + class ExecuteFixturesCommandTest extends TestCase { - protected ExecuteFixturesCommand|MockObject $executeFixturesCommandMock; - - protected EntityManager|MockObject $entityManager; - /** * @throws Exception */ - public function setUp(): void - { - $this->executeFixturesCommandMock = $this->createMock(ExecuteFixturesCommand::class); - $this->entityManager = $this->createMock(EntityManager::class); - } - - public function testCreateCommand(): void + public function testWillCreateCommand(): void { - $this->assertInstanceOf(ExecuteFixturesCommand::class, $this->executeFixturesCommandMock); + $entityManager = $this->createMock(EntityManager::class); + $loader = $this->createMock(Loader::class); + $purger = $this->createMock(ORMPurger::class); + $executor = $this->createMock(ORMExecutor::class); + $path = getcwd() . '/data/doctrine/fixtures'; + $command = new ExecuteFixturesCommand($entityManager, $loader, $purger, $executor, $path); + $this->assertInstanceOf(ExecuteFixturesCommand::class, $command); } /** * @throws ReflectionException * @throws Exception */ - public function testCommandWillExecute(): void + public function testWillExecuteCommand(): void { $configuration = $this->createMock(Configuration::class); $connection = $this->createMock(Connection::class); $entityManager = $this->createMock(EntityManager::class); - $entityManager->method('getConnection')->willReturn($connection); + $eventManager = $this->createMock(EventManager::class); + $loader = $this->createMock(Loader::class); + $purger = $this->createMock(ORMPurger::class); + $executor = $this->createMock(ORMExecutor::class); $connection->method('getConfiguration')->willReturn($configuration); - $command = new ExecuteFixturesCommand($entityManager, 'fixtures:execute'); - $reflection = new ReflectionMethod(ExecuteFixturesCommand::class, 'execute'); + $entityManager->method('getConnection')->willReturn($connection); + $entityManager->method('getEventManager')->willReturn($eventManager); + $purger->method('getObjectManager')->willReturn($entityManager); + $loader->method('getFixtures')->willReturnMap([ + [ + [], + ], + ]); + $path = getcwd() . '/data/doctrine/fixtures'; - $result = $reflection->invoke( - $command, - new ArgvInput(), - new BufferedOutput() - ); + $command = new ExecuteFixturesCommand($entityManager, $loader, $purger, $executor, $path); + $reflection = new ReflectionMethod(ExecuteFixturesCommand::class, 'execute'); + $result = $reflection->invoke($command, new ArgvInput(), new BufferedOutput()); $this->assertSame($result, Command::SUCCESS); } + + /** + * @throws Exception + */ + public function testConfigure(): void + { + $entityManager = $this->createMock(EntityManager::class); + $loader = $this->createMock(Loader::class); + $purger = $this->createMock(ORMPurger::class); + $executor = $this->createMock(ORMExecutor::class); + + $path = getcwd() . '/data/doctrine/fixtures'; + $command = new ExecuteFixturesCommand($entityManager, $loader, $purger, $executor, $path); + $defaultName = $command->getName(); + $description = $command->getDescription(); + $options = $command->getDefinition()->getOption('class'); + + $this->assertSame('fixtures:execute', $defaultName); + $this->assertSame('Executes one or multiple fixtures.', $description); + $this->assertSame('class', $options->getName()); + $this->assertEmpty($options->getShortcut()); + $this->assertFalse($options->getDefault()); + $this->assertSame('Execute a specific fixture.', $options->getDescription()); + } } diff --git a/test/Command/ListFixturesCommandTest.php b/test/Command/ListFixturesCommandTest.php index 876053b..4887825 100644 --- a/test/Command/ListFixturesCommandTest.php +++ b/test/Command/ListFixturesCommandTest.php @@ -4,9 +4,15 @@ namespace DotTest\DataFixtures\Command; +use Doctrine\Common\DataFixtures\Executor\ORMExecutor; +use Doctrine\Common\DataFixtures\Loader; +use Doctrine\Common\DataFixtures\Purger\ORMPurger; +use Doctrine\Common\EventManager; +use Doctrine\DBAL\Configuration; +use Doctrine\DBAL\Connection; +use Doctrine\ORM\EntityManager; use Dot\DataFixtures\Command\ListFixturesCommand; use PHPUnit\Framework\MockObject\Exception; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use ReflectionException; use ReflectionMethod; @@ -14,29 +20,46 @@ use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\BufferedOutput; +use function getcwd; + class ListFixturesCommandTest extends TestCase { - protected ListFixturesCommand|MockObject $listFixturesCommandMock; - /** * @throws Exception */ - public function setUp(): void - { - $this->listFixturesCommandMock = $this->createMock(ListFixturesCommand::class); - } - - public function testCreate(): void + public function testWillCreateCommand(): void { - $this->assertInstanceOf(ListFixturesCommand::class, $this->listFixturesCommandMock); + $loader = $this->createMock(Loader::class); + $purger = $this->createMock(ORMPurger::class); + $executor = $this->createMock(ORMExecutor::class); + $path = getcwd() . '/data/doctrine/fixtures'; + $command = new ListFixturesCommand($loader, $purger, $executor, $path); + $this->assertInstanceOf(ListFixturesCommand::class, $command); } /** * @throws ReflectionException + * @throws Exception */ - public function testCommandWillExecute(): void + public function testWillExecuteCommand(): void { - $command = new ListFixturesCommand('test'); + $configuration = $this->createMock(Configuration::class); + $connection = $this->createMock(Connection::class); + $entityManager = $this->createMock(EntityManager::class); + $eventManager = $this->createMock(EventManager::class); + $loader = $this->createMock(Loader::class); + $purger = $this->createMock(ORMPurger::class); + $executor = $this->createMock(ORMExecutor::class); + $connection->method('getConfiguration')->willReturn($configuration); + $entityManager->method('getConnection')->willReturn($connection); + $entityManager->method('getEventManager')->willReturn($eventManager); + $purger->method('getObjectManager')->willReturn($entityManager); + $loader->method('getFixtures')->willReturnMap([ + [0 => []], + ]); + $path = getcwd() . '/data/doctrine/fixtures'; + + $command = new ListFixturesCommand($loader, $purger, $executor, $path); $reflection = new ReflectionMethod(ListFixturesCommand::class, 'execute'); $result = $reflection->invoke( @@ -47,9 +70,16 @@ public function testCommandWillExecute(): void $this->assertSame($result, Command::SUCCESS); } + /** + * @throws Exception + */ public function testFunctions(): void { - $command = new ListFixturesCommand('test'); + $loader = $this->createMock(Loader::class); + $purger = $this->createMock(ORMPurger::class); + $executor = $this->createMock(ORMExecutor::class); + $path = getcwd() . '/data/doctrine/fixtures'; + $command = new ListFixturesCommand($loader, $purger, $executor, $path); $defaultName = $command->getName(); $description = $command->getDescription(); $this->assertSame('fixtures:list', $defaultName); diff --git a/test/Factory/ExecuteFixturesCommandFactoryTest.php b/test/Factory/ExecuteFixturesCommandFactoryTest.php index b057be4..7971525 100644 --- a/test/Factory/ExecuteFixturesCommandFactoryTest.php +++ b/test/Factory/ExecuteFixturesCommandFactoryTest.php @@ -4,6 +4,10 @@ namespace DotTest\DataFixtures\Factory; +use Doctrine\Common\DataFixtures\Executor\ORMExecutor; +use Doctrine\Common\DataFixtures\Loader; +use Doctrine\Common\DataFixtures\Purger\ORMPurger; +use Doctrine\Common\EventManager; use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManager; @@ -17,6 +21,8 @@ use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; +use function getcwd; + class ExecuteFixturesCommandFactoryTest extends TestCase { protected ContainerInterface|MockObject $container; @@ -41,11 +47,65 @@ public function testWillNotCreateServiceWithoutEntityManager(): void ->method('has') ->with(EntityManager::class) ->willReturn(false); - $this->expectException(\Exception::class); + $this->expectException(NotFoundException::class); $this->expectExceptionMessage('EntityManager not found.'); (new ExecuteFixturesCommandFactory())($this->container); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function testWillNotCreateServiceWithoutLoader(): void + { + $this->container->method('has')->willReturnMap([ + [EntityManager::class, true], + [Loader::class, false], + [ORMPurger::class, true], + [ORMExecutor::class, true], + ['config', true], + ]); + $this->expectException(NotFoundException::class); + $this->expectExceptionMessage('Loader not found.'); + (new ExecuteFixturesCommandFactory())($this->container); + } + + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function testWillNotCreateServiceWithoutPurger(): void + { + $this->container->method('has')->willReturnMap([ + [EntityManager::class, true], + [Loader::class, true], + [ORMPurger::class, false], + [ORMExecutor::class, true], + ['config', true], + ]); + $this->expectException(NotFoundException::class); + $this->expectExceptionMessage('ORMPurger not found.'); + (new ExecuteFixturesCommandFactory())($this->container); + } + + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function testWillNotCreateServiceWithoutExecutor(): void + { + $this->container->method('has')->willReturnMap([ + [EntityManager::class, true], + [Loader::class, true], + [ORMPurger::class, true], + [ORMExecutor::class, false], + ['config', true], + ]); + $this->expectException(NotFoundException::class); + $this->expectExceptionMessage('ORMExecutor not found.'); + (new ExecuteFixturesCommandFactory())($this->container); + } + /** * @throws NotFoundException * @throws ContainerExceptionInterface @@ -55,12 +115,15 @@ public function testWillNotCreateServiceWithoutPath(): void { $this->container->method('has')->willReturnMap([ [EntityManager::class, true], + [Loader::class, true], + [ORMPurger::class, true], + [ORMExecutor::class, true], ['config', true], ]); $this->container->method('get') ->with('config') ->willReturn(null); - $this->expectException(\Exception::class); + $this->expectException(NotFoundException::class); $this->expectExceptionMessage('Key `fixtures` not found in doctrine configuration.'); (new ExecuteFixturesCommandFactory())($this->container); } @@ -76,14 +139,33 @@ public function testPath(): void $configuration = $this->createMock(Configuration::class); $connection = $this->createMock(Connection::class); $entityManager = $this->createMock(EntityManager::class); + $eventManager = $this->createMock(EventManager::class); + $loader = $this->createMock(Loader::class); + $purger = $this->createMock(ORMPurger::class); + $executor = $this->createMock(ORMExecutor::class); + $connection->method('getConfiguration')->willReturn($configuration); + $entityManager->method('getConnection')->willReturn($connection); + $entityManager->method('getEventManager')->willReturn($eventManager); + $purger->method('getObjectManager')->willReturn($entityManager); + $loader->method('getFixtures')->willReturnMap([ + [ + [], + ], + ]); $this->container->method('has')->willReturnMap([ [EntityManager::class, true], + [Loader::class, true], + [ORMPurger::class, true], + [ORMExecutor::class, true], ['config', true], ]); $this->container->method('get')->willReturnMap([ [EntityManager::class, $entityManager], - ['config', ['doctrine' => ['fixtures' => 'fixtures:list']]], + [Loader::class, $loader], + [ORMPurger::class, $purger], + [ORMExecutor::class, $executor], + ['config', ['doctrine' => ['fixtures' => getcwd() . '/data/doctrine/fixtures']]], ]); $entityManager->method('getConnection')->willReturn($connection); @@ -91,6 +173,6 @@ public function testPath(): void $factory = (new ExecuteFixturesCommandFactory())($this->container); $this->assertInstanceOf(ExecuteFixturesCommand::class, $factory); $path = $this->container->get('config')['doctrine']['fixtures']; - $this->assertSame('fixtures:list', $path); + $this->assertSame(getcwd() . '/data/doctrine/fixtures', $path); } } diff --git a/test/Factory/ListFixturesCommandFactoryTest.php b/test/Factory/ListFixturesCommandFactoryTest.php index 87ff945..c1127bb 100644 --- a/test/Factory/ListFixturesCommandFactoryTest.php +++ b/test/Factory/ListFixturesCommandFactoryTest.php @@ -4,6 +4,10 @@ namespace DotTest\DataFixtures\Factory; +use Doctrine\Common\DataFixtures\Executor\ORMExecutor; +use Doctrine\Common\DataFixtures\Loader; +use Doctrine\Common\DataFixtures\Purger\ORMPurger; +use Doctrine\ORM\EntityManager; use Dot\DataFixtures\Command\ListFixturesCommand; use Dot\DataFixtures\Exception\NotFoundException; use Dot\DataFixtures\Factory\ListFixturesCommandFactory; @@ -14,6 +18,8 @@ use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; +use function getcwd; + class ListFixturesCommandFactoryTest extends TestCase { private ContainerInterface|MockObject $container; @@ -37,7 +43,7 @@ public function testWithoutConfig(): void ->method('get') ->with('config') ->willReturn(null); - $this->expectException(\Exception::class); + $this->expectException(NotFoundException::class); $this->expectExceptionMessage('Key `fixtures` not found in doctrine configuration.'); $factory = (new ListFixturesCommandFactory())($this->container); $this->assertInstanceOf(ListFixturesCommand::class, $factory); @@ -47,15 +53,25 @@ public function testWithoutConfig(): void * @throws ContainerExceptionInterface * @throws NotFoundException * @throws NotFoundExceptionInterface + * @throws Exception */ public function testPathWithConfig(): void { - $this->container->method('get') - ->with('config') - ->willReturn(['doctrine' => ['fixtures' => 'fixtures:list']]); + $entityManager = $this->createMock(EntityManager::class); + $loader = $this->createMock(Loader::class); + $purger = $this->createMock(ORMPurger::class); + $executor = $this->createMock(ORMExecutor::class); + + $this->container->method('get')->willReturnMap([ + [EntityManager::class, $entityManager], + [Loader::class, $loader], + [ORMPurger::class, $purger], + [ORMExecutor::class, $executor], + ['config', ['doctrine' => ['fixtures' => getcwd() . '/data/doctrine/fixtures']]], + ]); $factory = (new ListFixturesCommandFactory())($this->container); $this->assertInstanceOf(ListFixturesCommand::class, $factory); $path = $this->container->get('config')['doctrine']['fixtures']; - $this->assertSame('fixtures:list', $path); + $this->assertSame(getcwd() . '/data/doctrine/fixtures', $path); } } From 419bcd8b62e768159c51530a577bec6303d2cd32 Mon Sep 17 00:00:00 2001 From: poprazvan17 Date: Tue, 8 Aug 2023 16:20:52 +0300 Subject: [PATCH 3/5] implemented phpUnit tests, phpcs and psalm --- src/ConfigProvider.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 0196995..b38332a 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -9,17 +9,12 @@ use Dot\DataFixtures\Factory\ExecuteFixturesCommandFactory; use Dot\DataFixtures\Factory\ListFixturesCommandFactory; -use function getcwd; - class ConfigProvider { public function __invoke(): array { return [ 'dependencies' => $this->getDependencies(), - 'doctrine' => [ - 'fixtures' => getcwd() . '/data/doctrine/fixtures', - ], ]; } From e58229bd4bdecdfda2e2b5bd9af3cb9c1999bc89 Mon Sep 17 00:00:00 2001 From: poprazvan17 Date: Wed, 9 Aug 2023 13:00:02 +0300 Subject: [PATCH 4/5] implemented phpUnit tests, phpcs and psalm --- OSSMETADATA | 2 +- test/Command/ExecuteFixturesCommandTest.php | 2 +- test/Command/ListFixturesCommandTest.php | 2 +- test/Factory/ExecuteFixturesCommandFactoryTest.php | 8 ++++---- test/Factory/ListFixturesCommandFactoryTest.php | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/OSSMETADATA b/OSSMETADATA index 6c7e106..b96d4a4 100644 --- a/OSSMETADATA +++ b/OSSMETADATA @@ -1 +1 @@ -osslifecycle=active \ No newline at end of file +osslifecycle=active diff --git a/test/Command/ExecuteFixturesCommandTest.php b/test/Command/ExecuteFixturesCommandTest.php index 2fe88b5..7390990 100644 --- a/test/Command/ExecuteFixturesCommandTest.php +++ b/test/Command/ExecuteFixturesCommandTest.php @@ -39,8 +39,8 @@ public function testWillCreateCommand(): void } /** - * @throws ReflectionException * @throws Exception + * @throws ReflectionException */ public function testWillExecuteCommand(): void { diff --git a/test/Command/ListFixturesCommandTest.php b/test/Command/ListFixturesCommandTest.php index 4887825..2f07a61 100644 --- a/test/Command/ListFixturesCommandTest.php +++ b/test/Command/ListFixturesCommandTest.php @@ -38,8 +38,8 @@ public function testWillCreateCommand(): void } /** - * @throws ReflectionException * @throws Exception + * @throws ReflectionException */ public function testWillExecuteCommand(): void { diff --git a/test/Factory/ExecuteFixturesCommandFactoryTest.php b/test/Factory/ExecuteFixturesCommandFactoryTest.php index 7971525..aef442a 100644 --- a/test/Factory/ExecuteFixturesCommandFactoryTest.php +++ b/test/Factory/ExecuteFixturesCommandFactoryTest.php @@ -36,9 +36,9 @@ public function setUp(): void } /** + * @throws ContainerExceptionInterface * @throws Exception * @throws NotFoundException - * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function testWillNotCreateServiceWithoutEntityManager(): void @@ -107,8 +107,8 @@ public function testWillNotCreateServiceWithoutExecutor(): void } /** - * @throws NotFoundException * @throws ContainerExceptionInterface + * @throws NotFoundException * @throws NotFoundExceptionInterface */ public function testWillNotCreateServiceWithoutPath(): void @@ -129,10 +129,10 @@ public function testWillNotCreateServiceWithoutPath(): void } /** - * @throws NotFoundExceptionInterface - * @throws NotFoundException * @throws ContainerExceptionInterface * @throws Exception + * @throws NotFoundException + * @throws NotFoundExceptionInterface */ public function testPath(): void { diff --git a/test/Factory/ListFixturesCommandFactoryTest.php b/test/Factory/ListFixturesCommandFactoryTest.php index c1127bb..8bd5166 100644 --- a/test/Factory/ListFixturesCommandFactoryTest.php +++ b/test/Factory/ListFixturesCommandFactoryTest.php @@ -51,9 +51,9 @@ public function testWithoutConfig(): void /** * @throws ContainerExceptionInterface + * @throws Exception * @throws NotFoundException * @throws NotFoundExceptionInterface - * @throws Exception */ public function testPathWithConfig(): void { From c3c357eb94a0fe44eb5097af62ee4fe3b0c76f15 Mon Sep 17 00:00:00 2001 From: poprazvan17 Date: Thu, 10 Aug 2023 11:23:21 +0300 Subject: [PATCH 5/5] exceptions ordered alphabetically --- test/Exception/NotFoundExceptionTest.php | 17 ++++------------- test/Factory/ListFixturesCommandFactoryTest.php | 2 +- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/test/Exception/NotFoundExceptionTest.php b/test/Exception/NotFoundExceptionTest.php index 713e5f9..4c6cf3f 100644 --- a/test/Exception/NotFoundExceptionTest.php +++ b/test/Exception/NotFoundExceptionTest.php @@ -5,24 +5,15 @@ namespace DotTest\DataFixtures\Exception; use Dot\DataFixtures\Exception\NotFoundException; -use PHPUnit\Framework\MockObject\Exception; -use PHPUnit\Framework\MockObject\MockObject; +use Exception; use PHPUnit\Framework\TestCase; class NotFoundExceptionTest extends TestCase { - protected NotFoundException|MockObject $exceptionMock; - - /** - * @throws Exception - */ - public function setUp(): void - { - $this->exceptionMock = $this->createMock(NotFoundException::class); - } - public function testCreate() { - $this->assertInstanceOf(NotFoundException::class, $this->exceptionMock); + $exception = new NotFoundException(); + $this->assertInstanceOf(NotFoundException::class, $exception); + $this->assertInstanceOf(Exception::class, $exception); } } diff --git a/test/Factory/ListFixturesCommandFactoryTest.php b/test/Factory/ListFixturesCommandFactoryTest.php index 8bd5166..667b7d5 100644 --- a/test/Factory/ListFixturesCommandFactoryTest.php +++ b/test/Factory/ListFixturesCommandFactoryTest.php @@ -34,8 +34,8 @@ protected function setUp(): void /** * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface * @throws NotFoundException + * @throws NotFoundExceptionInterface */ public function testWithoutConfig(): void {