Есть отличная удаленная работа для php+codeception+jenkins+allure+docker спецов. 100% remote! Присоединиться к проекту

Codeception не находит класс ступени при запуске теста

codeception
Теги: #<Tag:0x00007f7b62317290>

(Magvan) #1

Добрый день!

Изучаю Yii2 по книге “Web Application Development with Yii 2”.

“Codeception” не может найти класс.

Вот что я сделал:

  1. $ php composer.phar require “codeception/codeception:*”
  2. В конфиг прописал сайт

config:
PhpBrowser:
url: ‘http://site

  1. $ php composer.phar require “fzaninotto/faker:*”
  2. $ cept generate:cept acceptance QueryCustomerByPhoneNumber
<?php $I = new \AcceptanceTester\CRMOperatorSteps($scenario); $I->wantTo('add two different customers to database');

$I->amInAddCustomerUi();
$first_customer = $I->imagineCustomer();
$I->fillCustomerDataForm($first_customer);
$I->submitCustomerDataForm();

$I->seeIAmInListCustomersUi();

$I->amInAddCustomerUi();
$second_customer = $I->imagineCustomer();
$I->fillCustomerDataForm($second_customer);
$I->submitCustomerDataForm();

$I->seeIAmInListCustomersUi();

//$I = new \AcceptanceTester\CRMUserSteps($scenario);
$I = new CRMUserSteps($scenario);
$I->wantTo(‘query the customer info using his phone number’);

$I->amInQueryCustomerUi();
$I->fillInPhoneFieldWithDataForm($first_customer);
$I->clickSearchButton();

$I->seeIAmInListCustomersUi();
$I->seeCustomerInList($first_customer);
$I->dontSeeCustomerInList($second_customer);

  1. $ cept generate:stepobject acceptance CRMOperatorSteps
<?php namespace Step\Acceptance;

class CRMOperatorSteps extends \AcceptanceTester
{
public function amInAddCustomerUi()
{
$I = $this;
$I->amOnPage(’/customers/add’);
}

public function imagineCustomer()
{
$faker = \Faker\Factory::create();
return [
‘CustomerRecord[name]’ => $faker->name,
‘CustomerRecord[birth_date]’ => $faker->date(‘Y-m-d’),
‘CustomerRecord[notes]’ => $faker->sentence(8),
‘PhoneRecord[number]’ => $faker->phoneNumber
];
}

public function fillCustomerDataForm($fieldData)
{
$I = $this;
foreach ($fieldData as $key => $value) {
$I->fillField($key, $value);
}
}

public function submitCustomerDataForm()
{
$I = $this;
$I->click(‘Submit’);
}

public function seeIAmInListCustomersUi()
{
$I = $this;
$I->seeCurrentUrlMatches(’/customers/’);
}

public function amInListCustomersUi()
{
$I = $this;
$I->amOnPage(’/customers/’);
}
}

  1. $ cept generate:stepobject acceptance CRMUserSteps
<?php namespace Step\Acceptance;

class CRMUserSteps extends \AcceptanceTester
{
public function amInQueryCustomerUi()
{
$I = $this;
$I->amOnPage(’/customers/query’);
}

public function fillInPhoneFieldWithDataFrom($customer_data)
{
$I = $this;
$I->fillField(‘PhoneRecord[number]’, $customer_data[‘PhoneRecord[number]’]);
}

public function clickSearchButton()
{
$I = $this;
$I->click(‘Search’);
}

public function seeIAmInListCustomersUi()
{
$I = $this;
$->seeCurrentUrlMatches(’/customers/’);
}

public function seeCustomerInList($customer_data)
{
$I = $this;
$I->see($customer_data[‘CustomerRecord[name]’], ‘#search_results’);
}

public function dontSeeCustomerInList($customer_data)
{
$I = $this;
$I->dontSee($customer_date[‘CustomerRecord[name]’], ‘#search_results’);
}
}

  1. $ cept build
  2. $ cept run

Error:

Acceptance Tests (2) --------------------------------------------------------------------------------------------------------------------
Trying to add two different customers to database (QueryCustomerByPhoneNumberCept)… PHP Fatal error: Class ‘AcceptanceTester\CRMOperatorSteps’ not found in /home/m/magvan/crmapp/tests/acceptance/QueryCustomerByPhoneNumberCept.php on line 2

FATAL ERROR. TESTS NOT FINISHED.
Class ‘AcceptanceTester\CRMOperatorSteps’ not found
in /home/m/magvan/crmapp/tests/acceptance/QueryCustomerByPhoneNumberCept.php:2

При запуске теста выдает ошибку. Подскажите, пожалуйста, куда копать =)


(Magvan) #2

Я решил проблему. Добавил в файл QueryCustomerByPhoneNumberCept.php
следующий код

use Step\Acceptance\CRMOperatorSteps;
use Step\Acceptance\CRMUserSteps;

(Aleshinib) #3

Вместо

$I = new \AcceptanceTester\CRMOperatorSteps($scenario);
$I = new \AcceptanceTester\CRMUserSteps($scenario);

Пишем

$I = new \Step\Acceptance\CRMOperatorSteps($scenario);
$I = new \Step\Acceptance\CRMUserSteps($scenario);