From e197a002ea31f20e8cf48c899f2bc4042dba832f Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 15 Dec 2013 17:58:35 +0100 Subject: [PATCH 01/15] Added Option to specify single Fixture or directory. Fixes #3 --- .../Command/ImportCommand.php | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/DoctrineDataFixtureModule/Command/ImportCommand.php b/src/DoctrineDataFixtureModule/Command/ImportCommand.php index 829c377..3db9e00 100644 --- a/src/DoctrineDataFixtureModule/Command/ImportCommand.php +++ b/src/DoctrineDataFixtureModule/Command/ImportCommand.php @@ -59,7 +59,13 @@ protected function configure() EOT ) ->addOption('append', null, InputOption::VALUE_NONE, 'Append data to existing data.') - ->addOption('purge-with-truncate', null, InputOption::VALUE_NONE, 'Truncate tables before inserting data'); + ->addOption('purge-with-truncate', null, InputOption::VALUE_NONE, 'Truncate tables before inserting data') + ->addOption( + 'fixtures', + null, + InputOption::VALUE_REQUIRED, + 'Set path to Fixture Class or Directory to be added' + ); } public function execute(InputInterface $input, OutputInterface $output) @@ -73,9 +79,27 @@ public function execute(InputInterface $input, OutputInterface $output) $executor = new ORMExecutor($this->em, $purger); - foreach ($this->paths as $key => $value) { - $loader->loadFromDirectory($value); + if ($input->getOption('fixtures') != null) { + $fixtures = $input->getOption('fixtures'); + if (is_dir($fixtures)) { + $loader->loadFromDirectory($fixtures); + } elseif (file_exists($fixtures)) { + $classes = get_declared_classes(); + include($fixtures); + $newClasses = get_declared_classes(); + + $diff = array_diff($newClasses, $classes); + $class = array_pop($diff); + $loader->addFixture(new $class); + } else { + throw new \RuntimeException('Cannot find File or Directory.'); + } + } else { + foreach ($this->paths as $key => $value) { + $loader->loadFromDirectory($value); + } } + $executor->execute($loader->getFixtures(), $input->getOption('append')); } From a80eb6186d693b1626739aa3a1bd8c2bd021ccc9 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 15 Dec 2013 19:20:20 +0100 Subject: [PATCH 02/15] Modified Readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 7ec769a..56cb6b0 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,11 @@ Access the Doctrine command line as following ```sh ./vendor/bin/doctrine-module ``` + +##Options + +--append + +--purge-with-truncate + +--fixtures=./path/to/fixtures/or/directory \ No newline at end of file From 165d81e17386245cc52e5ada0038d0170beea466 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 29 Jan 2014 21:22:34 +0100 Subject: [PATCH 03/15] Added Tests for import command --- .../Command/ImportCommand.php | 35 +++-- src/DoctrineDataFixtureModule/Module.php | 2 + .../Command/ImportCommandTest.php | 129 ++++++++++++++++++ .../TestAsset/Entity/Role.php | 36 +++++ .../TestAsset/Entity/User.php | 76 +++++++++++ 5 files changed, 268 insertions(+), 10 deletions(-) create mode 100644 tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php create mode 100644 tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php create mode 100644 tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php diff --git a/src/DoctrineDataFixtureModule/Command/ImportCommand.php b/src/DoctrineDataFixtureModule/Command/ImportCommand.php index f5054a8..a74fa02 100644 --- a/src/DoctrineDataFixtureModule/Command/ImportCommand.php +++ b/src/DoctrineDataFixtureModule/Command/ImportCommand.php @@ -51,12 +51,21 @@ class ImportCommand extends Command * @var Zend\ServiceManager\ServiceLocatorInterface */ protected $serviceLocator; + /** + * ServiceLocatorAwareLoader + * @var DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader + */ + protected $loader; + + protected $purger; const PURGE_MODE_TRUNCATE = 2; public function __construct(ServiceLocatorInterface $serviceLocator) { $this->serviceLocator = $serviceLocator; + $this->loader = new ServiceLocatorAwareLoader($this->serviceLocator); + parent::__construct(); } @@ -83,19 +92,14 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { - $loader = new ServiceLocatorAwareLoader($this->serviceLocator); - $purger = new ORMPurger(); - if ($input->getOption('purge-with-truncate')) { - $purger->setPurgeMode(self::PURGE_MODE_TRUNCATE); + $this->purger->setPurgeMode(self::PURGE_MODE_TRUNCATE); } - $executor = new ORMExecutor($this->em, $purger); - if ($input->getOption('fixtures') != null) { $fixtures = $input->getOption('fixtures'); if (is_dir($fixtures)) { - $loader->loadFromDirectory($fixtures); + $this->loader->loadFromDirectory($fixtures); } elseif (file_exists($fixtures)) { $classes = get_declared_classes(); include($fixtures); @@ -103,17 +107,18 @@ public function execute(InputInterface $input, OutputInterface $output) $diff = array_diff($newClasses, $classes); $class = array_pop($diff); - $loader->addFixture(new $class); + $this->loader->addFixture(new $class); } else { throw new \RuntimeException('Cannot find File or Directory.'); } } else { foreach ($this->paths as $key => $value) { - $loader->loadFromDirectory($value); + $this->loader->loadFromDirectory($value); } } - $executor->execute($loader->getFixtures(), $input->getOption('append')); + $executor = new ORMExecutor($this->em, $this->purger); + $executor->execute($this->loader->getFixtures(), $input->getOption('append')); } public function setPath($paths) @@ -125,4 +130,14 @@ public function setEntityManager($em) { $this->em = $em; } + + public function getLoader() + { + return $this->loader; + } + + public function setPurger(ORMPurger $purger) + { + $this->purger = $purger; + } } diff --git a/src/DoctrineDataFixtureModule/Module.php b/src/DoctrineDataFixtureModule/Module.php index a229110..2dd674f 100644 --- a/src/DoctrineDataFixtureModule/Module.php +++ b/src/DoctrineDataFixtureModule/Module.php @@ -27,6 +27,7 @@ use Doctrine\ORM\Tools\Console\ConsoleRunner; use DoctrineDataFixtureModule\Command\ImportCommand; use DoctrineDataFixtureModule\Service\FixtureFactory; +use Doctrine\Common\DataFixtures\Purger\ORMPurger; /** * Base module for Doctrine Data Fixture. @@ -74,6 +75,7 @@ public function init(ModuleManager $e) $importCommand = new ImportCommand($sm); $importCommand->setEntityManager($em); $importCommand->setPath($paths); + $importCommand->setORMPurger(new ORMPurger); ConsoleRunner::addCommands($cli); $cli->addCommands(array( $importCommand diff --git a/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php b/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php new file mode 100644 index 0000000..63dc760 --- /dev/null +++ b/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php @@ -0,0 +1,129 @@ +. + */ +namespace DoctrineDataFixtureTest\Command; + + +use DoctrineDataFixtureModule\Command\ImportCommand; +use Doctrine\ORM\EntityManager; +use Symfony\Component\Console\Tester\CommandTester; + +use Zend\ServiceManager\ServiceManager; +use Zend\Mvc\Service\ServiceManagerConfig; +use PHPUnit_Framework_TestCase; +use Doctrine\ORM\Tools\Setup; + +/** + * Test Import commands for fixtures + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @author Martin Shwalbe + */ +class ImportCommandTest extends PHPUnit_Framework_TestCase +{ + /** + * @dataProvider provider + */ + public function testExecute($option, $value, $assert) + { + $serviceLocator = new ServiceManager(new ServiceManagerConfig()); + + $command = new ImportCommand($serviceLocator); + + $command->setentityManager($this->getMockSqliteEntityManager()); + $command->setPurger($this->getMockPurger()); + $paths = array( + 'DoctrineDataFixture_Test_Paths' => __DIR__ . '/../TestAsset/Fixtures/NoSL', + ); + $command->setPath($paths); + + $commandTester = new CommandTester($command); + $commandTester->execute( + array( + $option=> $value, + ) + ); + + $loader= $command->getLoader(); + $fixtures = $loader->getFixtures(); + + $this->assertArrayHasKey($assert, $fixtures); + } + + public function provider() { + return array( + array('--append', true, 'DoctrineDataFixtureTest\TestAsset\Fixtures\NoSL\FixtureA'), + array('--fixtures', __DIR__ . '/../TestAsset/Fixtures/NoSL', 'DoctrineDataFixtureTest\TestAsset\Fixtures\NoSL\FixtureA'), + array('--fixtures', __DIR__ . '/../TestAsset/Fixtures/HasSL/FixtureA.php', 'DoctrineDataFixtureTest\TestAsset\Fixtures\HasSL\FixtureA') + ); + } + + private function getMockFixture($em) + { + return $this->getMock('Doctrine\Common\DataFixtures\FixtureInterface'); + } + + private function getMockPurger() + { + return $this->getMock('Doctrine\Common\DataFixtures\Purger\ORMPurger'); + } + + /** + * EntityManager mock object together with + * annotation mapping driver and pdo_sqlite + * database in memory + * + * @return EntityManager + */ + protected function getMockSqliteEntityManager() + { + $dbParams = array('driver' => 'pdo_sqlite', 'memory' => true); + $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/../TestAsset/Entity'), true); + return EntityManager::create($dbParams, $config); + } + + protected function getMockEntityManager() + { + $driver = $this->getMock('Doctrine\DBAL\Driver'); + $driver->expects($this->once()) + ->method('getDatabasePlatform') + ->will($this->returnValue($this->getMock('Doctrine\DBAL\Platforms\MySqlPlatform'))); + + $conn = $this->getMock('Doctrine\DBAL\Connection', array(), array(array(), $driver)); + $conn->expects($this->once()) + ->method('getEventManager') + ->will($this->returnValue($this->getMock('Doctrine\Common\EventManager'))); + + $config = $this->getMock('Doctrine\ORM\Configuration'); + $config->expects($this->once()) + ->method('getProxyDir') + ->will($this->returnValue('test')); + + $config->expects($this->once()) + ->method('getProxyNamespace') + ->will($this->returnValue('Proxies')); + + $config->expects($this->once()) + ->method('getMetadataDriverImpl') + ->will($this->returnValue($this->getMock('Doctrine\ORM\Mapping\Driver\DriverChain'))); + + $em = EntityManager::create($conn, $config); + return $em; + } +} diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php new file mode 100644 index 0000000..5ab3786 --- /dev/null +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php @@ -0,0 +1,36 @@ +id; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } +} \ No newline at end of file diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php new file mode 100644 index 0000000..e9aa8f3 --- /dev/null +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php @@ -0,0 +1,76 @@ +id = $id; + } + + public function setCode($code) + { + $this->code = $code; + } + + public function setPassword($password) + { + $this->password = md5($password); + } + + public function getPassword() + { + return $this->password; + } + + public function setEmail($email) + { + $this->email = $email; + } + + public function getEmail() + { + return $this->email; + } + + public function setRole(Role $role) + { + $this->role = $role; + } + + public function getRole() + { + return $this->role; + } +} \ No newline at end of file From f8d5008277017f0621e6a2d5d5b0f51cea1f26ee Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 29 Jan 2014 22:39:54 +0100 Subject: [PATCH 04/15] Refactored execute and moved loading of files to loader --- clover.xml | 156 ++++++++++++++++++ .../Command/ImportCommand.php | 58 ++----- .../Loader/ServiceLocatorAwareLoader.php | 24 +++ src/DoctrineDataFixtureModule/Module.php | 6 +- .../Command/ImportCommandTest.php | 83 +++------- .../Loader/ServiceLocatorAwareLoaderTest.php | 44 +++++ .../TestAsset/Entity/Role.php | 2 +- .../TestAsset/Fixtures/FixtureA.php | 12 ++ 8 files changed, 275 insertions(+), 110 deletions(-) create mode 100644 clover.xml create mode 100644 tests/DoctrineDataFixtureTest/TestAsset/Fixtures/FixtureA.php diff --git a/clover.xml b/clover.xml new file mode 100644 index 0000000..050e1be --- /dev/null +++ b/clover.xml @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/DoctrineDataFixtureModule/Command/ImportCommand.php b/src/DoctrineDataFixtureModule/Command/ImportCommand.php index a74fa02..30d3ff0 100644 --- a/src/DoctrineDataFixtureModule/Command/ImportCommand.php +++ b/src/DoctrineDataFixtureModule/Command/ImportCommand.php @@ -29,7 +29,7 @@ use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Purger\ORMPurger; use DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader; -use Zend\ServiceManager\ServiceLocatorInterface; +use Doctrine\ORM\EntityManager; /** * Command for generate migration classes by comparing your current database schema @@ -46,11 +46,6 @@ class ImportCommand extends Command protected $em; - /** - * Service Locator instance - * @var Zend\ServiceManager\ServiceLocatorInterface - */ - protected $serviceLocator; /** * ServiceLocatorAwareLoader * @var DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader @@ -61,10 +56,12 @@ class ImportCommand extends Command const PURGE_MODE_TRUNCATE = 2; - public function __construct(ServiceLocatorInterface $serviceLocator) + public function __construct(ServiceLocatorAwareLoader $loader, ORMPurger $purger, EntityManager $em, array $paths = null) { - $this->serviceLocator = $serviceLocator; - $this->loader = new ServiceLocatorAwareLoader($this->serviceLocator); + $this->loader = $loader; + $this->purger = $purger; + $this->em = $em; + $this->paths = $paths; parent::__construct(); } @@ -97,47 +94,14 @@ public function execute(InputInterface $input, OutputInterface $output) } if ($input->getOption('fixtures') != null) { - $fixtures = $input->getOption('fixtures'); - if (is_dir($fixtures)) { - $this->loader->loadFromDirectory($fixtures); - } elseif (file_exists($fixtures)) { - $classes = get_declared_classes(); - include($fixtures); - $newClasses = get_declared_classes(); - - $diff = array_diff($newClasses, $classes); - $class = array_pop($diff); - $this->loader->addFixture(new $class); - } else { - throw new \RuntimeException('Cannot find File or Directory.'); - } + $this->loader->loadPath($input->getOption('fixtures')); } else { - foreach ($this->paths as $key => $value) { - $this->loader->loadFromDirectory($value); - } + $this->loader->loadPaths($this->paths); } - - $executor = new ORMExecutor($this->em, $this->purger); - $executor->execute($this->loader->getFixtures(), $input->getOption('append')); - } - - public function setPath($paths) - { - $this->paths=$paths; - } - public function setEntityManager($em) - { - $this->em = $em; - } - - public function getLoader() - { - return $this->loader; - } + $executor = new ORMExecutor($this->em, $this->purger); - public function setPurger(ORMPurger $purger) - { - $this->purger = $purger; + + $executor->execute($this->loader->getFixtures(), $input->getOption('append')); } } diff --git a/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php b/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php index a3d05d1..3982dff 100644 --- a/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php +++ b/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php @@ -55,4 +55,28 @@ public function addFixture(FixtureInterface $fixture) } parent::addFixture($fixture); } + + public function loadPath($path) + { + if (is_dir($path)) { + $this->loadFromDirectory($path); + } elseif (file_exists($path)) { + $classes = get_declared_classes(); + include($path); + $newClasses = get_declared_classes(); + + $diff = array_diff($newClasses, $classes); + $class = array_pop($diff); + $this->addFixture(new $class); + } else { + throw new \RuntimeException('Cannot find File or Directory.'); + } + } + + public function loadPaths($paths) + { + foreach ($paths as $key => $value) { + $this->loadFromDirectory($value); + } + } } diff --git a/src/DoctrineDataFixtureModule/Module.php b/src/DoctrineDataFixtureModule/Module.php index 2dd674f..9ba4989 100644 --- a/src/DoctrineDataFixtureModule/Module.php +++ b/src/DoctrineDataFixtureModule/Module.php @@ -71,11 +71,9 @@ public function init(ModuleManager $e) $sm = $e->getParam('ServiceManager'); $em = $sm->get('doctrine.entitymanager.orm_default'); $paths = $sm->get('doctrine.configuration.fixtures'); + $loader = new ServiceLocatorAwareLoader($sm) - $importCommand = new ImportCommand($sm); - $importCommand->setEntityManager($em); - $importCommand->setPath($paths); - $importCommand->setORMPurger(new ORMPurger); + $importCommand = new ImportCommand($loader, new ORMPurger, $em, $paths); ConsoleRunner::addCommands($cli); $cli->addCommands(array( $importCommand diff --git a/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php b/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php index 63dc760..c80a3c5 100644 --- a/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php +++ b/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php @@ -23,11 +23,11 @@ use Doctrine\ORM\EntityManager; use Symfony\Component\Console\Tester\CommandTester; -use Zend\ServiceManager\ServiceManager; -use Zend\Mvc\Service\ServiceManagerConfig; use PHPUnit_Framework_TestCase; use Doctrine\ORM\Tools\Setup; +use Zend\ServiceManager\ServiceManager; +use Zend\Mvc\Service\ServiceManagerConfig; /** * Test Import commands for fixtures * @@ -37,44 +37,23 @@ */ class ImportCommandTest extends PHPUnit_Framework_TestCase { - /** - * @dataProvider provider - */ - public function testExecute($option, $value, $assert) + public function testExecute() { - $serviceLocator = new ServiceManager(new ServiceManagerConfig()); - - $command = new ImportCommand($serviceLocator); - - $command->setentityManager($this->getMockSqliteEntityManager()); - $command->setPurger($this->getMockPurger()); $paths = array( 'DoctrineDataFixture_Test_Paths' => __DIR__ . '/../TestAsset/Fixtures/NoSL', ); - $command->setPath($paths); + + $command = new ImportCommand($this->getMockServiceLocatorAwareLoader(), $this->getMockPurger(), $this->getMockSqliteEntityManager(), $paths); $commandTester = new CommandTester($command); $commandTester->execute( array( - $option=> $value, + '--append' => 'true', ) ); - - $loader= $command->getLoader(); - $fixtures = $loader->getFixtures(); - - $this->assertArrayHasKey($assert, $fixtures); } - public function provider() { - return array( - array('--append', true, 'DoctrineDataFixtureTest\TestAsset\Fixtures\NoSL\FixtureA'), - array('--fixtures', __DIR__ . '/../TestAsset/Fixtures/NoSL', 'DoctrineDataFixtureTest\TestAsset\Fixtures\NoSL\FixtureA'), - array('--fixtures', __DIR__ . '/../TestAsset/Fixtures/HasSL/FixtureA.php', 'DoctrineDataFixtureTest\TestAsset\Fixtures\HasSL\FixtureA') - ); - } - - private function getMockFixture($em) + private function getMockFixture() { return $this->getMock('Doctrine\Common\DataFixtures\FixtureInterface'); } @@ -84,6 +63,23 @@ private function getMockPurger() return $this->getMock('Doctrine\Common\DataFixtures\Purger\ORMPurger'); } + protected function getMockServiceLocatorAwareLoader() + { + $loader = $this->getMock( + 'DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader', + array(), + array(new ServiceManager(new ServiceManagerConfig())) + ); + + $loader->expects($this->once()) + ->method('getFixtures') + ->will($this->returnValue( + array($this->getMockFixture()) + )); + + return $loader; + } + /** * EntityManager mock object together with * annotation mapping driver and pdo_sqlite @@ -97,33 +93,4 @@ protected function getMockSqliteEntityManager() $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/../TestAsset/Entity'), true); return EntityManager::create($dbParams, $config); } - - protected function getMockEntityManager() - { - $driver = $this->getMock('Doctrine\DBAL\Driver'); - $driver->expects($this->once()) - ->method('getDatabasePlatform') - ->will($this->returnValue($this->getMock('Doctrine\DBAL\Platforms\MySqlPlatform'))); - - $conn = $this->getMock('Doctrine\DBAL\Connection', array(), array(array(), $driver)); - $conn->expects($this->once()) - ->method('getEventManager') - ->will($this->returnValue($this->getMock('Doctrine\Common\EventManager'))); - - $config = $this->getMock('Doctrine\ORM\Configuration'); - $config->expects($this->once()) - ->method('getProxyDir') - ->will($this->returnValue('test')); - - $config->expects($this->once()) - ->method('getProxyNamespace') - ->will($this->returnValue('Proxies')); - - $config->expects($this->once()) - ->method('getMetadataDriverImpl') - ->will($this->returnValue($this->getMock('Doctrine\ORM\Mapping\Driver\DriverChain'))); - - $em = EntityManager::create($conn, $config); - return $em; - } -} +} \ No newline at end of file diff --git a/tests/DoctrineDataFixtureTest/Loader/ServiceLocatorAwareLoaderTest.php b/tests/DoctrineDataFixtureTest/Loader/ServiceLocatorAwareLoaderTest.php index 84343c7..cd9f0ca 100644 --- a/tests/DoctrineDataFixtureTest/Loader/ServiceLocatorAwareLoaderTest.php +++ b/tests/DoctrineDataFixtureTest/Loader/ServiceLocatorAwareLoaderTest.php @@ -71,4 +71,48 @@ public function testLoadingFixtureWhichIsServiceLocatorAware() $this->assertInstanceOf('Zend\ServiceManager\ServiceLocatorAwareInterface', $fixture); $this->assertSame($serviceLocator, $fixture->getServiceLocator()); } + + public function testLoadingByConfigPaths() + { + $paths = array( + 'DoctrineDataFixture_Test_Paths_NoSL' => __DIR__ . '/../TestAsset/Fixtures/NoSL', + 'DoctrineDataFixture_Test_Paths_HasSL' => __DIR__ . '/../TestAsset/Fixtures/HasSL', + ); + + $serviceLocator = new ServiceManager(new ServiceManagerConfig()); + + $loader = new ServiceLocatorAwareLoader($serviceLocator); + $loader->loadPaths($paths); + $fixtures = $loader->getFixtures(); + + $this->assertArrayHasKey('DoctrineDataFixtureTest\TestAsset\Fixtures\HasSL\FixtureA', $fixtures); + $this->assertArrayHasKey('DoctrineDataFixtureTest\TestAsset\Fixtures\NoSL\FixtureA', $fixtures); + + + } + + public function testLoadingByDirectoryPath() + { + $fixturePath = __DIR__ . '/../TestAsset/Fixtures/HasSL'; + $serviceLocator = new ServiceManager(new ServiceManagerConfig()); + + $loader = new ServiceLocatorAwareLoader($serviceLocator); + $loader->loadPath($fixturePath); + $fixtures = $loader->getFixtures(); + + $this->assertArrayHasKey('DoctrineDataFixtureTest\TestAsset\Fixtures\HasSL\FixtureA', $fixtures); + } + + public function testLoadingByPath() + { + $fixturePath = __DIR__ . '/../TestAsset/Fixtures/FixtureA.php'; + $serviceLocator = new ServiceManager(new ServiceManagerConfig()); + + $loader = new ServiceLocatorAwareLoader($serviceLocator); + $loader->loadPath($fixturePath); + $fixtures = $loader->getFixtures(); + + $this->assertArrayHasKey('DoctrineDataFixtureTest\TestAsset\Fixtures\FixtureA', $fixtures); + + } } diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php index 5ab3786..77443f3 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php @@ -1,6 +1,6 @@ Date: Sat, 1 Feb 2014 13:41:29 +0100 Subject: [PATCH 05/15] Fixed PHPCS and added assertion to ImportCommandTest --- clover.xml | 48 +++++++++---------- .../Command/ImportCommand.php | 8 +++- .../Command/ImportCommandTest.php | 25 ++++++++-- .../TestAsset/Entity/Role.php | 2 +- .../TestAsset/Entity/User.php | 2 +- 5 files changed, 52 insertions(+), 33 deletions(-) diff --git a/clover.xml b/clover.xml index 050e1be..99b136b 100644 --- a/clover.xml +++ b/clover.xml @@ -1,46 +1,46 @@ - - + + - + - - - - + - + + - - + + + - - - + - + + - - + - - - - - + + + + + + - - + + + + @@ -151,6 +151,6 @@ - + diff --git a/src/DoctrineDataFixtureModule/Command/ImportCommand.php b/src/DoctrineDataFixtureModule/Command/ImportCommand.php index 30d3ff0..dd1d363 100644 --- a/src/DoctrineDataFixtureModule/Command/ImportCommand.php +++ b/src/DoctrineDataFixtureModule/Command/ImportCommand.php @@ -56,8 +56,12 @@ class ImportCommand extends Command const PURGE_MODE_TRUNCATE = 2; - public function __construct(ServiceLocatorAwareLoader $loader, ORMPurger $purger, EntityManager $em, array $paths = null) - { + public function __construct( + ServiceLocatorAwareLoader $loader, + ORMPurger $purger, + EntityManager $em, + array $paths = null + ) { $this->loader = $loader; $this->purger = $purger; $this->em = $em; diff --git a/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php b/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php index c80a3c5..0caeca3 100644 --- a/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php +++ b/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php @@ -28,6 +28,7 @@ use Zend\ServiceManager\ServiceManager; use Zend\Mvc\Service\ServiceManagerConfig; + /** * Test Import commands for fixtures * @@ -37,18 +38,23 @@ */ class ImportCommandTest extends PHPUnit_Framework_TestCase { - public function testExecute() + public function testExecutePurgeWithTruncate() { $paths = array( 'DoctrineDataFixture_Test_Paths' => __DIR__ . '/../TestAsset/Fixtures/NoSL', ); - $command = new ImportCommand($this->getMockServiceLocatorAwareLoader(), $this->getMockPurger(), $this->getMockSqliteEntityManager(), $paths); + $command = new ImportCommand( + $this->getMockServiceLocatorAwareLoader(), + $this->getMockPurger(), + $this->getMockSqliteEntityManager(), + $paths + ); $commandTester = new CommandTester($command); $commandTester->execute( array( - '--append' => 'true', + '--purge-with-truncate' => 'true', ) ); } @@ -60,7 +66,13 @@ private function getMockFixture() private function getMockPurger() { - return $this->getMock('Doctrine\Common\DataFixtures\Purger\ORMPurger'); + $purger = $this->getMock('Doctrine\Common\DataFixtures\Purger\ORMPurger'); + + $purger->expects($this->once()) + ->method('setPurgeMode') + ->with($this->equalTo(2)); + + return $purger; } protected function getMockServiceLocatorAwareLoader() @@ -77,6 +89,9 @@ protected function getMockServiceLocatorAwareLoader() array($this->getMockFixture()) )); + $loader->expects($this->once()) + ->method('loadPaths'); + return $loader; } @@ -93,4 +108,4 @@ protected function getMockSqliteEntityManager() $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/../TestAsset/Entity'), true); return EntityManager::create($dbParams, $config); } -} \ No newline at end of file +} diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php index 77443f3..a7e352e 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php @@ -33,4 +33,4 @@ public function getName() { return $this->name; } -} \ No newline at end of file +} diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php index e9aa8f3..8264d6e 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php @@ -73,4 +73,4 @@ public function getRole() { return $this->role; } -} \ No newline at end of file +} From 5c65fda5059c02d45f2d7dc81bd4673b70d4d46a Mon Sep 17 00:00:00 2001 From: Martin Supiot Date: Tue, 4 Mar 2014 22:42:48 +0100 Subject: [PATCH 06/15] Fix typo --- src/DoctrineDataFixtureModule/Module.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DoctrineDataFixtureModule/Module.php b/src/DoctrineDataFixtureModule/Module.php index 9ba4989..52f5e7f 100644 --- a/src/DoctrineDataFixtureModule/Module.php +++ b/src/DoctrineDataFixtureModule/Module.php @@ -26,6 +26,7 @@ use Zend\ModuleManager\ModuleManager; use Doctrine\ORM\Tools\Console\ConsoleRunner; use DoctrineDataFixtureModule\Command\ImportCommand; +use DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader; use DoctrineDataFixtureModule\Service\FixtureFactory; use Doctrine\Common\DataFixtures\Purger\ORMPurger; @@ -71,7 +72,7 @@ public function init(ModuleManager $e) $sm = $e->getParam('ServiceManager'); $em = $sm->get('doctrine.entitymanager.orm_default'); $paths = $sm->get('doctrine.configuration.fixtures'); - $loader = new ServiceLocatorAwareLoader($sm) + $loader = new ServiceLocatorAwareLoader($sm); $importCommand = new ImportCommand($loader, new ORMPurger, $em, $paths); ConsoleRunner::addCommands($cli); From faca963d6f35bdefe128ae5e1a06514de4144e21 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 27 Mar 2015 10:47:22 +0100 Subject: [PATCH 07/15] Removed and added clover to ignore --- .gitignore | 3 +- clover.xml | 156 ----------------------------------------------------- 2 files changed, 2 insertions(+), 157 deletions(-) delete mode 100644 clover.xml diff --git a/.gitignore b/.gitignore index 0ee1ad3..c1e5e42 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /build /vendor composer.lock -composer.phar \ No newline at end of file +composer.phar +clover.xml \ No newline at end of file diff --git a/clover.xml b/clover.xml deleted file mode 100644 index 99b136b..0000000 --- a/clover.xml +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 05cdc066f26b0d24f56857670a27ebe96573e9e1 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 27 Mar 2015 11:03:47 +0100 Subject: [PATCH 08/15] Fixed Licensing and docblock*s --- .../Command/ImportCommand.php | 23 +++++++++++-------- .../Loader/ServiceLocatorAwareLoader.php | 5 ++-- .../Command/ImportCommandTest.php | 5 ++-- .../Loader/ServiceLocatorAwareLoaderTest.php | 5 ++-- .../TestAsset/Entity/Role.php | 17 ++++++++++++++ .../TestAsset/Entity/User.php | 17 ++++++++++++++ .../TestAsset/Fixtures/FixtureA.php | 18 +++++++++++++++ .../TestAsset/Fixtures/HasSL/FixtureA.php | 18 +++++++++++++++ .../TestAsset/Fixtures/NoSL/FixtureA.php | 18 +++++++++++++++ 9 files changed, 111 insertions(+), 15 deletions(-) diff --git a/src/DoctrineDataFixtureModule/Command/ImportCommand.php b/src/DoctrineDataFixtureModule/Command/ImportCommand.php index dd1d363..e3383f4 100644 --- a/src/DoctrineDataFixtureModule/Command/ImportCommand.php +++ b/src/DoctrineDataFixtureModule/Command/ImportCommand.php @@ -13,7 +13,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals - * and is licensed under the LGPL. For more information, see + * and is licensed under the MIT license. For more information, see * . */ @@ -32,18 +32,20 @@ use Doctrine\ORM\EntityManager; /** - * Command for generate migration classes by comparing your current database schema - * to your mapping information. + * Command to import Fixtures * - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @license MIT * @link www.doctrine-project.org - * @since 2.0 - * @author Jonathan Wage + * @author Martin Shwalbe */ class ImportCommand extends Command { protected $paths; + /** + * EntityManager + * @var Doctrine\ORM\EntityManager + */ protected $em; /** @@ -52,6 +54,10 @@ class ImportCommand extends Command */ protected $loader; + /** + * ORMPurger + * @var Doctrine\Common\DataFixtures\Purger\ORMPurger + */ protected $purger; const PURGE_MODE_TRUNCATE = 2; @@ -60,7 +66,7 @@ public function __construct( ServiceLocatorAwareLoader $loader, ORMPurger $purger, EntityManager $em, - array $paths = null + array $paths = array() ) { $this->loader = $loader; $this->purger = $purger; @@ -97,7 +103,7 @@ public function execute(InputInterface $input, OutputInterface $output) $this->purger->setPurgeMode(self::PURGE_MODE_TRUNCATE); } - if ($input->getOption('fixtures') != null) { + if ($input->getOption('fixtures') !== null) { $this->loader->loadPath($input->getOption('fixtures')); } else { $this->loader->loadPaths($this->paths); @@ -105,7 +111,6 @@ public function execute(InputInterface $input, OutputInterface $output) $executor = new ORMExecutor($this->em, $this->purger); - $executor->execute($this->loader->getFixtures(), $input->getOption('append')); } } diff --git a/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php b/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php index 3982dff..1069287 100644 --- a/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php +++ b/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php @@ -13,9 +13,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals - * and is licensed under the LGPL. For more information, see + * and is licensed under the MIT license. For more information, see * . */ + namespace DoctrineDataFixtureModule\Loader; use Doctrine\Common\DataFixtures\Loader as BaseLoader; @@ -27,7 +28,7 @@ * Doctrine fixture loader which is ZF2 Service Locator-aware * Will inject the service locator instance into all SL-aware fixtures on add * - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @license MIT * @link www.doctrine-project.org * @author Adam Lundrigan */ diff --git a/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php b/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php index 0caeca3..21a2bca 100644 --- a/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php +++ b/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php @@ -13,9 +13,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals - * and is licensed under the LGPL. For more information, see + * and is licensed under the MIT license. For more information, see * . */ + namespace DoctrineDataFixtureTest\Command; @@ -32,7 +33,7 @@ /** * Test Import commands for fixtures * - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @license MIT * @link www.doctrine-project.org * @author Martin Shwalbe */ diff --git a/tests/DoctrineDataFixtureTest/Loader/ServiceLocatorAwareLoaderTest.php b/tests/DoctrineDataFixtureTest/Loader/ServiceLocatorAwareLoaderTest.php index cd9f0ca..f29fde9 100644 --- a/tests/DoctrineDataFixtureTest/Loader/ServiceLocatorAwareLoaderTest.php +++ b/tests/DoctrineDataFixtureTest/Loader/ServiceLocatorAwareLoaderTest.php @@ -13,9 +13,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals - * and is licensed under the LGPL. For more information, see + * and is licensed under the MIT license. For more information, see * . */ + namespace DoctrineDataFixtureTest\Loader; use Doctrine\Common\DataFixtures\Loader; @@ -26,7 +27,7 @@ /** * Test Service Locator-aware fixture loader * - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @license MIT * @link www.doctrine-project.org * @author Adam Lundrigan */ diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php index a7e352e..81a9dad 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php @@ -1,4 +1,21 @@ . + */ namespace DoctrineDataFixtureTest\TestAsset\Entity; diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php index 8264d6e..5fd63c1 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php @@ -1,4 +1,21 @@ . + */ namespace DoctrineDataFixtureTest\TestAsset\Entity; diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Fixtures/FixtureA.php b/tests/DoctrineDataFixtureTest/TestAsset/Fixtures/FixtureA.php index fe630ca..323eca2 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Fixtures/FixtureA.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Fixtures/FixtureA.php @@ -1,4 +1,22 @@ . + */ + namespace DoctrineDataFixtureTest\TestAsset\Fixtures; use Doctrine\Common\Persistence\ObjectManager; diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Fixtures/HasSL/FixtureA.php b/tests/DoctrineDataFixtureTest/TestAsset/Fixtures/HasSL/FixtureA.php index c6fd35b..380ea63 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Fixtures/HasSL/FixtureA.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Fixtures/HasSL/FixtureA.php @@ -1,4 +1,22 @@ . + */ + namespace DoctrineDataFixtureTest\TestAsset\Fixtures\HasSL; use Doctrine\Common\Persistence\ObjectManager; diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Fixtures/NoSL/FixtureA.php b/tests/DoctrineDataFixtureTest/TestAsset/Fixtures/NoSL/FixtureA.php index 2313721..9d6d762 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Fixtures/NoSL/FixtureA.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Fixtures/NoSL/FixtureA.php @@ -1,4 +1,22 @@ . + */ + namespace DoctrineDataFixtureTest\TestAsset\Fixtures\NoSL; use Doctrine\Common\Persistence\ObjectManager; From 3712c890a8eb63d4a36860b3dc785c3ba9d4f4e8 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 27 Mar 2015 11:37:10 +0100 Subject: [PATCH 09/15] Cleanup and @covers annotation --- .../Command/ImportCommand.php | 30 +++++++++---------- .../Loader/ServiceLocatorAwareLoader.php | 6 ++-- .../Command/ImportCommandTest.php | 3 ++ .../Loader/ServiceLocatorAwareLoaderTest.php | 20 +++++++++++-- .../TestAsset/Entity/Role.php | 15 ++++++---- .../TestAsset/Entity/User.php | 18 ++++++----- 6 files changed, 60 insertions(+), 32 deletions(-) diff --git a/src/DoctrineDataFixtureModule/Command/ImportCommand.php b/src/DoctrineDataFixtureModule/Command/ImportCommand.php index e3383f4..cfd339d 100644 --- a/src/DoctrineDataFixtureModule/Command/ImportCommand.php +++ b/src/DoctrineDataFixtureModule/Command/ImportCommand.php @@ -29,7 +29,7 @@ use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Purger\ORMPurger; use DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; /** * Command to import Fixtures @@ -46,31 +46,31 @@ class ImportCommand extends Command * EntityManager * @var Doctrine\ORM\EntityManager */ - protected $em; + protected $entityManager; /** * ServiceLocatorAwareLoader * @var DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader */ - protected $loader; + protected $serviceLocatorAwareloader; /** * ORMPurger * @var Doctrine\Common\DataFixtures\Purger\ORMPurger */ - protected $purger; + protected $ormPurger; const PURGE_MODE_TRUNCATE = 2; public function __construct( - ServiceLocatorAwareLoader $loader, - ORMPurger $purger, - EntityManager $em, + ServiceLocatorAwareLoader $serviceLocatorAwareloader, + ORMPurger $ormPurger, + EntityManagerInterface $entityManager, array $paths = array() ) { - $this->loader = $loader; - $this->purger = $purger; - $this->em = $em; + $this->serviceLocatorAwareloader = $serviceLocatorAwareloader; + $this->ormPurger = $ormPurger; + $this->entityManager = $entityManager; $this->paths = $paths; parent::__construct(); @@ -100,17 +100,17 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('purge-with-truncate')) { - $this->purger->setPurgeMode(self::PURGE_MODE_TRUNCATE); + $this->ormPurger->setPurgeMode(self::PURGE_MODE_TRUNCATE); } if ($input->getOption('fixtures') !== null) { - $this->loader->loadPath($input->getOption('fixtures')); + $this->serviceLocatorAwareloader->loadPath($input->getOption('fixtures')); } else { - $this->loader->loadPaths($this->paths); + $this->serviceLocatorAwareloader->loadPaths($this->paths); } - $executor = new ORMExecutor($this->em, $this->purger); + $executor = new ORMExecutor($this->entityManager, $this->ormPurger); - $executor->execute($this->loader->getFixtures(), $input->getOption('append')); + $executor->execute($this->serviceLocatorAwareloader->getFixtures(), $input->getOption('append')); } } diff --git a/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php b/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php index 1069287..5867dc2 100644 --- a/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php +++ b/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php @@ -61,6 +61,7 @@ public function loadPath($path) { if (is_dir($path)) { $this->loadFromDirectory($path); + return $this; } elseif (file_exists($path)) { $classes = get_declared_classes(); include($path); @@ -69,9 +70,10 @@ public function loadPath($path) $diff = array_diff($newClasses, $classes); $class = array_pop($diff); $this->addFixture(new $class); - } else { - throw new \RuntimeException('Cannot find File or Directory.'); + return $this; } + + throw new \RuntimeException('Cannot find File or Directory.'); } public function loadPaths($paths) diff --git a/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php b/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php index 21a2bca..30a2b73 100644 --- a/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php +++ b/tests/DoctrineDataFixtureTest/Command/ImportCommandTest.php @@ -39,6 +39,9 @@ */ class ImportCommandTest extends PHPUnit_Framework_TestCase { + /** + * @covers DoctrineDataFixtureModule\Command\ImportCommand::execute + */ public function testExecutePurgeWithTruncate() { $paths = array( diff --git a/tests/DoctrineDataFixtureTest/Loader/ServiceLocatorAwareLoaderTest.php b/tests/DoctrineDataFixtureTest/Loader/ServiceLocatorAwareLoaderTest.php index f29fde9..7d4ec8d 100644 --- a/tests/DoctrineDataFixtureTest/Loader/ServiceLocatorAwareLoaderTest.php +++ b/tests/DoctrineDataFixtureTest/Loader/ServiceLocatorAwareLoaderTest.php @@ -37,6 +37,9 @@ class ServiceLocatorAwareLoaderTest extends \PHPUnit_Framework_TestCase /** * Ensures that ServiceLocatorAwareLoader does not affect loading of * fixtures that are not SL-aware + * + * @covers DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader::loadFromDirectory + * @covers DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader::getFixtures */ public function testLoadingFixtureWhichIsNotServiceLocatorAware() { @@ -56,6 +59,9 @@ public function testLoadingFixtureWhichIsNotServiceLocatorAware() /** * Ensures that the Service Locator instance passed into the ServiceLocatorAwareLoader * actually makes it to the SL-aware fixtures loaded + * + * @covers DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader::loadFromDirectory + * @covers DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader::getFixtures */ public function testLoadingFixtureWhichIsServiceLocatorAware() { @@ -73,6 +79,10 @@ public function testLoadingFixtureWhichIsServiceLocatorAware() $this->assertSame($serviceLocator, $fixture->getServiceLocator()); } + /** + * @covers DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader::loadPaths + * @covers DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader::getFixtures + */ public function testLoadingByConfigPaths() { $paths = array( @@ -88,10 +98,12 @@ public function testLoadingByConfigPaths() $this->assertArrayHasKey('DoctrineDataFixtureTest\TestAsset\Fixtures\HasSL\FixtureA', $fixtures); $this->assertArrayHasKey('DoctrineDataFixtureTest\TestAsset\Fixtures\NoSL\FixtureA', $fixtures); - - } + /** + * @covers DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader::loadPath + * @covers DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader::getFixtures + */ public function testLoadingByDirectoryPath() { $fixturePath = __DIR__ . '/../TestAsset/Fixtures/HasSL'; @@ -104,6 +116,10 @@ public function testLoadingByDirectoryPath() $this->assertArrayHasKey('DoctrineDataFixtureTest\TestAsset\Fixtures\HasSL\FixtureA', $fixtures); } + /** + * @covers DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader::loadPath + * @covers DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader::getFixtures + */ public function testLoadingByPath() { $fixturePath = __DIR__ . '/../TestAsset/Fixtures/FixtureA.php'; diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php index 81a9dad..47f5f48 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php @@ -19,20 +19,23 @@ namespace DoctrineDataFixtureTest\TestAsset\Entity; +use Doctrine\ORM\Mapping as ORM; + /** - * @Entity + * @ORM\Entity + * @ORM\Table(name="doctrine_data_fixture_role") */ class Role { - /** - * @Column(type="integer") - * @Id - * @GeneratedValue(strategy="IDENTITY") + /* + * @ORM\Id + * @ORM\Column(type="integer"); + * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** - * @Column(length=50) + * @ORM\Column(type="string", length=50) */ private $name; diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php index 5fd63c1..5f029c1 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php @@ -19,14 +19,18 @@ namespace DoctrineDataFixtureTest\TestAsset\Entity; +use Doctrine\ORM\Mapping as ORM; + /** - * @Entity + * @ORM\Entity + * @ORM\Table(name="doctrine_data_fixture_user") */ class User { - /** - * @Column(type="integer") - * @Id + /* + * @ORM\Id + * @ORM\Column(type="integer"); + * @ORM\GeneratedValue(strategy="AUTO") */ private $id; @@ -37,17 +41,17 @@ class User private $code; /** - * @Column(length=32) + * @ORM\Column(type="string", length=32) */ private $password; /** - * @Column(length=255) + * @ORM\Column(type="string", length=255) */ private $email; /** - * @ManyToOne(targetEntity="Role", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="Role", cascade={"persist"}) */ private $role; From 98b5d6c6e63ce1fa684cd3953b54d84836d28b2d Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 27 Mar 2015 11:41:35 +0100 Subject: [PATCH 10/15] Add missing Docblock to Importcommant --- .../Loader/ServiceLocatorAwareLoader.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php b/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php index 5867dc2..6300ab4 100644 --- a/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php +++ b/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php @@ -57,6 +57,10 @@ public function addFixture(FixtureInterface $fixture) parent::addFixture($fixture); } + /** + * Load Fixtures from directory or Single fixture from path + * @param $path + */ public function loadPath($path) { if (is_dir($path)) { @@ -76,6 +80,10 @@ public function loadPath($path) throw new \RuntimeException('Cannot find File or Directory.'); } + /** + * Load Fixtures from directories + * @param $paths + */ public function loadPaths($paths) { foreach ($paths as $key => $value) { From 20c30464a5ea33afb7aa6a3de118e101fb1113a5 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 31 Mar 2015 09:52:14 +0200 Subject: [PATCH 11/15] PHPCS Fixes --- tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php | 2 +- tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php index 47f5f48..85fbb68 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php @@ -27,7 +27,7 @@ */ class Role { - /* + /** * @ORM\Id * @ORM\Column(type="integer"); * @ORM\GeneratedValue(strategy="AUTO") diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php index 5f029c1..9b6d871 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php @@ -27,7 +27,7 @@ */ class User { - /* + /** * @ORM\Id * @ORM\Column(type="integer"); * @ORM\GeneratedValue(strategy="AUTO") From 20d74a74dbe6d3b97cd891f808a7292841941c95 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 3 Apr 2015 13:08:44 +0200 Subject: [PATCH 12/15] Remove else --- .../Loader/ServiceLocatorAwareLoader.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php b/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php index 6300ab4..e193cc7 100644 --- a/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php +++ b/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php @@ -66,7 +66,9 @@ public function loadPath($path) if (is_dir($path)) { $this->loadFromDirectory($path); return $this; - } elseif (file_exists($path)) { + } + + if (file_exists($path)) { $classes = get_declared_classes(); include($path); $newClasses = get_declared_classes(); From f7af7211ba6c00e36c6267224fc89b561da52e44 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 3 Apr 2015 13:11:08 +0200 Subject: [PATCH 13/15] Removed setters and getters --- .../TestAsset/Entity/Role.php | 19 +------ .../TestAsset/Entity/User.php | 50 ++----------------- 2 files changed, 7 insertions(+), 62 deletions(-) diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php index 85fbb68..d731aec 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/Role.php @@ -32,25 +32,10 @@ class Role * @ORM\Column(type="integer"); * @ORM\GeneratedValue(strategy="AUTO") */ - private $id; + public $id; /** * @ORM\Column(type="string", length=50) */ - private $name; - - public function getId() - { - return $this->id; - } - - public function setName($name) - { - $this->name = $name; - } - - public function getName() - { - return $this->name; - } + public $name; } diff --git a/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php b/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php index 9b6d871..f721754 100644 --- a/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php +++ b/tests/DoctrineDataFixtureTest/TestAsset/Entity/User.php @@ -32,66 +32,26 @@ class User * @ORM\Column(type="integer"); * @ORM\GeneratedValue(strategy="AUTO") */ - private $id; + public $id; /** * @Column(length=32) * @Id */ - private $code; + public $code; /** * @ORM\Column(type="string", length=32) */ - private $password; + public $password; /** * @ORM\Column(type="string", length=255) */ - private $email; + public $email; /** * @ORM\ManyToOne(targetEntity="Role", cascade={"persist"}) */ - private $role; - - public function setId($id) - { - $this->id = $id; - } - - public function setCode($code) - { - $this->code = $code; - } - - public function setPassword($password) - { - $this->password = md5($password); - } - - public function getPassword() - { - return $this->password; - } - - public function setEmail($email) - { - $this->email = $email; - } - - public function getEmail() - { - return $this->email; - } - - public function setRole(Role $role) - { - $this->role = $role; - } - - public function getRole() - { - return $this->role; - } + public $role; } From 866d6ea6b442e7e86efd9632b54eb37090e3d9f5 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 3 Apr 2015 13:11:50 +0200 Subject: [PATCH 14/15] Initialize during addCommand --- src/DoctrineDataFixtureModule/Module.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/DoctrineDataFixtureModule/Module.php b/src/DoctrineDataFixtureModule/Module.php index 52f5e7f..6285e8b 100644 --- a/src/DoctrineDataFixtureModule/Module.php +++ b/src/DoctrineDataFixtureModule/Module.php @@ -74,10 +74,9 @@ public function init(ModuleManager $e) $paths = $sm->get('doctrine.configuration.fixtures'); $loader = new ServiceLocatorAwareLoader($sm); - $importCommand = new ImportCommand($loader, new ORMPurger, $em, $paths); ConsoleRunner::addCommands($cli); $cli->addCommands(array( - $importCommand + new ImportCommand($loader, new ORMPurger, $em, $paths) )); }); } From 6a830d3f3fa3f83685957c51d159661b539c0228 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 3 Apr 2015 13:12:15 +0200 Subject: [PATCH 15/15] Add newline --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c1e5e42..9079acb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ /vendor composer.lock composer.phar -clover.xml \ No newline at end of file +clover.xml