我正在跟随这个博客创建使用我的数据夹具作为基础的单元测试.相关代码:
namespace Tests\AppBundle\Repository;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DataFixtureTestCase extends WebTestCase
{
protected $client, $container, $em;
protected static $application;
/**
* {@inheritdoc}
*/
protected function setUp()
{
self::runCommand('doctrine:schema:drop --force');
self::runCommand('doctrine:schema:create');
self::runCommand('doctrine:fixtures:load --append --no-interaction --force');
$this->client = static::createClient();
$this->container = $this->client->getContainer();
$this->em = $this->container->get('doctrine')->getManager();
}
protected static function runCommand($command)
{
$command = sprintf('%s --quiet', $command);
try {
return self::getApplication()->run(new StringInput($command));
} catch(\Exception $e) {
echo $e->getMessage();
}
}
protected static function getApplication()
{
if (null === self::$application) …Run Code Online (Sandbox Code Playgroud)