Magento 2 - PHPUnit Integration Tests installs DB then fails with SQLSTATE[HY000] [2002] No such file or directory

I am trying to setup CircleCi with Magento 2.

The integration test DB is setup successfully. Setup and Update scripts run successfully. The setup process fails after the following console output:

    [SUCCESS]: Magento installation complete.
    [SUCCESS]: Magento Admin URI: /backend


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

As for the error, this suggests: Unable to connect to MySQL.

Any ideas?

Below I have included the full error. I have skipped the steps in between, but you get the picture.

    $#!/bin/bash -eo pipefail
    echo $PATH_TO_MAGENTO
    magento/vendor/bin/phpunit --configuration ${PATH_TO_MAGENTO}/phpunit.xml

    magento/dev/tests/integration

    Exception: Starting Magento installation:
    File permissions check...
    [Progress: 1 / 845]

    ...

    Post installation file permissions check...
    For security, remove write permissions from these directories: '/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/etc'
    [Progress: 844 / 845]
    Write installation date...
    [Progress: 845 / 845]
    [SUCCESS]: Magento installation complete.
    [SUCCESS]: Magento Admin URI: /backend


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


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


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


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

    setup:install [--backend-frontname BACKEND-FRONTNAME] [--amqp-host AMQP-HOST] [--amqp-port AMQP-PORT] [--amqp-user AMQP-USER] [--amqp-password AMQP-PASSWORD] [--amqp-virtualhost AMQP-VIRTUALHOST] [--amqp-ssl AMQP-SSL] [--key KEY] [--db-host DB-HOST] [--db-name DB-NAME] [--db-user DB-USER] [--db-engine DB-ENGINE] [--db-password DB-PASSWORD] [--db-prefix DB-PREFIX] [--db-model DB-MODEL] [--db-init-statements DB-INIT-STATEMENTS] [-s|--skip-db-validation] [--http-cache-hosts HTTP-CACHE-HOSTS] [--session-save SESSION-SAVE] [--session-save-redis-host SESSION-SAVE-REDIS-HOST] [--session-save-redis-port SESSION-SAVE-REDIS-PORT] [--session-save-redis-password SESSION-SAVE-REDIS-PASSWORD] [--session-save-redis-timeout SESSION-SAVE-REDIS-TIMEOUT] [--session-save-redis-persistent-id SESSION-SAVE-REDIS-PERSISTENT-ID] [--session-save-redis-db SESSION-SAVE-REDIS-DB] [--session-save-redis-compression-threshold SESSION-SAVE-REDIS-COMPRESSION-THRESHOLD] [--session-save-redis-compression-lib SESSION-SAVE-REDIS-COMPRESSION-LIB] [--session-save-redis-log-level SESSION-SAVE-REDIS-LOG-LEVEL] [--session-save-redis-max-concurrency SESSION-SAVE-REDIS-MAX-CONCURRENCY] [--session-save-redis-break-after-frontend SESSION-SAVE-REDIS-BREAK-AFTER-FRONTEND] [--session-save-redis-break-after-adminhtml SESSION-SAVE-REDIS-BREAK-AFTER-ADMINHTML] [--session-save-redis-first-lifetime SESSION-SAVE-REDIS-FIRST-LIFETIME] [--session-save-redis-bot-first-lifetime SESSION-SAVE-REDIS-BOT-FIRST-LIFETIME] [--session-save-redis-bot-lifetime SESSION-SAVE-REDIS-BOT-LIFETIME] [--session-save-redis-disable-locking SESSION-SAVE-REDIS-DISABLE-LOCKING] [--session-save-redis-min-lifetime SESSION-SAVE-REDIS-MIN-LIFETIME] [--session-save-redis-max-lifetime SESSION-SAVE-REDIS-MAX-LIFETIME] [--cache-backend CACHE-BACKEND] [--cache-backend-redis-server CACHE-BACKEND-REDIS-SERVER] [--cache-backend-redis-db CACHE-BACKEND-REDIS-DB] [--cache-backend-redis-port CACHE-BACKEND-REDIS-PORT] [--page-cache PAGE-CACHE] [--page-cache-redis-server PAGE-CACHE-REDIS-SERVER] [--page-cache-redis-db PAGE-CACHE-REDIS-DB] [--page-cache-redis-port PAGE-CACHE-REDIS-PORT] [--page-cache-redis-compress-data PAGE-CACHE-REDIS-COMPRESS-DATA] [--base-url BASE-URL] [--language LANGUAGE] [--timezone TIMEZONE] [--currency CURRENCY] [--use-rewrites USE-REWRITES] [--use-secure USE-SECURE] [--base-url-secure BASE-URL-SECURE] [--use-secure-admin USE-SECURE-ADMIN] [--admin-use-security-key ADMIN-USE-SECURITY-KEY] [--admin-user ADMIN-USER] [--admin-password ADMIN-PASSWORD] [--admin-email ADMIN-EMAIL] [--admin-firstname ADMIN-FIRSTNAME] [--admin-lastname ADMIN-LASTNAME] [--cleanup-database] [--sales-order-increment-prefix SALES-ORDER-INCREMENT-PREFIX] [--use-sample-data] [-i|--interactive] [--magento-init-params MAGENTO-INIT-PARAMS]
     in /home/circleci/project/magento/vendor/magento/framework/Shell.php:61
    Stack trace:
    #0 /home/circleci/project/magento/dev/tests/integration/framework/Magento/TestFramework/Application.php(466): Magento\Framework\Shell->execute('/usr/local/bin/...', Array)
    #1 /home/circleci/project/magento/dev/tests/integration/framework/bootstrap.php(77): Magento\TestFramework\Application->install(false)
    #2 /home/circleci/project/magento/vendor/phpunit/phpunit/src/Util/Fileloader.php(64): include_once('/home/circleci/...')
    #3 /home/circleci/project/magento/vendor/phpunit/phpunit/src/Util/Fileloader.php(48): PHPUnit\Util\Fileloader::load('/home/circleci/...')
    #4 /home/circleci/project/magento/vendor/phpunit/phpunit/src/TextUI/Command.php(991): PHPUnit\Util\Fileloader::checkAndLoad('/home/circleci/...')
    #5 /home/circleci/project/magento/vendor/phpunit/phpunit/src/TextUI/Command.php(788): PHPUnit\TextUI\Command->handleBootstrap('/home/circleci/...')
    #6 /home/circleci/project/magento/vendor/phpunit/phpunit/src/TextUI/Command.php(159): PHPUnit\TextUI\Command->handleArguments(Array)
    #7 /home/circleci/project/magento/vendor/phpunit/phpunit/src/TextUI/Command.php(148): PHPUnit\TextUI\Command->run(Array, true)
    #8 /home/circleci/project/magento/vendor/phpunit/phpunit/phpunit(53): PHPUnit\TextUI\Command::main()
    #9 {main}

    Next Magento\Framework\Exception\LocalizedException: Command returned non-zero exit code:
    `/usr/local/bin/php -f '/home/circleci/project/magento/bin/magento' setup:install -vvv --db-host='127.0.0.1' --db-user='root' --db-password='root' --db-name='magento' --backend-frontname='backend' --admin-user='user' --admin-password='password1' --admin-email='admin@example.com' --admin-firstname='firstname' --admin-lastname='lastname' --magento-init-params='MAGE_DIRS[etc][path]=/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/etc&MAGE_DIRS[var][path]=/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/var&MAGE_DIRS[media][path]=/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/pub/media&MAGE_DIRS[static][path]=/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/pub/static&MAGE_DIRS[view_preprocessed][path]=/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/var/view_preprocessed/pub/static&MAGE_DIRS[code][path]=/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/generated/code&MAGE_DIRS[cache][path]=/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/var/cache&MAGE_DIRS[log][path]=/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/var/log&MAGE_DIRS[session][path]=/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/var/session&MAGE_DIRS[tmp][path]=/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/var/tmp&MAGE_DIRS[upload][path]=/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/var/upload&MAGE_DIRS[pub][path]=/home/circleci/project/magento/dev/tests/integration/tmp/sandbox-0-09615633afe7a4592c902442673d028f/pub&MAGE_MODE=developer' 2>&1` in /home/circleci/project/magento/vendor/magento/framework/Shell.php:62
    Stack trace:
    #0 /home/circleci/project/magento/dev/tests/integration/framework/Magento/TestFramework/Application.php(466): Magento\Framework\Shell->execute('/usr/local/bin/...', Array)
    #1 /home/circleci/project/magento/dev/tests/integration/framework/bootstrap.php(77): Magento\TestFramework\Application->install(false)
    #2 /home/circleci/project/magento/vendor/phpunit/phpunit/src/Util/Fileloader.php(64): include_once('/home/circleci/...')
    #3 /home/circleci/project/magento/vendor/phpunit/phpunit/src/Util/Fileloader.php(48): PHPUnit\Util\Fileloader::load('/home/circleci/...')
    #4 /home/circleci/project/magento/vendor/phpunit/phpunit/src/TextUI/Command.php(991): PHPUnit\Util\Fileloader::checkAndLoad('/home/circleci/...')
    #5 /home/circleci/project/magento/vendor/phpunit/phpunit/src/TextUI/Command.php(788): PHPUnit\TextUI\Command->handleBootstrap('/home/circleci/...')
    #6 /home/circleci/project/magento/vendor/phpunit/phpunit/src/TextUI/Command.php(159): PHPUnit\TextUI\Command->handleArguments(Array)
    #7 /home/circleci/project/magento/vendor/phpunit/phpunit/src/TextUI/Command.php(148): PHPUnit\TextUI\Command->run(Array, true)
    #8 /home/circleci/project/magento/vendor/phpunit/phpunit/phpunit(53): PHPUnit\TextUI\Command::main()
    #9 {main}

    === Memory Usage System Stats ===
    Memory usage (OS):	31.41M (523.50% of 6.00M reported by PHP)
    Estimated memory leak:	25.41M (80.90% of used memory)

    Exited with code 1

