【发布时间】:2016-06-22 15:02:44
【问题描述】:
我正在用 PHPUnit 为 Symfony 编写一些虚拟测试,以便更多地了解 PHP 中的功能测试。
这就是问题所在。 这是我的测试方法:
//Redirecting test by clicking on href
public function testRedirect() {
$client = static::createClient();
$crawler = $client->request('GET', '/redirect');
$link = $crawler->selectLink('Click me !')->link();
$client->click($link);
$crawler2 = $client->followRedirect();
$this->assertTrue(
$client->getResponse()->isRedirect()
);
$this->assertTrue($crawler2->filter('html:contains("Haha, you\'ve been redirect !")')->count() > 0);
}
这是我的链接:
<a href="{{ path('redirect2') }}">Click me !</a>
以及目的地的消息:
Haha, you've been redirect !
我认为
redirect2
是我的路线名称。
测试给了我:
1) AppBundle\Tests\Controller\DefaultControllerTest::testRedirect
LogicException: The request was not redirected.
所以我的问题是:href 是否被视为重定向?
提前致谢! 最远的,
【问题讨论】:
标签: php symfony redirect routes phpunit