Codeception Помощник Api Suite не вызывает _beforeSuite (), _afterSuite (), _initialize () - PullRequest
0 голосов
/ 01 ноября 2018

Я выполняю рефакторинг набора тестов API. Мне нужно переместить много кода в вспомогательный класс Api внутри _beforeSuite ($ settings = []) & _afterSuite ().

Проблема в том, что эти функции внутри вспомогательного класса api по какой-то причине не вызываются при запуске пакета.

Структура моего проекта

MyApiTests/
  ├── tests/
  │   ├── _data/
  │   │   ├── CommentsData.php
  │   │   ├── MyData.php
  │   │   └── TestData.php
  │   ├── _output/
  │   │   └── some failed reports
  │   ├── _support/
  │   │    ├── _generated
  │   │    │    └── ApiTesterActions.php 
  │   │    ├── Helper
  │   │    │    └── Api.php 
  │   │    └── ApiTester.php
  │   ├── api
  │   │    └── comments
  │   │        └── all my "comment" tests
  │   └── api.suite.yml
  ├── vendor (composer folder)
  ├── codeception.yml
  ├── composer.json
  └── composer.lock

/ Helper / Api.php

namespace Helper;

require_once(__DIR__ . './../../_data/MyData.php');
require_once(__DIR__ . './../../_data/TestData.php');
require_once(__DIR__ . './../../_data/CommentsData.php');

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class Api extends \Codeception\Module
{
    public function _beforeSuite($settings = [])
    {
        echo "TEST";

        parent::_beforeSuite($settings);

        $I = $this;
        $token = MyData::$tokenReadAndWrite;
        $json = CommentsData::$addCommentsProj;
        $keySingJson = CommentsData::$createKeySingular;
        $keyPluralJson = CommentsData::$createKeyPlural;

        $I->wantTo('Setup project and keys for comments');

        // create project for comments
        $projectId = $I->addProject($token,$json);

        // add singular key for adding comments
        $I->addKey($token, $projectId, $keySingJson);

        // add plural key for adding comments
        $I->addKey($token, $projectId, $keyPluralJson);

        echo "TEST";
    }

    public function _afterSuite()
    {
        parent::_afterSuite();
//        $I = $this;
//
//        $token = MyData::$tokenReadAndWrite;
//        $projectName = CommentsData::$projName;
//
//        $I->wantTo('deleting comments project');
//
//        // fetch the id of comments project
//        $projectId = $I->getProjectIdByName($token, $projectName);
//
//        $I->deleteProject($token, $projectId);
    }
}

api.suite.yml

actor: ApiTester
modules:
    enabled:
        - Api

codeception.yml

paths:
    tests: tests
    output: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs

actor_suffix: Tester

extensions:
    enabled:
        - Codeception\Extension\RunFailed


# suite config
suites:
    api:
        actor: ApiTester
        path: .
        modules:
            enabled:
                - REST:
                    url: http://someapp.local/api2/
                    depends: PhpBrowser
                - PhpBrowser:
                    curl:
                      CURLOPT_TIMEOUT: 300
                - Asserts
            config:
              REST:
                timeout: 90
              PhpBrowser:
                url: http://someapp.local/api2/
                curl:
                  CURLOPT_TIMEOUT: 300

Я закомментировал весь код в _afterSuite () для целей отладки. Пробовал разные подходы с переименованием класса, перемещением в другую папку и перепроверкой моих файлов .yml, а также пытался изменить функцию _beforeSuite на _initialize - без разницы. Я чувствую, что что-то упустил.

Обновление:

codecept build не помогло

Ответ:

➜  MyApiTests codecept build

    ==== Redirecting to Composer-installed version in vendor/codeception ====
    Building Actor classes for suites: api
     -> ApiTesterActions.php generated successfully. 0 methods added
    \ApiTester includes modules: REST, PhpBrowser, Asserts
...