0

I noticed a strage behaviour in codeception: if I rely only on codeception.yml with:

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    helpers: tests/_support
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
modules:
    config:
        Db:
            dsn: 'mysql:host=localhost;dbname=test'
            user: 'test'
            password: 'test'
            dump: tests/_data/dump.sql

run:

php artisan migrate --package=cartalyst/sentry --env="testing" php artisan migrate --seed --env="testing"

I've got this error

[PDOException]
SQLSTATE[42000] [1044] Access denied for user ''@'localhost' to database 'f orge'

if I put a file database.php in app/config/testing with

return array(

    'default' => 'mysql',

        'connections' => array(

        'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'lama-test',
            'username'  => 'lama-test',
            'password'  => 'lama-test',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        )

    ),

all it's ok.

I'm new at codeception so I'm wondering what's the matter and if I make something wrong.

2
  • you are setting the environment to "testing" when you run the migration - so you need the corresponding database configuration for testing. You seem to have answered your own question? Commented Jul 24, 2014 at 10:15
  • I've read the book laravel-testing-decoded and it states to populate the testing db you should run php artisan migrate --seed --env="testing" but I wait for a call to codeception.yml not to database.php Commented Jul 24, 2014 at 10:18

1 Answer 1

1

So there are two aspects to database access:

  1. From your application
  2. From codeception directly

From your application:

When running tests, your application needs to access your database as part of your code. i.e. when you search for the current user, or add a new blog post etc. This database access will occur through Laravel in "testing" mode - so it is good practice to define a "testing" database (which you have done).

From codeception directly:

When running tests, it is important that databases are the same before/after each test. That way a test does not rely on the output of a previous test etc. Codeception will use the database access defined in the yaml file to directly access the database, and 'refresh' it with your tests/_data/dump.sql file in between each test.

Codeception is not using the 'direct' database access during the actual test - just before/after.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for teh reply.So you are saying is the waited behaviour, arent you ?
Yes - it is the correct behaviour, and just how codeception and the process works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.