I'm following along with this blog to create unit tests that use my data fixtures as a base. The relevant code:
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) {
$client = static::createClient();
self::$application = new Application($client->getKernel());
self::$application->setAutoExit(false);
}
return self::$application;
}
// other methods not relevant to the question
My unit test classes extend DataFixtureTestCase
. When setUp()
is invoked, I keep getting errors like:
There are no commands defined in the "doctrine:schema" namespace
Any ideas on what's causing this? My research hasn't revealed the cause of the error. Doctrine is correctly installed via Composer, and I can run the console commands manually in a terminal.
parent::setUp();
, I assume you shouldn't do that – Vaughn