我正在尝试在运行我的 phpunit 测试时从 php 代码运行夹具命令。它最终出现以下错误:
Symfony\\Component\\Console\\Exception\\CommandNotFoundException] There are no commands defined in the \u0022doctrine:fixtures
我必须说我一直在我的控制器上运行相同的东西并且它运行良好。它不仅找不到doctrine:fixtures
命令,而且找不到所有其他命令。
就好像在运行测试时所有命令都无法访问。
这是我的代码:
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));
}
}