Codeception BDD是否有类似Behat的@Transform函数?

huangapple go评论69阅读模式
英文:

Does Codeception BDD have a @Transform function like Behat does?

问题

在Behat中,你可以进行如下的转换:

<?php

/**
 * @Transform /^"([^"]+)" shipping method$/
 * @Transform /^shipping method "([^"]+)"$/
 * @Transform :shippingMethod
 */
public function getShippingMethodByName($shippingMethodName)
{
    $shippingMethod = $this->shippingMethodRepository->findOneByName($shippingMethodName);

    Assert::notNull(
        $shippingMethod,
        sprintf('Shipping method with name "%s" does not exist', $shippingMethodName)
    );

    return $shippingMethod;
}

/**
 * @Given /^(shipping method "[^"]+") belongs to ("[^"]+" tax category)$/
 */
public function shippingMethodBelongsToTaxCategory(
    ShippingMethodInterface $shippingMethod,
    TaxCategoryInterface $taxCategory
) {
    // some logic here
}

基本上,你可以在变量前面加上冒号,并使用 @Transform 关键字来实现这种转换。

Codeception中是否有类似的方式可以实现这个功能?

英文:

In Behat you can do a transformation like so:

&lt;?php

/**
 * @Transform /^&quot;([^&quot;]+)&quot; shipping method$/
 * @Transform /^shipping method &quot;([^&quot;]+)&quot;$/
 * @Transform :shippingMethod
 */
public function getShippingMethodByName($shippingMethodName)
{
    $shippingMethod = $this-&gt;shippingMethodRepository-&gt;findOneByName($shippingMethodName);

    Assert::notNull(
        $shippingMethod,
        sprintf(&#39;Shipping method with name &quot;%s&quot; does not exist&#39;, $shippingMethodName)
    );

    return $shippingMethod;
}

/**
 * @Given /^(shipping method &quot;[^&quot;]+&quot;) belongs to (&quot;[^&quot;]+&quot; tax category)$/
 */
public function shippingMethodBelongsToTaxCategory(
    ShippingMethodInterface $shippingMethod,
    TaxCategoryInterface $taxCategory
) {
    // some logic here
}

Basically, adding a colon before a variable and using @Transform keyword.

Is there a way to do that in Codeception?

答案1

得分: 1

Codeception,尽管使用了Behat供应商库,但不实现@Transform功能。

英文:

codeception, despite using behat vendor libraries, does not implement the @Transform feature.

huangapple
  • 本文由 发表于 2023年3月7日 23:25:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75663918.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定