Codeception: Db: could not find mysql driver while creating PDO connection

Created on 12 Oct 2016  路  1Comment  路  Source: Codeception/Codeception

What are you trying to achieve?

I want to connect to the database.

The whole environment is setup with docker. For codeception I am using this docker container

What do you get instead?

Provide console output if related. Use -vvv mode for more details.

Codeception PHP Testing Framework v2.2.5
Powered by PHPUnit 5.6.1 by Sebastian Bergmann and contributors.


  [Codeception\Exception\ModuleException]
  Db: could not find mysql driver while creating PDO connection


Exception trace:
 () at /repo/src/Codeception/Module/Db.php:219
 Codeception\Module\Db->connect() at /repo/src/Codeception/Module/Db.php:174
 Codeception\Module\Db->_initialize() at /repo/src/Codeception/SuiteManager.php:81
 Codeception\SuiteManager->initialize() at /repo/src/Codeception/Codecept.php:207
 Codeception\Codecept->runSuite() at /repo/src/Codeception/Codecept.php:178
 Codeception\Codecept->run() at /repo/src/Codeception/Command/Run.php:329
 Codeception\Command\Run->runSuites() at /repo/src/Codeception/Command/Run.php:256
 Codeception\Command\Run->execute() at /repo/vendor/symfony/console/Command/Command.php:256
 Symfony\Component\Console\Command\Command->run() at /repo/vendor/symfony/console/Application.php:820
 Symfony\Component\Console\Application->doRunCommand() at /repo/vendor/symfony/console/Application.php:187
 Symfony\Component\Console\Application->doRun() at /repo/vendor/symfony/console/Application.php:118
 Symfony\Component\Console\Application->run() at /repo/src/Codeception/Application.php:103
 Codeception\Application->run() at /repo/codecept:33

Provide test source code if related

<?php


class AuthCest
{
    /** @var string */
    private $email;

    public function _before(AcceptanceTester $I)
    {
        $this->email = '[email protected]';
    }

    public function _after(AcceptanceTester $I)
    {
    }

    public function checkRegister(AcceptanceTester $I)
    {
        $I->am('user');
        $I->wantTo('register to website');
        $I->amOnPage('/en/login');
        $I->fillField('#register-name','John Doe');
        $I->fillField('#register-email',$this->email);
        $I->click('Register Now');
        $userId = $I->grabFromDatabase('users', 'id', array('email' => $this->email));
    }
}

Details

  • Codeception version: 2.2.5
  • PHP Version: 7.0
  • Operating System: Docker container
  • Suite configuration:

codeception.yml

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
extensions:
    enabled:
        - Codeception\Extension\RunFailed
modules:
    config:
        Db:
            dsn: 'mysql:host=mysql;dbname=eventerza'
            user: 'root'
            password: 'pw'

tests/acceptance.suite.yml

# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.

class_name: AcceptanceTester
modules:
    enabled:
        - Db
        - PhpBrowser:
            url: http://web/
        - \Helper\Acceptance

Most helpful comment

After some more testings i found the solution. It is not a codeception bug, it's a bug in the codeception docker container. There you need to add the pdo_mysql php extension.

Dockerfile

FROM codeception/codeception

RUN apt-get update && \
    rm -rf /var/lib/apt/lists/*

RUN docker-php-ext-install \
    pdo_mysql

>All comments

After some more testings i found the solution. It is not a codeception bug, it's a bug in the codeception docker container. There you need to add the pdo_mysql php extension.

Dockerfile

FROM codeception/codeception

RUN apt-get update && \
    rm -rf /var/lib/apt/lists/*

RUN docker-php-ext-install \
    pdo_mysql

Was this page helpful?
0 / 5 - 0 ratings