【问题标题】:Codeception call to undefined method assertEquals对未定义方法 assertEquals 的代码接收调用
【发布时间】:2021-03-01 18:51:51
【问题描述】:

我的 Codeception 冒险刚刚开始。 即使我声明了 assertEquals() 方法,我也遇到了问题 use PHPUnit\Framework\Assert;

代码测试:

<?php declare(strict_types=1);
namespace Product\TestApi;
use Product\ApiTester;
use Codeception\Util\HttpCode;
use PHPUnit\Framework\Assert;
public function CreateProduct(ApiTester $I)
    {
        $I->sendPost('/api/product/');
        $I->seeResponseCodeIs(HttpCode::CREATED);

        $responsePost = $I->grabDataFromResponseByJsonPath('$..product');
        $I-$this->assertEquals(4,strlen((string)$responsePost));

        $I->seeResponseContainsJson(
            [
                'category' => 'main',
                'product' => 'fish',
            ]
        );
    }
}

我收到一个错误:

api/CreateProductCest.php:createProduct
                                                                                              
  [Error] Call to undefined method Product\TestApi\CreateProductCest::assertEquals()  
                                                                                              

Scenario Steps:

 3. $I->grabDataFromResponseByJsonPath("$..product") at api/CreateProductCest.php:42
 2. $I->seeResponseCodeIs(201) at api/CreateProductCest.php:41
 1. $I->sendPost("/api/product/") at api/CreateProductCest.php:40

#1  /product-service/modules/Product/tests/api/CreateProductCest.php:43
#2  Product\TestApi\CreateProductCest->createProduct
Artifacts:

Body: {"id":3,"product":"fish","category":"main"}

【问题讨论】:

    标签: php codeception


    【解决方案1】:

    $this-&gt;assertEquals 在 Cest 格式中不可用,您必须在套件配置文件中启用 Asserts 模块,然后使用 $I-&gt;assertEquals

    api.suite.yaml:

    actor: ApiTester
    modules:
        enabled:
            - Asserts
            - REST:
                depends: PhpBrowser
    

    【讨论】:

      猜你喜欢
      • 2020-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多