-
Notifications
You must be signed in to change notification settings - Fork 71
Single fixture #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Single fixture #24
Changes from 8 commits
e197a00
a80eb61
a6a3695
165d81e
f8d5008
5162302
5c65fda
e5d764f
faca963
05cdc06
3712c89
98b5d6c
20c3046
20d74a7
f7af721
866d6ea
6a830d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<coverage generated="1391258417"> | ||
<project timestamp="1391258417"> | ||
<package name="DoctrineDataFixtureModule\Command"> | ||
<file name="/home/martin/Work/github/DoctrineDataFixtureModule/src/DoctrineDataFixtureModule/Command/ImportCommand.php"> | ||
<class name="ImportCommand" namespace="DoctrineDataFixtureModule\Command"> | ||
<metrics methods="3" coveredmethods="3" conditionals="0" coveredconditionals="0" statements="29" coveredstatements="27" elements="32" coveredelements="30"/> | ||
</class> | ||
<line num="0" type="stmt" count="1"/> | ||
<line num="59" type="method" name="__construct" crap="1" count="1"/> | ||
<line num="65" type="stmt" count="1"/> | ||
<line num="66" type="stmt" count="1"/> | ||
<line num="67" type="stmt" count="1"/> | ||
<line num="68" type="stmt" count="1"/> | ||
<line num="70" type="stmt" count="1"/> | ||
<line num="71" type="stmt" count="1"/> | ||
<line num="73" type="method" name="configure" crap="1" count="1"/> | ||
<line num="75" type="stmt" count="1"/> | ||
<line num="77" type="stmt" count="1"/> | ||
<line num="78" type="stmt" count="1"/> | ||
<line num="79" type="stmt" count="1"/> | ||
<line num="83" type="stmt" count="1"/> | ||
<line num="84" type="stmt" count="1"/> | ||
<line num="85" type="stmt" count="1"/> | ||
<line num="86" type="stmt" count="1"/> | ||
<line num="87" type="stmt" count="1"/> | ||
<line num="88" type="stmt" count="1"/> | ||
<line num="89" type="stmt" count="1"/> | ||
<line num="91" type="stmt" count="1"/> | ||
<line num="92" type="stmt" count="1"/> | ||
<line num="94" type="method" name="execute" crap="3.07" count="1"/> | ||
<line num="96" type="stmt" count="1"/> | ||
<line num="97" type="stmt" count="1"/> | ||
<line num="98" type="stmt" count="1"/> | ||
<line num="100" type="stmt" count="1"/> | ||
<line num="101" type="stmt" count="0"/> | ||
<line num="102" type="stmt" count="0"/> | ||
<line num="103" type="stmt" count="1"/> | ||
<line num="106" type="stmt" count="1"/> | ||
<line num="109" type="stmt" count="1"/> | ||
<line num="110" type="stmt" count="1"/> | ||
<line num="112" type="stmt" count="1"/> | ||
<metrics loc="111" ncloc="81" classes="1" methods="3" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="29" coveredstatements="27" elements="32" coveredelements="29"/> | ||
</file> | ||
</package> | ||
<package name="DoctrineDataFixtureModule\Loader"> | ||
<file name="/home/martin/Work/github/DoctrineDataFixtureModule/src/DoctrineDataFixtureModule/Loader/ServiceLocatorAwareLoader.php"> | ||
<class name="ServiceLocatorAwareLoader" namespace="DoctrineDataFixtureModule\Loader"> | ||
<metrics methods="4" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="23" coveredstatements="22" elements="27" coveredelements="26"/> | ||
</class> | ||
<line num="41" type="method" name="__construct" crap="1" count="6"/> | ||
<line num="43" type="stmt" count="6"/> | ||
<line num="44" type="stmt" count="6"/> | ||
<line num="51" type="method" name="addFixture" crap="2" count="5"/> | ||
<line num="53" type="stmt" count="5"/> | ||
<line num="54" type="stmt" count="3"/> | ||
<line num="55" type="stmt" count="3"/> | ||
<line num="56" type="stmt" count="5"/> | ||
<line num="57" type="stmt" count="5"/> | ||
<line num="59" type="method" name="loadPath" crap="3.01" count="2"/> | ||
<line num="61" type="stmt" count="2"/> | ||
<line num="62" type="stmt" count="1"/> | ||
<line num="63" type="stmt" count="2"/> | ||
<line num="64" type="stmt" count="1"/> | ||
<line num="65" type="stmt" count="1"/> | ||
<line num="66" type="stmt" count="1"/> | ||
<line num="68" type="stmt" count="1"/> | ||
<line num="69" type="stmt" count="1"/> | ||
<line num="70" type="stmt" count="1"/> | ||
<line num="71" type="stmt" count="1"/> | ||
<line num="72" type="stmt" count="0"/> | ||
<line num="74" type="stmt" count="2"/> | ||
<line num="76" type="method" name="loadPaths" crap="2" count="1"/> | ||
<line num="78" type="stmt" count="1"/> | ||
<line num="79" type="stmt" count="1"/> | ||
<line num="80" type="stmt" count="1"/> | ||
<line num="81" type="stmt" count="1"/> | ||
<line num="83" type="stmt" count="1"/> | ||
<line num="87" type="stmt" count="2"/> | ||
<metrics loc="82" ncloc="49" classes="1" methods="4" coveredmethods="3" conditionals="0" coveredconditionals="0" statements="23" coveredstatements="22" elements="27" coveredelements="25"/> | ||
</file> | ||
</package> | ||
<package name="DoctrineDataFixtureModule"> | ||
<file name="/home/martin/Work/github/DoctrineDataFixtureModule/src/DoctrineDataFixtureModule/Module.php"> | ||
<class name="Module" namespace="DoctrineDataFixtureModule"> | ||
<metrics methods="5" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="54" coveredstatements="0" elements="59" coveredelements="0"/> | ||
</class> | ||
<line num="18" type="stmt" count="0"/> | ||
<line num="47" type="method" name="getAutoloaderConfig" crap="2" count="0"/> | ||
<line num="48" type="stmt" count="0"/> | ||
<line num="49" type="stmt" count="0"/> | ||
<line num="50" type="stmt" count="0"/> | ||
<line num="51" type="stmt" count="0"/> | ||
<line num="52" type="stmt" count="0"/> | ||
<line num="53" type="stmt" count="0"/> | ||
<line num="54" type="stmt" count="0"/> | ||
<line num="55" type="stmt" count="0"/> | ||
<line num="56" type="stmt" count="0"/> | ||
<line num="61" type="method" name="init" crap="2" count="0"/> | ||
<line num="62" type="stmt" count="0"/> | ||
<line num="63" type="stmt" count="0"/> | ||
<line num="66" type="method" name="anonymous function" crap="2" count="0"/> | ||
<line num="67" type="stmt" count="0"/> | ||
<line num="68" type="stmt" count="0"/> | ||
<line num="70" type="stmt" count="0"/> | ||
<line num="71" type="stmt" count="0"/> | ||
<line num="72" type="stmt" count="0"/> | ||
<line num="73" type="stmt" count="0"/> | ||
<line num="74" type="stmt" count="0"/> | ||
<line num="76" type="stmt" count="0"/> | ||
<line num="77" type="stmt" count="0"/> | ||
<line num="78" type="stmt" count="0"/> | ||
<line num="79" type="stmt" count="0"/> | ||
<line num="80" type="stmt" count="0"/> | ||
<line num="81" type="stmt" count="0"/> | ||
<line num="82" type="stmt" count="0"/> | ||
<line num="87" type="method" name="getConfig" crap="2" count="0"/> | ||
<line num="88" type="stmt" count="0"/> | ||
<line num="89" type="stmt" count="0"/> | ||
<line num="90" type="stmt" count="0"/> | ||
<line num="95" type="method" name="getServiceConfig" crap="2" count="0"/> | ||
<line num="96" type="stmt" count="0"/> | ||
<line num="97" type="stmt" count="0"/> | ||
<line num="98" type="stmt" count="0"/> | ||
<line num="99" type="stmt" count="0"/> | ||
<line num="100" type="stmt" count="0"/> | ||
<line num="101" type="stmt" count="0"/> | ||
<line num="102" type="stmt" count="0"/> | ||
<metrics loc="103" ncloc="63" classes="1" methods="5" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="41" coveredstatements="0" elements="46" coveredelements="0"/> | ||
</file> | ||
</package> | ||
<package name="DoctrineDataFixtureModule\Service"> | ||
<file name="/home/martin/Work/github/DoctrineDataFixtureModule/src/DoctrineDataFixtureModule/Service/FixtureFactory.php"> | ||
<class name="FixtureFactory" namespace="DoctrineDataFixtureModule\Service"> | ||
<metrics methods="2" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="13" coveredstatements="0" elements="15" coveredelements="0"/> | ||
</class> | ||
<line num="18" type="stmt" count="0"/> | ||
<line num="35" type="method" name="createService" crap="2" count="0"/> | ||
<line num="36" type="stmt" count="0"/> | ||
<line num="38" type="stmt" count="0"/> | ||
<line num="40" type="stmt" count="0"/> | ||
<line num="41" type="stmt" count="0"/> | ||
<line num="52" type="method" name="getOptions" crap="6" count="0"/> | ||
<line num="53" type="stmt" count="0"/> | ||
<line num="54" type="stmt" count="0"/> | ||
<line num="55" type="stmt" count="0"/> | ||
<line num="56" type="stmt" count="0"/> | ||
<line num="57" type="stmt" count="0"/> | ||
<line num="59" type="stmt" count="0"/> | ||
<line num="60" type="stmt" count="0"/> | ||
<metrics loc="61" ncloc="27" classes="1" methods="2" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="14" coveredstatements="0" elements="16" coveredelements="0"/> | ||
</file> | ||
</package> | ||
<metrics files="4" loc="357" ncloc="220" classes="4" methods="14" coveredmethods="5" conditionals="0" coveredconditionals="0" statements="107" coveredstatements="49" elements="121" coveredelements="54"/> | ||
</project> | ||
</coverage> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should rather create another pr to upgrade it for ORM 2.4 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a big deal, do it here. |
||
|
||
/** | ||
* Command for generate migration classes by comparing your current database schema | ||
|
@@ -47,16 +47,26 @@ class ImportCommand extends Command | |
protected $em; | ||
|
||
/** | ||
* Service Locator instance | ||
* @var Zend\ServiceManager\ServiceLocatorInterface | ||
* ServiceLocatorAwareLoader | ||
* @var DoctrineDataFixtureModule\Loader\ServiceLocatorAwareLoader | ||
*/ | ||
protected $serviceLocator; | ||
protected $loader; | ||
|
||
protected $purger; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing docblock |
||
|
||
const PURGE_MODE_TRUNCATE = 2; | ||
|
||
public function __construct(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
$this->serviceLocator = $serviceLocator; | ||
public function __construct( | ||
ServiceLocatorAwareLoader $loader, | ||
ORMPurger $purger, | ||
EntityManager $em, | ||
array $paths = null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) { | ||
$this->loader = $loader; | ||
$this->purger = $purger; | ||
$this->em = $em; | ||
$this->paths = $paths; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
|
@@ -72,33 +82,30 @@ 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) | ||
{ | ||
$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); | ||
|
||
foreach ($this->paths as $key => $value) { | ||
$loader->loadFromDirectory($value); | ||
if ($input->getOption('fixtures') != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$this->loader->loadPath($input->getOption('fixtures')); | ||
} else { | ||
$this->loader->loadPaths($this->paths); | ||
} | ||
$executor->execute($loader->getFixtures(), $input->getOption('append')); | ||
} | ||
|
||
public function setPath($paths) | ||
{ | ||
$this->paths=$paths; | ||
} | ||
$executor = new ORMExecutor($this->em, $this->purger); | ||
|
||
public function setEntityManager($em) | ||
{ | ||
$this->em = $em; | ||
|
||
$executor->execute($this->loader->getFixtures(), $input->getOption('append')); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,28 @@ public function addFixture(FixtureInterface $fixture) | |
} | ||
parent::addFixture($fixture); | ||
} | ||
|
||
public function loadPath($path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing docblock |
||
{ | ||
if (is_dir($path)) { | ||
$this->loadFromDirectory($path); | ||
} elseif (file_exists($path)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for the |
||
$classes = get_declared_classes(); | ||
include($path); | ||
$newClasses = get_declared_classes(); | ||
|
||
$diff = array_diff($newClasses, $classes); | ||
$class = array_pop($diff); | ||
$this->addFixture(new $class); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
throw new \RuntimeException('Cannot find File or Directory.'); | ||
} | ||
} | ||
|
||
public function loadPaths($paths) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing docblock |
||
{ | ||
foreach ($paths as $key => $value) { | ||
$this->loadFromDirectory($value); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,9 @@ | |
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; | ||
|
||
/** | ||
* Base module for Doctrine Data Fixture. | ||
|
@@ -70,10 +72,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 = new ImportCommand($loader, new ORMPurger, $em, $paths); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just instantiate this at line 80 |
||
ConsoleRunner::addCommands($cli); | ||
$cli->addCommands(array( | ||
$importCommand | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be committed