I have been writing some unit tests with Codeception and my database has been getting over run with the test data. While reading the documentation I found it says:
Database will be cleaned and populated after each test
Does anybody know if there is anything in the yaml file or maybe something I need to put in the tear down method?
Here is my test:
use Codeception\Util\Stub;
class peopleAdminTest extends \Codeception\TestCase\Test
{
/**
* @var \CodeGuy
*/
protected $codeGuy;
/**
* @var the model object
*/
private $_model;
/**
* @var some mock data
*/
private $_data = array( "people" => array( "title" => "Unit Test Data" ) );
protected function _before()
{
$this->_model = new People_model();
}
public function test_instantiation()
{
$this->assertInstanceOf( 'people_model', $this->_model );
}
public function test_save()
{
$this->_model->save( $this->_data[ 'people' ] );
$this->codeGuy->seeInDatabase( 'pegisis_people', array( 'title' => 'Unit Test Data' ) );
}
}
Did you add populate: true and cleanup: true in unit.suite.yml?
Check vendor/codeception/src/Codeception/Module/Db.php. _after() or the teardown method in codeception does not cleanup the Db. The cleanup is done in _before() and then the sql is executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With