我正在尝试在运行 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));
}
}
简单回答:
我不得不使用以下语句
use Symfony\Bundle\FrameworkBundle\Console\Application;
而不是
use Symfony\Component\Console\Application;