Codeception: How to fix undefinite index afterOpen? Index of what?

Created on 6 Jun 2018  路  10Comments  路  Source: Codeception/Codeception

What are you trying to achieve?

run test with latest version codeception with configure yii2-app-advanced for it

https://github.com/bscheshirwork/docker-yii2-app-advanced/blob/master/docker-codeception-run/docker-compose.yml

https://github.com/bscheshirwork/yii2-app-advanced/tree/merge-config-moving-to-separated-file

What do you get instead?

projects/docker-yii2-app-advanced/docker-codeception-run$ docker-compose run --rm codecept run -c ./common -vvv
Starting docker-codeception-run_db_1 ... done
Starting docker-codeception-run_browser_1 ... done
Starting docker-codeception-run_php_1     ... done
Starting docker-codeception-run_nginx_1   ... done
Codeception PHP Testing Framework v2.4.2
Powered by PHPUnit 7.1.5-22-g67289aa71 by Sebastian Bergmann and contributors.

Common\tests.unit Tests (3) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: Yii2
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- LoginFormTest: Login no user
  Destroying application
  Starting application
  [Fixtures] Loading fixtures
  [yii\db\Connection::open] 'Opening DB connection: mysql:host=db;dbname=yii2advanced'
  [Fixtures] Opened database connection: mysql:host=db;dbname=yii2advanced
E LoginFormTest: Login no user 
E LoginFormTest: Login no user (0.02s)
  [Transaction] Rolling back 0 transactions

In Event.php line 167:

  [yii\base\ErrorException (8)]  
  Undefined index: afterOpen     


Exception trace:
 Codeception\Module\Yii2->rollbackTransactions() at /var/www/html/vendor/codeception/base/src/Codeception/Module/Yii2.php:351
 Codeception\Module\Yii2->_after() at /var/www/html/vendor/codeception/base/src/Codeception/Subscriber/Module.php:66
 Codeception\Subscriber\Module->after() at /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php:212
 Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php:44
 Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at /var/www/html/vendor/codeception/phpunit-wrapper/src/Listener.php:133
 Codeception\PHPUnit\Listener->fire() at /var/www/html/vendor/codeception/phpunit-wrapper/src/Listener.php:119
 Codeception\PHPUnit\Listener->endTest() at /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:384
 PHPUnit\Framework\TestResult->endTest() at /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:842
 PHPUnit\Framework\TestResult->run() at /repo/vendor/phpunit/phpunit/src/Framework/TestCase.php:798
 common\tests\unit\models\LoginFormTest->run() at /var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php:776
 Codeception\Suite->run() at /var/www/html/vendor/codeception/phpunit-wrapper/src/Runner.php:114
 Codeception\PHPUnit\Runner->doEnhancedRun() at /var/www/html/vendor/codeception/base/src/Codeception/SuiteManager.php:157
 Codeception\SuiteManager->run() at /repo/src/Codeception/Codecept.php:189
 Codeception\Codecept->runSuite() at /repo/src/Codeception/Codecept.php:158
 Codeception\Codecept->run() at /repo/src/Codeception/Command/Run.php:466
 Codeception\Command\Run->runSuites() at /repo/src/Codeception/Command/Run.php:361
 Codeception\Command\Run->execute() at /repo/vendor/symfony/console/Command/Command.php:251
 Codeception\Command\Run->run() at /repo/vendor/symfony/console/Application.php:886
 Codeception\Application->doRunCommand() at /repo/vendor/symfony/console/Application.php:262
 Codeception\Application->doRun() at /repo/vendor/symfony/console/Application.php:145
 Codeception\Application->run() at /repo/src/Codeception/Application.php:108
 Codeception\Application->run() at /repo/codecept:42

Most helpful comment

I had the same problem, so started Codeception in debug mode with xdebug and discovered that the message had nothing to do with the actual error, because the error was in the fixtures; so loading fixtures with wrong fields leads to exception that is catched inside Codeception itself but is masked by other checks and the original exception message is lost.

Hope this helps.

All 10 comments

+1

I had the same problem, so started Codeception in debug mode with xdebug and discovered that the message had nothing to do with the actual error, because the error was in the fixtures; so loading fixtures with wrong fields leads to exception that is catched inside Codeception itself but is masked by other checks and the original exception message is lost.

Hope this helps.

@fabioaccetta thanks!
I try to trace it.

I'm not using fixtures. Actually my first day with yii2 and codeception.

same issue

In my case it happens when codeception try to handle db exception in Event.php

// wildcard event names $removed = false; foreach (self::$_eventWildcards[$name][$class] as $i => $event) { if ($event[0] === $handler) { unset(self::$_eventWildcards[$name][$class][$i]); $removed = true; } }
There is empty array in $_eventWildcards not afterOpen
And there is no check for that/ I am not sure it is Yii bug or codeception...

updated: I finally found that there are some problems in my Fixtures class or dataFile

@ratVien you tell about this?

    public static function on($class, $name, $handler, $data = null, $append = true)
    {
        $class = ltrim($class, '\\');

        if (strpos($class, '*') !== false || strpos($name, '*') !== false) {
            if ($append || empty(self::$_eventWildcards[$name][$class])) {
                self::$_eventWildcards[$name][$class][] = [$handler, $data];
            } else {
                array_unshift(self::$_eventWildcards[$name][$class], [$handler, $data]);
            }
            return;
        }

        if ($append || empty(self::$_events[$name][$class])) {
            self::$_events[$name][$class][] = [$handler, $data];
        } else {
            array_unshift(self::$_events[$name][$class], [$handler, $data]);
        }
    }

https://github.com/yiisoft/yii2/blob/ca3c8da503d9a152fc0d9ba7c2b51df5752a00fa/framework/base/Event.php#L103-L121

It fixed 10 days ago https://github.com/yiisoft/yii2/pull/16377
Will be work on 2.0.16

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gimler picture gimler  路  3Comments

simara-svatopluk picture simara-svatopluk  路  3Comments

rogoit picture rogoit  路  3Comments

sebastianneubert picture sebastianneubert  路  3Comments

sasha-x picture sasha-x  路  3Comments