@Bombadile

Как исправить ошибку при выполнении тестов Codeception с модулем Yii2?

Есть тест Codeception. Без включенного модуля Yii2 - ошибок нет.

А если в unite.suite.yml включен модуль Yii2:
class_name: UnitTester
modules:
    enabled:
        - Asserts
        - \Helper\Unit
        - Yii2:
                 configFile: 'tests/config/unit.php'
                 part: fixtures


Появляется ошибка:
An Error occurred while handling another error:
PHPUnit_Framework_Exception: Trying to get property of non-object

Тест:
namespace mobile\tests\unit;

class CheckoutTest extends \yii\codeception\TestCase
{
    public function testCartcheck()
    {
        $i = 80;
        expect('equal 80', $i)->equals(80);
    }
}


Логи:
An Error occurred while handling another error:
PHPUnit_Framework_Exception: Trying to get property of non-object

/home/server/yii/vendor/yiisoft/yii2/console/ErrorHandler.php:72
/home/server/yii/vendor/yiisoft/yii2/console/ErrorHandler.php:40
/home/server/yii/vendor/yiisoft/yii2/base/ErrorHandler.php:109

Previous exception:
Error: Call to a member function has() on null in /home/server/yii/vendor/codeception/codeception/src/Codeception/Module/Yii2.php:168
Stack trace:
#0 /home/server/yii/vendor/codeception/codeception/src/Codeception/Subscriber/Module.php(68): Codeception\Module\Yii2->_after(Object(mobile\tests\CheckoutTest))
#1 [internal function]: Codeception\Subscriber\Module->after(Object(Codeception\Event\TestEvent), 'test.after', Object(Symfony\Component\EventDispatcher\EventDispatcher))
#2 /home/server/yii/vendor/symfony/event-dispatcher/EventDispatcher.php(184): call_user_func(Array, Object(Codeception\Event\TestEvent), 'test.after', Object(Symfony\Component\EventDispatcher\EventDispatcher))
#3 /home/server/yii/vendor/symfony/event-dispatcher/EventDispatcher.php(46): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'test.after', Object(Codeception\Event\TestEvent))
#4 /home/server/yii/vendor/codeception/codeception/src/Codeception/PHPUnit/Listener.php(124): Symfony\Component\EventDispatcher\EventDispatcher->dispatch('test.after', Object(Codeception\Event\TestEvent))
#5 /home/server/yii/vendor/codeception/codeception/src/Codeception/PHPUnit/Listener.php(110): Codeception\PHPUnit\Listener->fire('test.after', Object(Codeception\Event\TestEvent))
#6 /home/server/yii/vendor/phpunit/phpunit/src/Framework/TestResult.php(401): Codeception\PHPUnit\Listener->endTest(Object(mobile\tests\CheckoutTest), 0.004040002822876)
#7 /home/server/yii/vendor/phpunit/phpunit/src/Framework/TestResult.php(876): PHPUnit_Framework_TestResult->endTest(Object(mobile\tests\CheckoutTest), 0.004040002822876)
#8 phar:///usr/local/bin/codecept/vendor/phpunit/phpunit/src/Framework/TestCase.php(888): PHPUnit_Framework_TestResult->run(Object(mobile\tests\CheckoutTest))
#9 /home/server/yii/vendor/phpunit/phpunit/src/Framework/TestSuite.php(753): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#10 /home/server/yii/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php(98): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#11 /home/server/yii/vendor/codeception/codeception/src/Codeception/SuiteManager.php(162): Codeception\PHPUnit\Runner->doEnhancedRun(Object(Codeception\Suite), Object(PHPUnit_Framework_TestResult), Array)
#12 phar:///usr/local/bin/codecept/src/Codeception/Codecept.php(209): Codeception\SuiteManager->run(Object(Codeception\PHPUnit\Runner), Object(PHPUnit_Framework_TestResult), Array)
#13 phar:///usr/local/bin/codecept/src/Codeception/Codecept.php(178): Codeception\Codecept->runSuite(Array, 'unit', NULL)
#14 phar:///usr/local/bin/codecept/src/Codeception/Command/Run.php(329): Codeception\Codecept->run('unit')
#15 phar:///usr/local/bin/codecept/src/Codeception/Command/Run.php(256): Codeception\Command\Run->runSuites(Array, Array)
#16 phar:///usr/local/bin/codecept/vendor/symfony/console/Command/Command.php(256): Codeception\Command\Run->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 phar:///usr/local/bin/codecept/vendor/symfony/console/Application.php(815): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 phar:///usr/local/bin/codecept/vendor/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(Codeception\Command\Run), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 phar:///usr/local/bin/codecept/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 phar:///usr/local/bin/codecept/src/Codeception/Application.php(103): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 phar:///usr/local/bin/codecept/codecept(36): Codeception\Application->run()
#22 /usr/local/bin/codecept(7): require_once('phar:///usr/loc...')
#23 {main}
  • Вопрос задан
  • 548 просмотров
Пригласить эксперта
Ответы на вопрос 1
kaily6
@kaily6
Backend Software Engineer at Live Typing
Попробуйте наследоваться не от \yii\codeception\TestCase, а от \Codeception\Test\Unit
вот так

class CheckoutTest extends \Codeception\Test\Unit
{
    public function testCartcheck()
    {
        $i = 80;
        expect('equal 80', $i)->equals(80);
    }
}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы