gpt4 book ai didi

testing - 不能多次执行 Laravel 4 Action /路由测试

转载 作者:行者123 更新时间:2023-11-28 21:31:53 26 4
gpt4 key购买 nike

我遇到了 Laravel 4 测试问题: Action /路由测试只能运行一次,而且必须是第一次测试运行。在调用断言之前,任何后续操作/路由测试都将失败并出现异常。

  • 路由/操作测试只要是第一次测试运行就会运行。
  • 非路由/ Action 测试正常运行,尽管它们会导致后续路由/ Action 测试抛出异常

重要的是要注意,有问题的测试不会失败,它们会在触发操作时抛出异常,例如:

Symfony\Component\Routing\Exception\RouteNotFoundException: Unable to generate a URL for the named route "home" as such route does not exist.

示例测试类:

class ExampleTest extends TestCase {

// passes
public function testOne()
{
$class = MyApp::ApiResponse();
$this->assertInstanceOf('\MyApp\Services\ApiResponse', $class);
}

// this fails unless moved the top of the file
public function testRoute()
{
$this->route('GET','home');
$this->assertTrue($this->client->getResponse()->isOk());
}

// passes
public function testTwo()
{
$class = MyApp::ProjectService();
$this->assertInstanceOf('\MyApp\Services\ProjectService', $class);
}

}

这是特定于实现的,新的 Laravel 4 项目不会出现该问题。是什么导致了这种行为?您将如何追踪问题?

最佳答案

在这种情况下,路由文件是使用 include_once 调用调用的。当运行后续测试时,路线是空的。

更改为 include() 解决了问题中出现的问题

关于testing - 不能多次执行 Laravel 4 Action /路由测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17985803/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com