php – 仅在使用Behat时发生语义错误
你好StackOverflow社区,我刚加入社区,这是我的第一个问题:)
我正在使用Symfony2.当我使用浏览器(firefox)手动访问页面时: http://localhost:8000/vendor/add-product 页面呈现正常,我看到一个表单,允许用户将产品添加到他的商店. 但是当我使用Behat进行测试时,我收到此错误:
这是相关源代码(的一部分): namespace AppBundleEntity; use DoctrineORMMapping as ORM; use SymfonyComponentValidatorConstraints as Assert; use SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity; /** * @ORMEntity * @ORMTable(name="app_products") */ class Product { /** * @ORMId * @ORMColumn(type="integer") * @ORMGeneratedValue(strategy="AUTO") */ private $productId; /** * @ORMColumn(type="integer") * @ORMManyToOne(targetEntity="AppBundleEntityStore") */ private $storeId; /** * @ORMColumn(type="string",length=255) * @AssertNotBlank(message="This is important,Product Name should not be blank!") * @AssertLength(max = "255",maxMessage="Your description must not exceed 255 characters.") */ private $productName; /** * @ORMColumn(type="integer",length=255) * @AssertGreaterThanOrEqual(value=0) * @AssertNotBlank(message="Product Price should not be blank!") */ private $productPrice; /** * @ORMColumn(type="string",length=255) * @AssertNotBlank(message="Please enter a product description.") * @AssertLength(max = "255",maxMessage="Your description must not exceed 255 characters.") */ private $productDescription; /** * @ORMColumn(type="integer") * @AssertGreaterThanOrEqual(value=0) * @AssertNotBlank(message="Product Quantity should not be blank!") */ private $productQuantity; /** * @ORMColumn(type="string",length=255) * @AssertFile(mimeTypes={ "image/jpeg" }) * @AssertFile(maxSize="6000000") */ private $productImage; ... 这是我的特色: Feature: Buying products As a customer,I want to view and select products before buying,So that I could have more value for my money Background: Given I am on the homepage When I fill in "username" with "24thsaint" And I fill in "password" with "123123" And I press "login-button" Scenario: Vendor wants to add a new product Given I am on the homepage When I follow "My Store" ###### The test stops here as I get the Semantical Error And I follow "add-new-product" 请帮忙,我真的觉得一切都到位了.只是在使用Behat进行测试期间发生了错误.什么可能出错? 编辑: 我通过清除缓存做了先生Evgeniy Kuzmin的建议.我跑了, php bin/console cache:clear --env=test 之前通过的测试现在失败,出现此错误: [Semantical Error] The annotation "@DoctrineORMMappingEntity" in class AppBundleEntityUser does not exist,or could not be auto-loaded. 请帮我. 解决方法
当您通过localhost手动访问表单时,很可能使用dev env.但是当Behat走向同一条路线时,它会使用测试环境.
所以首先尝试使用选项“-e test”清除缓存 另一点是检查你config_test.yml,可能你覆盖那里的选项 framework: validation: { enabled: true,enable_annotations: true } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |