Skip to content

Commit

Permalink
Merge branch 'master' of github.com:huitiemesens/LiipFunctionalTestBu…
Browse files Browse the repository at this point in the history
…ndle
  • Loading branch information
Charles-Antoine FOURNEL committed Mar 14, 2016
2 parents 89fe42c + 2d4be3f commit 5899bd2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
21 changes: 10 additions & 11 deletions Command/RunParatestCommand.php
Expand Up @@ -27,38 +27,37 @@ 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();
$this->output->writeln("Creating Schema in $testDbPath ...");
$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');
}
}

Expand All @@ -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;
});
Expand Down
13 changes: 8 additions & 5 deletions Factory/ConnectionFactory.php
@@ -1,12 +1,13 @@
<?php

namespace Liip\FunctionalTestBundle\Factory;

use Doctrine\Bundle\DoctrineBundle\ConnectionFactory as BaseConnectionFactory;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;

/**
* Creates a connection taking the db name from the env with
* Creates a connection taking the db name from the env with
* a unique number defined by current process ID.
*/
class ConnectionFactory extends BaseConnectionFactory
Expand All @@ -24,16 +25,18 @@ class ConnectionFactory extends BaseConnectionFactory
public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = array())
{
$dbName = $this->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');
}
}
}
7 changes: 3 additions & 4 deletions Tests/Command/ParatestCommandTest.php
Expand Up @@ -18,7 +18,7 @@
class ParatestCommandTest extends WebTestCase
{
/**
* Test paratestCommand
* Test paratestCommand.
*/
public function testParatest()
{
Expand All @@ -27,21 +27,20 @@ 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();
}

$this->assertContains('Initial schema created', $content);
$this->assertContains('Done...Running test.', $content);

}
}

0 comments on commit 5899bd2

Please sign in to comment.