[英]no route found in symfony 2 functional test
我正在尝试编写一个symfony 2功能测试。 这是我的代码:
<?php
namespace WebSite\MainBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ProductControllerTest extends WebTestCase
{
public function testPageContents()
{
$domCategoryLinksExpr = '.catalog-col-block > ul > li > a';
$client = static::createClient();
$crawler = $client->request('GET', '/catalog/');
$this->assertTrue($client->getResponse()->getStatusCode() == '200');
$countCategories = $crawler->filter($domCategoryLinksExpr)->count();
$this->assertTrue($crawler->filter($domCategoryLinksExpr)->count() > 0);
$categoryLink = $crawler->filter($domCategoryLinksExpr)->eq(rand(1, $countCategories))->link();
$crawler = $client->click($categoryLink);
}
}
但是当我运行这个测试时:
phpunit -c app src/WebSite/MainBundle/Tests/Controller/
我懂了:
1)WebSite \\ MainBundle \\ Tests \\ Controller \\ ProductControllerTest :: testPageContents Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException:找不到“GET /app_dev.php/catalog/psp”的路由...
/app_dev.php/catalog/psp
是$categoryLink->getUri()
的动态值。 并且此路由存在且在Web浏览器中正常工作。 有任何想法吗?
UPD:
这是我的路由规则:
routing_dev.yml:
...
_main:
resource: routing.yml
....
routing.yml:
....
WebSiteCategoryBundle:
resource: "@WebSiteCategoryBundle/Controller/"
type: annotation
prefix: /
....
src/WebSite/CategoryBundle/CategoryController.php:
/**
* @Route("/catalog")
*/
class CategoryController extends Controller
{
/**
* @Route("/{alias}", name="show_category" )
* @Template()
*/
public function showAction( $alias )
{
// some action here
}
}
它在浏览器中运行良好,但似乎$ crowler确实没有看到这个注释规则。
UPD2:问题出现在Symfony 2标准版中缺少的“routing_test.yml”中。 所以我创建它:
routing_test.yml:
_main:
resource: routing_dev.yml
和异常消失。 谢谢大家。
如果您发布了routing.yml,那就太好了
您还可以查看: http : //symfony.com/doc/master/bundles/SensioFrameworkExtraBundle/annotations/routing.html
您可以在操作中使用路由注释。
为了解决您的问题,我希望看到您的路由配置。
echo $ client-> getResponse() - > getContent()将帮助您进行调试(即使有例外)。 它将输出请求的html。
看起来您的路线不存在,可能位于错误的位置(指定了错误的环境?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.