Reputation: 1543
I'm trying to run a fixture command from php code while running my phpunit tests.
It ends up in the following error:
Symfony\\Component\\Console\\Exception\\CommandNotFoundException] There are no commands defined in the \u0022doctrine:fixtures
I must say that I've been running the same stuff on my controller and it worked perfectly. Not only cannot it find the doctrine:fixtures
command but also all the others.
It is as if all commands were unreachable while running tests.
This is my code:
namespace tests\functional\User\ManagerBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Output\BufferedOutput;
class ClassControllerTest extends WebTestCase
{
protected function setUp()
{
$client = static::createClient();
$application = new Application($client->getKernel());
$application->setAutoExit(false);
$input = new ArrayInput(array(
'command' => 'doctrine:fixtures:load',
// (optional) define the value of command arguments
// 'fooArgument' => 'barValue',
// (optional) pass options to the command
'--no-interaction' => true,
'--env' => 'TEST'
));
// You can use NullOutput() if you don't need the output
$output = new BufferedOutput();
$application->run($input, $output);
// return the output, don't use if you used NullOutput()
$content = $output->fetch();
var_dump(new JsonResponse($content));
}
}
Upvotes: -1
Views: 1498
Reputation: 1543
Simple answer:
I had to use the following statement
use Symfony\Bundle\FrameworkBundle\Console\Application;
instead of
use Symfony\Component\Console\Application;
Upvotes: 3