php – 仅在使用Behat时发生语义错误

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 仅在使用Behat时发生语义错误脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
你好StackOverflow社区,我刚加入社区,这是我的第一个问题:)

我正在使用Symfony2.当我使用浏览器(firefox)手动访问页面时:

http://localhost:8000/vendor/add-PRoduct

页面呈现正常,我看到一个表单,允许用户将产品添加到他的商店.

但是当我使用Behat进行测试时,我收到此错误

这是相关代码(的一部分):

namespace AppBundle\EntITy;

use Doctrine\ORM\Mapping as ORM;
use Symfony\component\Validator\Constraints as Assert;
use Symfony\bridge\Doctrine\Validator\Constraints\uniqueEntity;

/**
* @ORM\Entity
* @ORM\Table(name="app_products")
*/
class Product
{
    /**
    * @ORM\Id
    * @ORM\Column(tyPE="integer")
    * @ORM\GeneratedValue(strategy="AUTO")
    */
    private $productId;

    /**
    * @ORM\Column(type="integer")
    * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Store")
    */
    private $storeid;

    /**
    * @ORM\Column(type="string",length=255)
    * @Assert\NotBlank(message="This is important,Product Name should not be blank!")
    * @Assert\Length(max = "255",maXMessage="Your description must not exceed 255 characters.")
    */
    private $productName;

    /**
    * @ORM\Column(type="integer",length=255)
    * @Assert\GreaterThanOrEqual(value=0)
    * @Assert\NotBlank(message="Product Price should not be blank!")
    */
    private $productPrice;

    /**
    * @ORM\Column(type="string",length=255)
    * @Assert\NotBlank(message="Please enter a product description.")
    * @Assert\Length(max = "255",maxMessage="Your description must not exceed 255 characters.")
    */
    private $productDescription;

    /**
    * @ORM\Column(type="integer")
    * @Assert\GreaterThanOrEqual(value=0)
    * @Assert\NotBlank(message="Product Quantity should not be blank!")
    */
    private $productQuantity;

    /**
    * @ORM\Column(type="string",length=255)
    * @Assert\File(mimeTypes={ "image/jpeg" })
    * @Assert\File(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 "@Doctrine\ORM\Mapping\Entity" in 
class AppBundle\Entity\User 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 }

脚本宝典总结

以上是脚本宝典为你收集整理的php – 仅在使用Behat时发生语义错误全部内容,希望文章能够帮你解决php – 仅在使用Behat时发生语义错误所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。