Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codeception Db Module deleting my DATABASE! #574

Closed
gusdecool opened this issue Sep 25, 2013 · 8 comments

Comments

Projects
None yet
6 participants
@gusdecool
Copy link

commented Sep 25, 2013

I user Codeception version 1.6.7

Following with this tutorial here http://codeception.com/docs/modules/Db
I tried this Db config:

paths:
    tests: tests
    log: tests/_log
    data: tests/_data
    helpers: tests/_helpers
settings:
    bootstrap: _bootstrap.php
    suite_class: \PHPUnit_Framework_TestSuite
    colors: true
    memory_limit: 1024M
    log: true
modules:
    enabled: [Db]
    config:
      Db:
        dsn: 'mysql:host=localhost;dbname=test_codeception'
        user: 'gusdecool'
        password: 'gusdecool'
        dump: 'tests/_data/dump.sql'
        populate: true
        cleanup: false

And this is the code for my AcceptanceTesting

<?php
$user = 'gusdecool';
$pass = 'gusdecool';

/** @var $scenario \Codeception\Scenario */
$I = new WebGuy($scenario);
$I->wantTo('Do successful login');
$I->amOnPage('/index.php');
$I->fillField('user', $user);
$I->fillField('pass', $pass);
$I->click('input[type="submit"]');
$I->see('Hello, '.$user);
$I->amGoingTo('Testing check database');
$I->seeInDatabase('user', array('name'=>'gusdecool', 'pass'=>'123456'));

And then everytime i use run command, my actual database table is deleted!!!
and no database is dumped in tests/_data/dump.sql

Why this happening?

@DavertMik

This comment has been minimized.

Copy link
Member

commented Sep 25, 2013

Sorry, but I think you misread documentation.

populate: true means - to use dump you provided to load data before the test.
cleanup: false means to not cleanup database between tests.

You should create a test dump yourself (via mysqldump or phpmyadmin) and put it into tests/_data/dump.sql. It will be used by Db module to create database for tests.

Just to be clear: Db module does not create dumps itself. It uses the dump you created to load data before tests.

@DavertMik DavertMik closed this Sep 25, 2013

@gusdecool

This comment has been minimized.

Copy link
Author

commented Sep 25, 2013

Okay, that's mean in the step should be: dump the live database, put it into dump.sql then use the configuration as setting for creating new table?

If I'm right, i think you should change config name from dumpto source. It feel misleading for me.

@gustavovaldezsan

This comment has been minimized.

Copy link

commented Jan 7, 2014

I have the same feelings, and i'm here because i was mislead the same way DB Dump, sounds like a place where the DB will be dumped. +1 On the rename request.

@mipon

This comment has been minimized.

Copy link

commented Mar 16, 2015

I had to spend a few hours trying to find why the database is not restored in my acceptance tests because I expected the database data are automatically dumped when codecept run is performed. It would be useful if there was an option to allow it.

@DavertMik

This comment has been minimized.

Copy link
Member

commented Mar 16, 2015

@mipon there are much better tools to create database dumps. Codeception is a testing framework not a database dumper. So we recommend to dump data on your own. You can use mysqldump command, as well as mysql runner or whatever you like. It is pretty hard to implement some universal tool for database dumping.

@mipon

This comment has been minimized.

Copy link

commented Mar 16, 2015

@DavertMik I see. Thanks for the advice.

@Antnee

This comment has been minimized.

Copy link

commented Mar 31, 2015

We've just come across a similar problem. We have some tests that are running on a new table. We put the CREATE TABLE query in our dump and it is created as expected. However, when the process is finished the only table that exists is the one that was created in the tests. Everything else is gone, including the ones created previously. I'd have expected that it only cleans up what it created, not everything but what it created. It seems backwards to me and has broken other tests that didn't create tables because they were already in place. We're using populate: true and cleanup: true. I don't understand the benefits of dropping every single table except the one that was being tested

@GustavoDarriens

This comment has been minimized.

Copy link

commented Aug 13, 2015

@gustavovaldezsan And here I came to see why cleanup didn't restore the database from dump after the last test was run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.