2

I'm trying to run integration tests on our CI server using a docker container. Now the documentation states that I only need to have a test-database (called magento_integration_tests), so I created that one.

But when running my integration test suite, I got the following error:

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

I fixed this by editing dev/tests/integration/etc/install-config-mysql.php and changing db-host from localhost to 127.0.0.1, but now the error got thrown again, only after a successful installation:

...
Write installation date...
[Progress: 529 / 529]
[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /backend

[Zend_Db_Adapter_Exception]
SQLSTATE[HY000] [2002] No such file or directory

I thought this error would have the same cause (with the localhost/127.0.0.1-issue described above), so I looked into the code where the exception was thrown (vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php:148) and started var_dumping the configuration to see what was being used:

array(13) {
  'host' =>
  string(9) "localhost"
  'dbname' =>
  string(13) "[customer]-magento2"
  'username' =>
  ...

What's this? Apparently, at this point in the installation, the configuration of my shop is used to determine some information. But why? Could it be to copy some configuration settings from my actual webshop? I can only speculate for the reasons behind this.

Can anyone explain to me what's going on here? The documentation never mentions anything about the need for a production database for running integration tests. But in this setup it looks like it does!

Full stack trace:

Exception trace:
 () at /app/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php:148
 Zend_Db_Adapter_Pdo_Abstract->_connect() at /app/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Mysql.php:111
 Zend_Db_Adapter_Pdo_Mysql->_connect() at /app/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:398
 Magento\Framework\DB\Adapter\Pdo\Mysql->_connect() at /app/vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php:460
 Zend_Db_Adapter_Abstract->query() at /app/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php:242
 Zend_Db_Adapter_Pdo_Abstract->query() at /app/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:517
 Magento\Framework\DB\Adapter\Pdo\Mysql->_query() at /app/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:580
 Magento\Framework\DB\Adapter\Pdo\Mysql->query() at /app/vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php:737
 Zend_Db_Adapter_Abstract->fetchAll() at /app/vendor/magento/module-store/Model/ResourceModel/Store.php:173
 Magento\Store\Model\ResourceModel\Store->readAllStores() at /app/generated/code/Magento/Store/Model/ResourceModel/Store/Interceptor.php:37
 Magento\Store\Model\ResourceModel\Store\Interceptor->readAllStores() at /app/vendor/magento/module-store/Model/Config/Processor/Fallback.php:89
 Magento\Store\Model\Config\Processor\Fallback->process() at /app/vendor/magento/module-config/App/Config/Type/System/Reader.php:60
 Magento\Config\App\Config\Type\System\Reader->read() at /app/generated/code/Magento/Config/App/Config/Type/System/Reader/Proxy.php:95
 Magento\Config\App\Config\Type\System\Reader\Proxy->read() at /app/vendor/magento/module-config/App/Config/Type/System.php:292
 Magento\Config\App\Config\Type\System->readData() at /app/vendor/magento/module-config/App/Config/Type/System.php:219
 Magento\Config\App\Config\Type\System->loadScopeData() at /app/vendor/magento/module-config/App/Config/Type/System.php:158
 Magento\Config\App\Config\Type\System->get() at /app/vendor/magento/framework/App/Config.php:131
 Magento\Framework\App\Config->get() at /app/vendor/magento/framework/App/Config.php:80
 Magento\Framework\App\Config->getValue() at /app/vendor/magento/module-developer/Model/Logger/Handler/Debug.php:63
 Magento\Developer\Model\Logger\Handler\Debug->isHandling() at /app/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php:29
 Monolog\Handler\AbstractProcessingHandler->handle() at /app/vendor/monolog/monolog/src/Monolog/Logger.php:337
 Monolog\Logger->addRecord() at /app/vendor/magento/framework/Logger/Monolog.php:48
 Magento\Framework\Logger\Monolog->addRecord() at /app/vendor/monolog/monolog/src/Monolog/Logger.php:616
 Monolog\Logger->error() at /app/vendor/magento/module-deploy/Console/Command/App/ConfigImport/Processor.php:151
 Magento\Deploy\Console\Command\App\ConfigImport\Processor->execute() at /app/vendor/magento/module-deploy/Console/Command/App/ConfigImportCommand.php:63
 Magento\Deploy\Console\Command\App\ConfigImportCommand->execute() at /app/vendor/symfony/console/Command/Command.php:242
 Symfony\Component\Console\Command\Command->run() at /app/setup/src/Magento/Setup/Console/Command/InstallCommand.php:151
 Magento\Setup\Console\Command\InstallCommand->execute() at /app/vendor/symfony/console/Command/Command.php:242
 Symfony\Component\Console\Command\Command->run() at /app/vendor/symfony/console/Application.php:842
 Symfony\Component\Console\Application->doRunCommand() at /app/vendor/symfony/console/Application.php:193
 Symfony\Component\Console\Application->doRun() at /app/vendor/magento/framework/Console/Cli.php:104
 Magento\Framework\Console\Cli->doRun() at /app/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at /app/bin/magento:23
1

Magento integration tests framework requires an installed Magento instance to run a test suite. I will try to explain how it works in general:

  1. On the initialization step dev/tests/integration/framework/bootstrap.php reads configuration from dev/tests/integration/phpunit.xml.
  2. bootsrap.php initializes instance of \Magento\TestFramework\Application with TESTS_GLOBAL_CONFIG_DIR (contains the path to a "real" application etc folder, NOT test suite) from phpunit.xml.
  3. If a test instance is not installed, then bootstrap.php calls install() method to install it.

    3.1. Application copies configuration files from "real" instance (that's why it needs TESTS_GLOBAL_CONFIG_DIR config option).

    3.2 Creates dump db from the "real" db (and again it uses configuration path from TESTS_GLOBAL_CONFIG_DIR) - that's why you see some data from your real database.

  4. Runs test suite.

To solve your issue, you need to re-define TESTS_GLOBAL_CONFIG_DIR value (by default it ../../../app/etc, that's why test framework uses the same configuration as defined in the root application folder) in dev/tests/integration/phpunit.xml.dist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.