jeudi 10 octobre 2019

How do I write reusable method/actions in Codeception?

I am writing a set of API tests using Codeception and one of the methods I would like to have on every single test looks like:

public function ActionWasNotDoneIfParamsAreMissing(ApiTester $I): void
{
    $url = $this->serviceUrl;
    $method = $this->method;

    $dataCombination = $I->pcArrayPowerSet($this->data);
    foreach ($dataCombination as $combination) {
        $I->seeExceptionThrown(
            BadRequestHttpException::class,
            static function () use ($I, $url, $combination) {
                $I->$method($url, $combination);
            }
        );
    }
}

I did read docs here and here but is not so clear to me how to achieve re-usability in this scenario.

I wonder if there is a way to add this as part of a Helper so it can be reuse at any single test without the need to repeat the code. Any ideas and/or help?

Aucun commentaire:

Enregistrer un commentaire