Skip to content

Commit

Permalink
Merge pull request dotkernel#8 from poprazvan17/1.0
Browse files Browse the repository at this point in the history
issues: ORMPurger not found - fixed
  • Loading branch information
alexmerlin committed Aug 11, 2023
2 parents 5079466 + 135dfe9 commit f142b98
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 151 deletions.
2 changes: 1 addition & 1 deletion src/Command/ExecuteFixturesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->purger->setEntityManager($this->entityManager);
$this->executor->setPurger($this->purger);

if (empty($input->getOptions())) {
if ($input->getOption('class') === false) {
$this->loader->loadFromDirectory($this->path);
} else {
$this->loader->loadFromFile($this->path . DIRECTORY_SEPARATOR . $input->getOption('class') . '.php');
Expand Down
13 changes: 3 additions & 10 deletions src/Command/ListFixturesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
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;
Expand All @@ -22,18 +20,13 @@ class ListFixturesCommand extends Command
protected static $defaultName = 'fixtures:list';

protected Loader $loader;
protected ORMPurger $purger;
protected ORMExecutor $executor;
private string $path;

public function __construct(Loader $loader, ORMPurger $purger, ORMExecutor $executor, string $path)
public function __construct(Loader $loader, string $path)
{
parent::__construct(self::$defaultName);

$this->loader = $loader;
$this->purger = $purger;
$this->executor = $executor;
$this->path = $path;
$this->loader = $loader;
$this->path = $path;
}

protected function configure(): void
Expand Down
18 changes: 3 additions & 15 deletions src/Factory/ExecuteFixturesCommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,16 @@ 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),
$container->get(Loader::class),
$container->get(ORMPurger::class),
$container->get(ORMExecutor::class),
new Loader(),
new ORMPurger(),
new ORMExecutor($container->get(EntityManager::class)),
$path
);
}
Expand Down
6 changes: 1 addition & 5 deletions src/Factory/ListFixturesCommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

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;
Expand All @@ -30,9 +28,7 @@ public function __invoke(ContainerInterface $container): ListFixturesCommand
}

return new ListFixturesCommand(
$container->get(Loader::class),
$container->get(ORMPurger::class),
$container->get(ORMExecutor::class),
new Loader(),
$path
);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Command/ExecuteFixturesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testWillExecuteCommand(): void

$command = new ExecuteFixturesCommand($entityManager, $loader, $purger, $executor, $path);
$reflection = new ReflectionMethod(ExecuteFixturesCommand::class, 'execute');
$result = $reflection->invoke($command, new ArgvInput(), new BufferedOutput());
$result = $reflection->invoke($command, new ArgvInput([], $command->getDefinition()), new BufferedOutput());
$this->assertSame($result, Command::SUCCESS);
}

Expand Down
36 changes: 9 additions & 27 deletions test/Command/ListFixturesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@

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\TestCase;
Expand All @@ -29,11 +23,9 @@ class ListFixturesCommandTest extends TestCase
*/
public function testWillCreateCommand(): 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);
$loader = $this->createMock(Loader::class);
$path = getcwd() . '/data/doctrine/fixtures';
$command = new ListFixturesCommand($loader, $path);
$this->assertInstanceOf(ListFixturesCommand::class, $command);
}

Expand All @@ -43,23 +35,15 @@ public function testWillCreateCommand(): void
*/
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 = $this->createMock(Loader::class);
$loader->method('getFixtures')->willReturnMap([
[0 => []],
[
[],
],
]);
$path = getcwd() . '/data/doctrine/fixtures';

$command = new ListFixturesCommand($loader, $purger, $executor, $path);
$command = new ListFixturesCommand($loader, $path);
$reflection = new ReflectionMethod(ListFixturesCommand::class, 'execute');

$result = $reflection->invoke(
Expand All @@ -76,10 +60,8 @@ public function testWillExecuteCommand(): void
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);
$command = new ListFixturesCommand($loader, $path);
$defaultName = $command->getName();
$description = $command->getDescription();
$this->assertSame('fixtures:list', $defaultName);
Expand Down
2 changes: 1 addition & 1 deletion test/Exception/NotFoundExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class NotFoundExceptionTest extends TestCase
{
public function testCreate()
public function testCreate(): void
{
$exception = new NotFoundException();
$this->assertInstanceOf(NotFoundException::class, $exception);
Expand Down
78 changes: 1 addition & 77 deletions test/Factory/ExecuteFixturesCommandFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

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;
Expand Down Expand Up @@ -52,60 +49,6 @@ public function testWillNotCreateServiceWithoutEntityManager(): void
(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
Expand All @@ -115,9 +58,6 @@ 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')
Expand All @@ -140,36 +80,20 @@ public function testPath(): void
$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'];
Expand Down
14 changes: 0 additions & 14 deletions test/Factory/ListFixturesCommandFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

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;
Expand Down Expand Up @@ -51,22 +47,12 @@ public function testWithoutConfig(): void

/**
* @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);
Expand Down

0 comments on commit f142b98

Please sign in to comment.