我正在尝试从WebTestCase中调用“ router:debug”命令来自动验证所有静态路由。

class RoutesTest extends WebTestCase
{
  public function setUp()
   {
     $command = self::getApplication()->find('router:debug');
     $input = new ArrayInput(array());
     $returnCode = $command->run($input, $output);
     if($returnCode == 0) {
        var_dump($output);
     }
   }
}


但是我得到了


PHP致命错误:调用/data/www/symfony/src/Prexem/UserBundle/Tests/Controller/DefaultControllerTest.php中未定义的方法MyApplication \ MyBundle \ Tests \ Controller \ RoutesTest :: getApplication()

最佳答案

我以为self :: getApplication()是WebTestCase的成员,因为我看到了使用此方法的代码片段。

但是实际上我必须像这样实现它:
Best way to create a test database and load fixtures on Symfony 2 WebTestCase?

关于symfony - 从WebTestCase内部调用命令,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28362662/

10-13 01:24