Skip to content

Instantly share code, notes, and snippets.

@ahonymous
Created August 4, 2016 20:40
Show Gist options
  • Save ahonymous/c40f4bec50b5546263f8db48c563a21e to your computer and use it in GitHub Desktop.
Save ahonymous/c40f4bec50b5546263f8db48c563a21e to your computer and use it in GitHub Desktop.
bootstrap file for test
<?php
namespace Tests\AppBundle;
...
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\KernelInterface;
...
class EETestCase extends WebTestCase
{
...
/**
* @var Filesystem
*/
protected $fs;
public function setUp()
{
...
$this->fs = new Filesystem();
if ($this->fs->exists($this->client->getContainer()->getParameter('default_db_path'))) {
$this->fs->copy(
$this->client->getContainer()->getParameter('default_db_path'),
$this->client->getContainer()->getParameter('test_db_path'));
} else {
static::runCommand($this->client->getKernel(), ['command' => 't:f', '-e' => 'test', '-f' => true]);
}
...
}
public function tearDown()
{
...
$this->fs->remove($this->client->getContainer()->getParameter('test_db_path'));
...
}
...
public static function runCommand(KernelInterface $kernel, array $arguments = [])
{
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput($arguments);
$output = new BufferedOutput();
$application->run($input, $output);
}
...
}
<?php
require_once __DIR__ . '/../app/autoload.php';
$kernel = new AppKernel('test', true);
$kernel->boot();
\Tests\AppBundle\AppTestCase::runCommand($kernel, ['command' => 't:f', '-e' => 'test']);
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
...
bootstrap="tests/bootstrap.php"
>
...
</phpunit>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment