diff --git a/Command/RunParatestCommand.php b/Command/RunParatestCommand.php index 889af064..9db6aba6 100644 --- a/Command/RunParatestCommand.php +++ b/Command/RunParatestCommand.php @@ -27,19 +27,18 @@ protected function configure() ->setName('test:run') ->setDescription('Run phpunit tests with multiple process') ; - } protected function prepare() { - $this->configuration = $this->getContainer()->hasParameter("liip_functional_test"); - $paratestCfg = ( !isset($this->configuration['paratest'])) ? array('process' => $this->process, 'phpunit' => $this->phpunit) : $this->configuration['paratest']; + $this->configuration = $this->getContainer()->hasParameter('liip_functional_test'); + $paratestCfg = (!isset($this->configuration['paratest'])) ? array('process' => $this->process, 'phpunit' => $this->phpunit) : $this->configuration['paratest']; - $this->process = ( !empty($this->configuration['process']) ) ? $paratestCfg['process'] : $this->process; - $this->phpunit = ( !empty($this->configuration['phpunit']) ) ? $paratestCfg['phpunit'] : $this->phpunit; + $this->process = (!empty($this->configuration['process'])) ? $paratestCfg['process'] : $this->process; + $this->phpunit = (!empty($this->configuration['phpunit'])) ? $paratestCfg['phpunit'] : $this->phpunit; $testDbPath = $this->getContainer()->get('kernel')->getRootDir(); $this->output->writeln("Cleaning old dbs in $testDbPath ..."); - $createDirProcess = new Process('mkdir -p ' . $testDbPath . '/cache/test/'); + $createDirProcess = new Process('mkdir -p '.$testDbPath.'/cache/test/'); $createDirProcess->run(); $cleanProcess = new Process("rm -fr $testDbPath/cache/test/dbTest.db $testDbPath/cache/test/dbTest*.db*"); $cleanProcess->run(); @@ -47,18 +46,18 @@ protected function prepare() $createProcess = new Process('php app/console doctrine:schema:create --env=test'); $createProcess->run(); - $this->output->writeln("Initial schema created"); + $this->output->writeln('Initial schema created'); $populateProcess = new Process("php app/console doctrine:fixtures:load -n --fixtures $testDbPath/../src/overlord/AppBundle/Tests/DataFixtures/ORM/ --env=test"); $populateProcess->run(); if ($populateProcess->isSuccessful()) { $this->output->writeln('Initial schema populated, duplicating....'); - for ($a = 0; $a < $this->process; $a++) { - $test = new Process("cp $testDbPath/cache/test/dbTest.db " . $testDbPath . "/cache/test/dbTest$a.db"); + for ($a = 0; $a < $this->process; ++$a) { + $test = new Process("cp $testDbPath/cache/test/dbTest.db ".$testDbPath."/cache/test/dbTest$a.db"); $test->run(); } } else { - $this->output->writeln("Can t populate"); + $this->output->writeln('Can t populate'); } } @@ -73,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->output = $output; $this->prepare(); $this->output->writeln('Done...Running test.'); - $runProcess = new Process( $testDbPath . "../vendor/bin/paratest -c app/ --phpunit " .$this->phpunit." --runner WrapRunner -p ". $this->process); + $runProcess = new Process($testDbPath.'../vendor/bin/paratest -c app/ --phpunit '.$this->phpunit.' --runner WrapRunner -p '.$this->process); $runProcess->run(function ($type, $buffer) { echo $buffer; }); diff --git a/Factory/ConnectionFactory.php b/Factory/ConnectionFactory.php index ffcad722..88b7958e 100644 --- a/Factory/ConnectionFactory.php +++ b/Factory/ConnectionFactory.php @@ -1,4 +1,5 @@ getDbNameFromEnv($params['dbname']); - + if ($params['driver'] === 'pdo_sqlite') { - $params['path'] = str_replace("__DBNAME__", $dbName, $params['path']); + $params['path'] = str_replace('__DBNAME__', $dbName, $params['path']); } else { $params['dbname'] = $dbName; } + return parent::createConnection($params, $config, $eventManager, $mappingTypes); } + private function getDbNameFromEnv($dbName) { - return 'dbTest' . getenv('TEST_TOKEN'); + return 'dbTest'.getenv('TEST_TOKEN'); } -} \ No newline at end of file +} diff --git a/Tests/Command/ParatestCommandTest.php b/Tests/Command/ParatestCommandTest.php index 39eaeb78..3fe1bd69 100644 --- a/Tests/Command/ParatestCommandTest.php +++ b/Tests/Command/ParatestCommandTest.php @@ -18,7 +18,7 @@ class ParatestCommandTest extends WebTestCase { /** - * Test paratestCommand + * Test paratestCommand. */ public function testParatest() { @@ -27,14 +27,14 @@ public function testParatest() $application->setAutoExit(false); $input = new ArrayInput(array( - 'command' => 'test:run')); + 'command' => 'test:run', )); if (!class_exists('Symfony\Component\Console\Output\BufferedOutput')) { $output = new \Symfony\Component\Console\Output\StreamOutput(tmpfile(), \Symfony\Component\Console\Output\StreamOutput::VERBOSITY_NORMAL); $application->run($input, $output); rewind($output->getStream()); $content = stream_get_contents($output->getStream()); - }else{ + } else { $output = new \Symfony\Component\Console\Output\BufferedOutput(); $application->run($input, $output); $content = $output->fetch(); @@ -42,6 +42,5 @@ public function testParatest() $this->assertContains('Initial schema created', $content); $this->assertContains('Done...Running test.', $content); - } }