【发布时间】:2017-11-06 16:25:35
【问题描述】:
我正在尝试在运行我的 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));
}
}
【问题讨论】:
-
谢谢!!这解决了我的问题。但是我不认为它可以被认为是重复的。在这种情况下,我需要使用
Symfony\Bundle\FrameworkBundle\Console\Application而不是Symfony\Component\Console\Application -
嗯,这正是相关答案所说的,可能你读得太快了:)
标签: symfony unit-testing symfony-3.3 symfony-console symfony3.x