Db: invalid data source name while creating PDO connection

Hello!

I’m trying to run codeception tests via Windows command line (command codecept run), but every time take an error “Db: invalid data source name while creating PDO connection”.

I used instructions with commands like




composer global require codeception/codeception

composer require --dev yiisoft/yii2-codeception

codecept bootstrap --customize

codecept build



which generated all the files in /tests/.

Then I copied necessary models to /tests/_data with changed namespace, copied original DB and generate dump of that. What I have now:

_codeception.yml




...

modules:

    config:

        Db:

            dsn: 'mysql:host=localhost;dbname=fortime_test'

            user: 'root'

            password: ''

            dump: tests/_data/dump.sql



unit.suite.yml




class_name: UnitTester

modules:

    enabled:

        - Asserts

        - Db



tests/unit/config.php




<?php

return [

    'id' => 'app-console',

    'class' => 'yii\console\Application',

    'basePath' => \Yii::getAlias('@tests'),

    'runtimePath' => \Yii::getAlias('@tests/_output'),

    'bootstrap' => [],

    'components' => [

        'db' => [

            'class' => '\yii\db\Connection',

            'dsn' => 'mysql:host=localhost;dbname=fortime_test',

            'username' => 'root',

            'password' => '',

        ]

    ]

];



and one test-file in tests/unit.

But it still wrong!

And I tried to remove _config.php with DB-connection data, but command line don’t worried about that.

Maybe do you have some ideas?

If yes, thanks a lot!

Hi, I have exactly the same error with Db component. I’m using PostgreSQL so my config looks like:

acceptance.suite.yml


class_name: AcceptanceTester

modules:

    enabled:

        - WebDriver:

            url: localhost:8081

            browser: firefox

        - \Helper\Acceptance

        - Db:

            dsn: 'pgsql:host=localhost;port=5432;dbname=copied'

            user: 'postgres'

            password: '1234'

            dump: tests/_data/dump.sql

I tried to configure Yii2 module in codeception, but that end up with selenium(2.53.1) error:


[Facebook\WebDriver\Exception\UnknownServerException]

Unable to bind to locking port 7054 within 45000 ms

My Yii2 config:

acceptance.suite.yml


modules:

    enabled:

        - WebDriver:

            url: localhost:8081

            browser: firefox

        - \Helper\Acceptance

        - Yii2:

            part: [orm, fixtures] # allow to use AR methods

            cleanup: true # wrap test in transaction

            configFile: 'config/test.php'

test.php


<?php

// config/test.php

$config =  yii\helpers\ArrayHelper::merge(

    require(__DIR__ . '/web.php'),

    [

        'id' => 'app-tests',

        'components' => [

            'db' => [

                'dsn' => 'pgsql:host=localhost;port=5432;dbname=test',

            ]

        ]

    ]

);

return $config;

I can run tests only without Yii2 / Db modules. Hope someone will help us ;)

Solved.

For some reason I’ve created copy of codeception.yml, named it [color="#FF0000"]_[/color]codeception.yml and worked with it.