在另一个特征和类中引用相同的特征
PHP 似乎试图编译相同的 trait 两次.
PHP seems to be trying to compile the same trait twice.
use Behat\MinkExtension\Context\MinkDictionary;
class FeatureContext
{
use MinkDictionary, OrderDictionary;
}
use Behat\MinkExtension\Context\MinkDictionary;
trait OrderDictionary
{
//if you comment out this line, everything works, but methodFromMinkTrait is
//unresolved
use MinkDictionary;
public function myMethod($element, $text)
{
//some method that uses methods from MinkDictionary
return $this->methodFromMinkTrait();
}
}
编译失败,出现致命错误:
致命错误:Trait 方法 setMink 没有被应用,因为在 LunchTime\DeliveryBundle\Features\Context\FeatureContext 上与其他 trait 方法有冲突
Fatal error: Trait method setMink has not been applied, because there are collisions with other trait methods on LunchTime\DeliveryBundle\Features\Context\FeatureContext
setMink
方法仅在 MinkDictionary
trait 中定义.
setMink
method is only defined in MinkDictionary
trait.
问题在于 OrderDictionary
和 FeatureContext
都使用了来自 MinkDictionary
的方法.这就是为什么我在 OrderDictionary
中添加了 use MinkDictionary
.这是不允许的吗?如果您将其注释掉,那么一切正常,但编辑器显示了许多未解析的方法 - 它不知道它们来自哪里.
The problem is that both OrderDictionary
and FeatureContext
are using methods from MinkDictionary
. That's why I added use MinkDictionary
in OrderDictionary
. Is this not allowed? If you comment that out, then everything works, but the editor is showing a lot of unresolved methods - it doesn't know where they are coming from.
当然它会编译相同的特征两次,因为您在 FeatureContext 类中使用"了 MinkDictionary 两次——第一次是在类本身中,第二次是通过 OrderDictionary.
of course it compiles the same trait twice, because you "use" MinkDictionary twice in class FeatureContext - first in the class itself and second via OrderDictionary.
只需从 FeatureContext 类中删除use MinkDictionary"语句
just remove the "use MinkDictionary" statement from the FeatureContext class