Skip to content

Latest commit

 

History

History
115 lines (67 loc) · 2.26 KB

File metadata and controls

115 lines (67 loc) · 2.26 KB
layout doc
title Codeception - Documentation

Dbh Module

This module replaces Db module for functional and unit testing, and requires PDO instance to be set. Be default it will cover all database queries into transaction and rollback it afterwards. The database should support nested transactions, in order to make cleanup work as expected.

Pass PDO instance to this module from within your bootstrap file.

In _bootstrap.php:

{% highlight php %}

{% endhighlight %}

This will make all queries in this connection run withing transaction and rolled back afterwards.

Note, that you can't use this module with MySQL. Or perhaps you don't use transactions in your project, then it's ok. Otherwise consider using ORMs like Doctrine, that emulate nested transactions, or switch to Db module.

Configuration

  • cleanup: true - enable cleanups by covering all queries inside transaction.

Actions

dontSeeInDatabase

Effect is opposite to ->seeInDatabase

Checks if there is no record with such column values in database. Provide table name and column values.

Example:

{% highlight php %}

seeInDatabase('users', array('name' => 'Davert', 'email' => 'davert@mail.com')); {% endhighlight %} Will generate: {% highlight yaml %} sql SELECT COUNT(*) FROM `users` WHERE `name` = 'Davert' AND `email` = 'davert@mail.com' {% endhighlight %} Fails if such user was found. * param $table * param array $criteria #### grabFromDatabase Fetches a single column value from a database. Provide table name, desired column and criteria. Example: {% highlight php %} grabFromDatabase('users', 'email', array('name' => 'Davert')); {% endhighlight %} * version 1.1 * param $table * param $column * param array $criteria * return mixed #### seeInDatabase Checks if a row with given column values exists. Provide table name and column values. Example: {% highlight php %} seeInDatabase('users', array('name' => 'Davert', 'email' => 'davert@mail.com')); {% endhighlight %} Will generate: {% highlight yaml %} sql SELECT COUNT(*) FROM `users` WHERE `name` = 'Davert' AND `email` = 'davert@mail.com' {% endhighlight %} Fails if no such user found. * param $table * param array $criteria