Here is my config.yml

    version: 2
jobs:
  build:
    docker:
      # using custom image, see .circleci/images/primary/Dockerfile
      - image: circleci/php:7.0.30-apache-node
        environment:
          DB_USER: root
          DB_PASSWORD: root
          DB_NAME: m2_integration_tests
          DB_HOST: localhost
          DB_PORT: 3306
      - image: circleci/mysql:5.7-ram
        environment:
          MYSQL_USER: root
          MYSQL_DATABASE: m2_integration_tests
          MYSQL_ROOT_HOST: "%"
          MYSQL_ROOT_PASSWORD: root
    environment:
      TEST_RESULTS: /tmp/test-results
      PATH_TO_MAGENTO: magento/dev/tests/integration

    steps:
      - checkout
      - run: sudo apt-get install -y curl libpng-dev libxml2-dev zlib1g-dev libicu-dev g++ libmcrypt-dev libreadline-dev libxml2 libxml2-dev libxslt1-dev libfreetype6-dev libicu-dev libjpeg62-turbo-dev libmcrypt-dev libpng-dev libxslt1-dev sendmail-bin sendmail cron rsyslog git libgd-dev
      - run: sudo docker-php-ext-configure intl
      - run: sudo docker-php-ext-configure gd --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr
      - run: sudo docker-php-ext-install pdo_mysql gd intl bcmath soap mcrypt xsl mbstring json xml mysqli sockets zip
      - run: sudo apt install -y mysql-client
      - run: mkdir -p $TEST_RESULTS
      - run:
          name: update host file
          command: |
            echo 127.0.0.1 localhost | sudo tee -a /etc/hosts
            cat /etc/hosts
      - run:
          name: Install Composer
          command: |
            php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
            php -r "if (hash_file('SHA384', 'composer-setup.php') === trim(file_get_contents('https://composer.github.io/installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer invalid'; unlink('composer-setup.php'); } echo PHP_EOL;"
            php composer-setup.php
            php -r "unlink('composer-setup.php');"

      - run:
          name: Display PHP information
          command: |
            php -v
            php composer.phar --version
      - run:
          name: Install project dependencies
          command: |
              php composer.phar install
      - run:
          name: Run Unit tests
          command: |
              echo ${PATH_TO_MAGENTO}
              cd ${PATH_TO_MAGENTO}
              ../../../vendor/bin/phpunit --testsuite "All integration tests"
              # magento/vendor/bin/phpunit --configuration ${PATH_TO_MAGENTO}/phpunit.xml

(To get good answers here, please format your YAML with the code tool, so that it is all formatted. To do this, edit the post, select the YAML, click the code button, and save. For code formatting to work in Markdown, it needs to have a blank line before it, I think.)

Thanks Halfer

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.