- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在使用 WebTestCase
类进行功能测试时,@Route
注释似乎不起作用。
我的 Controller 看起来像这样:
<?php
namespace Foo\ShopBundle\Controller;
use Foo\ShopBundle\Entity\Cart;
use Foo\ShopBundle\Entity\ProductInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* @Route("cart")
*/
class CartController extends Controller
{
const CART_ID = 'cart_id';
/**
* @Route("/")
* @Template()
*/
public function indexAction()
{
return array('cart' => $this->getCart($this->getCurrentUserName(), $this->getCurrentSessionId()));
}
...
?>
如果我从我的浏览器调用 Controller ,这工作正常。但是在 WebTestCase
中调用相同的 URL 会产生以下异常:
Doctrine\Common\Annotations\AnnotationException : [Semantical Error] The annotation "@Sensio\Bundle\FrameworkExtraBundle\Configuration\Route" in class Foo\ShopBundle\Controller\CartController does not exist, or could not be auto-loaded.
#0 /Users/ernst/Source/php/cinergy/shop/vendor/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php(597): Doctrine\Common\Annotations\AnnotationException::semanticalError('The annotation ...')
#1 /Users/ernst/Source/php/cinergy/shop/vendor/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php(533): Doctrine\Common\Annotations\DocParser->Annotation()
#2 /Users/ernst/Source/php/cinergy/shop/vendor/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php(297): Doctrine\Common\Annotations\DocParser->Annotations()
#3 /Users/ernst/Source/php/cinergy/shop/vendor/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationReader.php(151): Doctrine\Common\Annotations\DocParser->parse('/**? * @Route("...', 'class Foo\S...')
#4 /Users/ernst/Source/php/cinergy/shop/vendor/doctrine/common/lib/Doctrine/Common/Annotations/FileCacheReader.php(90): Doctrine\Common\Annotations\AnnotationReader->getClassAnnotations(Object(ReflectionClass))
#5 /Users/ernst/Source/php/cinergy/shop/vendor/jms/di-extra-bundle/JMS/DiExtraBundle/Metadata/Driver/AnnotationDriver.php(65): Doctrine\Common\Annotations\FileCacheReader->getClassAnnotations(Object(ReflectionClass))
#6 /Users/ernst/Source/php/cinergy/shop/vendor/jms/metadata/src/Metadata/Driver/LazyLoadingDriver.php(20): JMS\DiExtraBundle\Metadata\Driver\AnnotationDriver->loadMetadataForClass(Object(ReflectionClass))
#7 /Users/ernst/Source/php/cinergy/shop/vendor/jms/metadata/src/Metadata/MetadataFactory.php(77): Metadata\Driver\LazyLoadingDriver->loadMetadataForClass(Object(ReflectionClass))
#8 /Users/ernst/Source/php/cinergy/shop/vendor/jms/di-extra-bundle/JMS/DiExtraBundle/HttpKernel/ControllerResolver.php(84): Metadata\MetadataFactory->getMetadataForClass('Foo\ShopBun...')
#9 /Users/ernst/Source/php/cinergy/shop/vendor/jms/di-extra-bundle/JMS/DiExtraBundle/HttpKernel/ControllerInjectorsWarmer.php(31): JMS\DiExtraBundle\HttpKernel\ControllerResolver->createInjector('Foo\ShopBun...')
#10 /Users/ernst/Source/php/cinergy/shop/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php(47): JMS\DiExtraBundle\HttpKernel\ControllerInjectorsWarmer->warmUp('/Users/ernst/So...')
#11 /Users/ernst/Source/php/cinergy/shop/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(595): Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp('/Users/ernst/So...')
#12 /Users/ernst/Source/php/cinergy/shop/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(133): Symfony\Component\HttpKernel\Kernel->initializeContainer()
#13 /Users/ernst/Source/php/cinergy/shop/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php(43): Symfony\Component\HttpKernel\Kernel->boot()
#14 /Users/ernst/Source/php/cinergy/shop/src/Foo/ShopBundle/Tests/Controller/CartControllerFunctionalTest.php(19): Symfony\Bundle\FrameworkBundle\Test\WebTestCase::createClient()
#15 [internal function]: Foo\ShopBundle\Tests\Controller\CartControllerFunctionalTest->testIndexAction()
#16 /Applications/MAMP/bin/php/php5.3.14/lib/php/PHPUnit/Framework/TestCase.php(967): ReflectionMethod->invokeArgs(Object(Foo\ShopBundle\Tests\Controller\CartControllerFunctionalTest), Array)
#17 /Applications/MAMP/bin/php/php5.3.14/lib/php/PHPUnit/Framework/TestCase.php(825): PHPUnit_Framework_TestCase->runTest()
#18 /Applications/MAMP/bin/php/php5.3.14/lib/php/PHPUnit/Framework/TestResult.php(649): PHPUnit_Framework_TestCase->runBare()
#19 /Applications/MAMP/bin/php/php5.3.14/lib/php/PHPUnit/Framework/TestCase.php(770): PHPUnit_Framework_TestResult->run(Object(Foo\ShopBundle\Tests\Controller\CartControllerFunctionalTest))
#20 /Applications/MAMP/bin/php/php5.3.14/lib/php/PHPUnit/Framework/TestSuite.php(776): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#21 /Applications/MAMP/bin/php/php5.3.14/lib/php/PHPUnit/Framework/TestSuite.php(746): PHPUnit_Framework_TestSuite->runTest(Object(Foo\ShopBundle\Tests\Controller\CartControllerFunctionalTest), Object(PHPUnit_Framework_TestResult))
#22 /Applications/MAMP/bin/php/php5.3.14/lib/php/PHPUnit/Framework/TestSuite.php(706): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult), false, Array, Array, false)
#23 /Applications/MAMP/bin/php/php5.3.14/lib/php/PHPUnit/TextUI/TestRunner.php(325): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult), false, Array, Array, false)
#24 /Applications/MAMP/bin/php/php5.3.14/lib/php/PHPUnit/TextUI/Command.php(177): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
#25 /private/var/folders/kc/ylyxk45170z_g5h6c2_vr0_00000gp/T/ide-phpunit.php(102): PHPUnit_TextUI_Command->run(Array, true)
#26 /private/var/folders/kc/ylyxk45170z_g5h6c2_vr0_00000gp/T/ide-phpunit.php(442): IDE_PHPUnit_TextUI_Command::main()
#27 {main}
有什么办法解决这个问题吗?
最佳答案
尝试将此添加到您的 setUp() 方法(不要忘记定义 $vendor Dir)
use Doctrine\Common\Annotations\AnnotationRegistry;
....
public function setUp()
{
/** To make annotations work here */
AnnotationRegistry::registerAutoloadNamespaces(array('Sensio\\Bundle\\FrameworkExtraBundle' => $vendorDir . '/sensio/framework-extra-bundle/'));
....
关于testing - WebTestCase 不会自动加载@Route 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13582055/
我尝试在 PhpUnit 的 WebTestCase 中发送原始数据,但它不起作用: $jsonEvent = '{ "type": "invoice.payment_succeeded"
我正在尝试从 WebTestCase 中调用“router:debug”命令来自动验证所有静态路由。 class RoutesTest extends WebTestCase { public f
我想做的是对我的包(可重复使用的包)进行功能测试。更深入: 创建对给定 url /my/url 的请求> 检查是否调用了 MyParamConverter 并将请求转换为 MyObject 的实例>
我目前正在为我的 symfony 应用程序编写功能测试。我将 symfony 3 (3.1.6) 与 phpunit 5.6.1 一起使用。编辑:根据 Alvin Bunk 的要求,我的应用程序不是网
Symfony WebTestCase 是一个只启动内核并测试响应对象的工具,还是生成一个 PHP Web 服务器并针对服务器进行测试的工具? 这是为了了解我是否可以测试 Symfony 框架之外的遗
我尝试为我的应用编写功能测试,但出现以下错误: InvalidArgumentException: The option "test_case" must be set. 我尝试用谷歌搜索它,但几乎没
use Liip\FunctionalTestBundle\Test\WebTestCase; class ControllerTest extends WebTestCase { publi
检查 php bin/console debug:autowiring 时,出现以下错误: In FileLoader.php line 168: Class Symfony\Bundle\Fra
在使用 WebTestCase 类进行功能测试时,@Route 注释似乎不起作用。 我的 Controller 看起来像这样: $this->getCart($this->getCurrentUse
我想测试我的 cookie 是否在 Controller 中设置正确。 class RedirectControllerTest extends WebTestCase { public
我有一个使用 Symfony2 编写的 API,我正在尝试为其编写事后测试。其中一个端点使用电子邮件服务向用户发送密码重置电子邮件。我想模拟此服务,以便我可以检查是否向该服务发送了正确的信息,并防止实
我有一个 WebTestCase,它在我的应用程序中执行一些基本路由。 我想在 PHPUnit 的 setUp 方法上创建一个与我的主数据库相同的测试数据库,并将固定装置加载到其中。 我目前正在做一些
使用 Symfony2 WebTestCase,我有以下测试: $client->request('GET', '/'); $this->assertTrue($client->getResponse
我的应用程序通过 $this->get('request')->getHost() 生成一些绝对链接。问题是:当我尝试运行测试用例时,我收到以下错误消息: [exception] 500 | Inte
我正在尝试访问 Symfony2 WebTestCase 中的容器,但我得到的是 NULL。有任何想法吗?这是我的代码: $this->client = static::createClient();
我用 composer create project 开始了一个新的 symfony/skeleton 项目。 现在我想添加php单元,所以我这样做 composer require --dev te
我正在尝试设置一个简单的 WebTestCase,它使用 Symfony 4(和 "phpunit/phpunit": "^6.5")。但是,测试失败: Failed to start the ses
我正在尝试在 symfony 2.3 中测试一个表单,该表单具有一个选择输入...以及一个文件上传(enctype multipart/form-data) 选择输入如下... 这是必填字段。 有 3
我安装了 phpunit 3.6.12 和 Silex。在我的应用程序的根目录中,我有包含简单测试文件 BlogFunctionTest.php 的测试目录 assertGreaterThan(0,
我的很多测试都有很多相同的 setUp()/tearDown()正在发生的事情。将相同的代码复制并粘贴到我的每个单元测试中似乎很愚蠢。我想我想创建一个扩展 WebTestCase 的新测试类我的其他测
我是一名优秀的程序员,十分优秀!