S
S
ShishMish2020-03-17 10:10:09
PHP
ShishMish, 2020-03-17 10:10:09

How to properly use getModule in Codeception?

In the helper class, in the function of creating a new user, I want to use the methods of the installed "Db" module:

public function createUser()
    {
        // Добавляем клиента
        /**
         * @var $dbm Db
         */
        $dbm = $this->getModule('Db');
        $dbm->_getDbh();
        $dbm->haveInDatabase('site_users', [
            'name' => $this->customerName,
            'solution' => $this->solution,
            'locale' => 'en',
            'active' => '1',
        ]);

When running a test in _before which this function is called, I get an error:
[Error] Call to a member function hasModule() on null  

/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Module.php:312
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Module.php:339
/home/shishmish/Work/gc/tests/_support/Helper/Universal.php:64
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Step.php:266
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Scenario.php:76
/home/shishmish/Work/gc/tests/_support/_generated/ApiTesterActions.php:4479
/home/shishmish/Work/gc/tests/api/TokenCest.php:23
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Lib/Di.php:127
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Test/Cest.php:138
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Test/Cest.php:97
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Test/Cest.php:80
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Test/Test.php:88
/home/shishmish/Work/gc/vendor/phpunit/phpunit/src/Framework/TestSuite.php:755
/home/shishmish/Work/gc/vendor/codeception/phpunit-wrapper/src/Runner.php:110
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/SuiteManager.php:161
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Codecept.php:196
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Codecept.php:163
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Command/Run.php:391
/home/shishmish/Work/gc/vendor/symfony/console/Command/Command.php:255
/home/shishmish/Work/gc/vendor/symfony/console/Application.php:987
/home/shishmish/Work/gc/vendor/symfony/console/Application.php:255
/home/shishmish/Work/gc/vendor/symfony/console/Application.php:148
/home/shishmish/Work/gc/vendor/codeception/codeception/src/Codeception/Application.php:117
/home/shishmish/Work/gc/vendor/codeception/codeception/app.php:46
/home/shishmish/Work/gc/vendor/codeception/codeception/app.php:47
/home/shishmish/Work/gc/vendor/codeception/codeception/codecept:7


What am I doing wrong? What is the correct way to use getModule?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
andead, 2020-06-23
@andead

$dbh = $this->getModule('Db')->_getDbh();
$dbh->haveInDatabase(...);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question