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/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/README.md b/README.md
index 9576854..8ed4050 100644
--- a/README.md
+++ b/README.md
@@ -1,21 +1,23 @@
# 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)
[![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.
**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 653ece9..63850a0 100644
--- a/composer.json
+++ b/composer.json
@@ -20,15 +20,40 @@
"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"
+ "Dot\\DataFixtures\\": "src/"
+ }
+ },
+ "autoload-dev": {
+ "psr-4": {
+ "DotTest\\DataFixtures\\": "test/"
+ }
+ },
+ "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": {
+ "sort-packages": true,
+ "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..07d292a
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,15 @@
+
+
+
+
+ ./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..c854478 100644
--- a/src/Command/ExecuteFixturesCommand.php
+++ b/src/Command/ExecuteFixturesCommand.php
@@ -1,48 +1,50 @@
entityManager = $entityManager;
- $this->path = $path;
+ $this->loader = $loader;
+ $this->purger = $purger;
+ $this->executor = $executor;
+ $this->path = $path;
}
- /**
- * @return void
- */
protected function configure(): void
{
$this->setName(self::$defaultName)
@@ -56,30 +58,23 @@ protected function configure(): void
);
}
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return int
- */
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 ', 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..9273609 100644
--- a/src/Command/ListFixturesCommand.php
+++ b/src/Command/ListFixturesCommand.php
@@ -1,66 +1,63 @@
path = $path;
+ $this->loader = $loader;
+ $this->purger = $purger;
+ $this->executor = $executor;
+ $this->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);
+ $this->loader->loadFromDirectory($this->path);
+
+ $rows = [];
+ $commandName = ExecuteFixturesCommand::getDefaultName();
- $rows = [];
- foreach ($loader->getFixtures() as $fixture) {
+ foreach ($this->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..b38332a 100644
--- a/src/ConfigProvider.php
+++ b/src/ConfigProvider.php
@@ -9,17 +9,8 @@
use Dot\DataFixtures\Factory\ExecuteFixturesCommandFactory;
use Dot\DataFixtures\Factory\ListFixturesCommandFactory;
-/**
- * Class ConfigProvider
- * @package Dot\DataFixtures
- */
class ConfigProvider
{
- /**
- * Returns the configuration array
- *
- * @return array
- */
public function __invoke(): array
{
return [
@@ -27,17 +18,12 @@ public function __invoke(): array
];
}
- /**
- * Returns the container dependencies
- *
- * @return 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.');
}
+ 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 ac5f23a..e696de7 100644
--- a/src/Factory/ListFixturesCommandFactory.php
+++ b/src/Factory/ListFixturesCommandFactory.php
@@ -1,16 +1,26 @@
get(Loader::class),
+ $container->get(ORMPurger::class),
+ $container->get(ORMExecutor::class),
+ $path
+ );
}
}
diff --git a/test/Command/ExecuteFixturesCommandTest.php b/test/Command/ExecuteFixturesCommandTest.php
new file mode 100644
index 0000000..7390990
--- /dev/null
+++ b/test/Command/ExecuteFixturesCommandTest.php
@@ -0,0 +1,94 @@
+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 Exception
+ * @throws ReflectionException
+ */
+ public function testWillExecuteCommand(): 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([
+ [
+ [],
+ ],
+ ]);
+ $path = getcwd() . '/data/doctrine/fixtures';
+
+ $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
new file mode 100644
index 0000000..2f07a61
--- /dev/null
+++ b/test/Command/ListFixturesCommandTest.php
@@ -0,0 +1,88 @@
+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 Exception
+ * @throws ReflectionException
+ */
+ public function testWillExecuteCommand(): 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([
+ [0 => []],
+ ]);
+ $path = getcwd() . '/data/doctrine/fixtures';
+
+ $command = new ListFixturesCommand($loader, $purger, $executor, $path);
+ $reflection = new ReflectionMethod(ListFixturesCommand::class, 'execute');
+
+ $result = $reflection->invoke(
+ $command,
+ new ArgvInput(),
+ new BufferedOutput()
+ );
+ $this->assertSame($result, Command::SUCCESS);
+ }
+
+ /**
+ * @throws Exception
+ */
+ public function testFunctions(): void
+ {
+ $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);
+ $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..4c6cf3f
--- /dev/null
+++ b/test/Exception/NotFoundExceptionTest.php
@@ -0,0 +1,19 @@
+assertInstanceOf(NotFoundException::class, $exception);
+ $this->assertInstanceOf(Exception::class, $exception);
+ }
+}
diff --git a/test/Factory/ExecuteFixturesCommandFactoryTest.php b/test/Factory/ExecuteFixturesCommandFactoryTest.php
new file mode 100644
index 0000000..aef442a
--- /dev/null
+++ b/test/Factory/ExecuteFixturesCommandFactoryTest.php
@@ -0,0 +1,178 @@
+container = $this->createMock(ContainerInterface::class);
+ }
+
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws Exception
+ * @throws NotFoundException
+ * @throws NotFoundExceptionInterface
+ */
+ public function testWillNotCreateServiceWithoutEntityManager(): void
+ {
+ $this->container->expects($this->once())
+ ->method('has')
+ ->with(EntityManager::class)
+ ->willReturn(false);
+ $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 ContainerExceptionInterface
+ * @throws NotFoundException
+ * @throws NotFoundExceptionInterface
+ */
+ 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(NotFoundException::class);
+ $this->expectExceptionMessage('Key `fixtures` not found in doctrine configuration.');
+ (new ExecuteFixturesCommandFactory())($this->container);
+ }
+
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws Exception
+ * @throws NotFoundException
+ * @throws NotFoundExceptionInterface
+ */
+ 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],
+ [Loader::class, $loader],
+ [ORMPurger::class, $purger],
+ [ORMExecutor::class, $executor],
+ ['config', ['doctrine' => ['fixtures' => getcwd() . '/data/doctrine/fixtures']]],
+ ]);
+
+ $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(getcwd() . '/data/doctrine/fixtures', $path);
+ }
+}
diff --git a/test/Factory/ListFixturesCommandFactoryTest.php b/test/Factory/ListFixturesCommandFactoryTest.php
new file mode 100644
index 0000000..667b7d5
--- /dev/null
+++ b/test/Factory/ListFixturesCommandFactoryTest.php
@@ -0,0 +1,77 @@
+container = $this->createMock(ContainerInterface::class);
+ }
+
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundException
+ * @throws NotFoundExceptionInterface
+ */
+ public function testWithoutConfig(): void
+ {
+ $this->container->expects($this->once())
+ ->method('get')
+ ->with('config')
+ ->willReturn(null);
+ $this->expectException(NotFoundException::class);
+ $this->expectExceptionMessage('Key `fixtures` not found in doctrine configuration.');
+ $factory = (new ListFixturesCommandFactory())($this->container);
+ $this->assertInstanceOf(ListFixturesCommand::class, $factory);
+ }
+
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws Exception
+ * @throws NotFoundException
+ * @throws NotFoundExceptionInterface
+ */
+ public function testPathWithConfig(): void
+ {
+ $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(getcwd() . '/data/doctrine/fixtures', $path);
+ }
+}