M
M
Maxim2018-03-22 12:33:06
Yii
Maxim, 2018-03-22 12:33:06

Why is there a problem when testing unit tests if there are several methods?

Hello!
The project is being unit tested on yii2 using codeception.
Command in progress:
php codecept.phar run --debug unit ExampleTest
Test code:

<?php

class ExampleTest extends \Codeception\Test\Unit
{
    /**
     * @var \UnitTester
     */
    protected $tester;

    protected function _before()
    {
    }

    protected function _after()
    {
    }

    // tests
    public function testSomeFeature()
    {

    }

    public function testSomeFeature2()
    {

    }
}

As a result of the test, on the testSomeFeature2() method, an error occurs:
- ExampleTest: Some feature
  [Database] Transaction started
+ ExampleTest: Some feature (0.01s)
  [Database] Transaction cancelled; all changes reverted.
- ExampleTest: Some feature2
Fatal error: Cannot declare class Yii, because the name is already in use in C:\OSPanel\domains\yii2tests.loc\vendor\yiisoft\yii2\Yii.php on line 21

If, to test only 1 method, then everything works fine.
config files.
unit.suite.xml
# Codeception Test Suite Configuration

# suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.

class_name: UnitTester
modules:
    enabled:
      - Asserts
      - Yii2:
            configFile: 'tests/config/unit.php'
            part: [orm, email]

/tests/config/unit.php
<?php
/**
 * Application configuration for acceptance tests
 */
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');

return yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/../../config/web.php'),
    require(__DIR__ . '/config.php'),
    []
);

Why does the error "Fatal error: Cannot declare class Yii, because the name is already in use" appear when testing several methods and how to fix it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question