php – 在symfony 2功能测试中找不到路由
我正在尝试编写一个symfony 2功能测试.这是我的代码:
<?php namespace WebSiteMainBundleTestsController; use SymfonyBundleFrameworkBundleTestWebTestCase; 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/ 我懂了:
/app_dev.php/catalog/psp是$categoryLink-> getUri()的动态值.和 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,那就太好了
你也可以看看: 您可以在操作中使用路由注释. 为了解决您的问题,我希望看到您的路由配置. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |