|
26 | 26 | * This module also provides actions to perform checks in a database, e.g. [seeInDatabase()](https://codeception.com/docs/modules/Db#seeInDatabase)
|
27 | 27 | *
|
28 | 28 | * In order to have your database populated with data you need a raw SQL dump.
|
29 |
| - * Simply put the dump in the `tests/_data` directory (by default) and specify the path in the config. |
| 29 | + * Simply put the dump in the `tests/Support/Data` directory (by default) and specify the path in the config. |
30 | 30 | * The next time after the database is cleared, all your data will be restored from the dump.
|
31 | 31 | * Don't forget to include `CREATE TABLE` statements in the dump.
|
32 | 32 | *
|
|
41 | 41 | * * MS SQL
|
42 | 42 | * * Oracle
|
43 | 43 | *
|
44 |
| - * Connection is done by database Drivers, which are stored in the `Codeception\Lib\Driver` namespace. |
45 |
| - * [Check out the drivers](https://github.com/Codeception/Codeception/tree/2.4/src/Codeception/Lib/Driver) |
46 |
| - * if you run into problems loading dumps and cleaning databases. |
| 44 | + * Connection is done by database drivers, which are stored in the `Codeception\Lib\Driver` namespace. |
| 45 | + * Check out the drivers if you run into problems loading dumps and cleaning databases. |
47 | 46 | *
|
48 |
| - * ## Config |
49 |
| - * |
50 |
| - * * dsn *required* - PDO DSN |
51 |
| - * * user *required* - username to access database |
52 |
| - * * password *required* - password |
53 |
| - * * dump - path to database dump |
54 |
| - * * populate: false - whether the the dump should be loaded before the test suite is started |
55 |
| - * * cleanup: false - whether the dump should be reloaded before each test |
56 |
| - * * reconnect: false - whether the module should reconnect to the database before each test |
57 |
| - * * waitlock: 0 - wait lock (in seconds) that the database session should use for DDL statements |
58 |
| - * * ssl_key - path to the SSL key (MySQL specific, @see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-key) |
59 |
| - * * ssl_cert - path to the SSL certificate (MySQL specific, @see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-ssl-cert) |
60 |
| - * * ssl_ca - path to the SSL certificate authority (MySQL specific, @see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-ssl-ca) |
61 |
| - * * ssl_verify_server_cert - disables certificate CN verification (MySQL specific, @see https://php.net/manual/de/ref.pdo-mysql.php) |
62 |
| - * * ssl_cipher - list of one or more permissible ciphers to use for SSL encryption (MySQL specific, @see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-cipher) |
63 |
| - * * databases - include more database configs and switch between them in tests. |
64 |
| - * * initial_queries - list of queries to be executed right after connection to the database has been initiated, i.e. creating the database if it does not exist or preparing the database collation |
65 |
| - * * skip_cleanup_if_failed - Do not perform the cleanup if the tests failed. If this is used, manual cleanup might be required when re-running |
66 |
| - * ## Example |
67 |
| - * |
68 |
| - * modules: |
69 |
| - * enabled: |
70 |
| - * - Db: |
71 |
| - * dsn: 'mysql:host=localhost;dbname=testdb' |
72 |
| - * user: 'root' |
73 |
| - * password: '' |
74 |
| - * dump: 'tests/_data/dump.sql' |
75 |
| - * populate: true |
76 |
| - * cleanup: true |
77 |
| - * reconnect: true |
78 |
| - * waitlock: 10 |
79 |
| - * skip_cleanup_if_failed: true |
80 |
| - * ssl_key: '/path/to/client-key.pem' |
81 |
| - * ssl_cert: '/path/to/client-cert.pem' |
82 |
| - * ssl_ca: '/path/to/ca-cert.pem' |
83 |
| - * ssl_verify_server_cert: false |
84 |
| - * ssl_cipher: 'AES256-SHA' |
85 |
| - * initial_queries: |
86 |
| - * - 'CREATE DATABASE IF NOT EXISTS temp_db;' |
87 |
| - * - 'USE temp_db;' |
88 |
| - * - 'SET NAMES utf8;' |
| 47 | + * ## Example `Functional.suite.yml` |
| 48 | + * ```yaml |
| 49 | + * modules: |
| 50 | + * enabled: |
| 51 | + * - Db: |
| 52 | + * dsn: 'mysql:host=localhost;dbname=testdb' |
| 53 | + * user: 'root' |
| 54 | + * password: '' |
| 55 | + * dump: 'tests/Support/Data/dump.sql' |
| 56 | + * populate: true # whether the dump should be loaded before the test suite is started |
| 57 | + * cleanup: true # whether the dump should be reloaded before each test |
| 58 | + * reconnect: true # whether the module should reconnect to the database before each test |
| 59 | + * waitlock: 10 # wait lock (in seconds) that the database session should use for DDL statements |
| 60 | + * databases: # include more database configs and switch between them in tests. |
| 61 | + * skip_cleanup_if_failed: true # Do not perform the cleanup if the tests failed. If this is used, manual cleanup might be required when re-running |
| 62 | + * ssl_key: '/path/to/client-key.pem' # path to the SSL key (MySQL specific, see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-key) |
| 63 | + * ssl_cert: '/path/to/client-cert.pem' # path to the SSL certificate (MySQL specific, see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-ssl-cert) |
| 64 | + * ssl_ca: '/path/to/ca-cert.pem' # path to the SSL certificate authority (MySQL specific, see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-ssl-ca) |
| 65 | + * ssl_verify_server_cert: false # disables certificate CN verification (MySQL specific, see https://php.net/manual/de/ref.pdo-mysql.php) |
| 66 | + * ssl_cipher: 'AES256-SHA' # list of one or more permissible ciphers to use for SSL encryption (MySQL specific, see https://php.net/manual/de/ref.pdo-mysql.php#pdo.constants.mysql-attr-cipher) |
| 67 | + * initial_queries: # list of queries to be executed right after connection to the database has been initiated, i.e. creating the database if it does not exist or preparing the database collation |
| 68 | + * - 'CREATE DATABASE IF NOT EXISTS temp_db;' |
| 69 | + * - 'USE temp_db;' |
| 70 | + * - 'SET NAMES utf8;' |
| 71 | + * ``` |
89 | 72 | *
|
90 | 73 | * ## Example with multi-dumps
|
91 |
| - * modules: |
92 |
| - * enabled: |
93 |
| - * - Db: |
94 |
| - * dsn: 'mysql:host=localhost;dbname=testdb' |
95 |
| - * user: 'root' |
96 |
| - * password: '' |
97 |
| - * dump: |
98 |
| - * - 'tests/_data/dump.sql' |
99 |
| - * - 'tests/_data/dump-2.sql' |
| 74 | + * ```yaml |
| 75 | + * modules: |
| 76 | + * enabled: |
| 77 | + * - Db: |
| 78 | + * dsn: 'mysql:host=localhost;dbname=testdb' |
| 79 | + * user: 'root' |
| 80 | + * password: '' |
| 81 | + * dump: |
| 82 | + * - 'tests/Support/Data/dump.sql' |
| 83 | + * - 'tests/Support/Data/dump-2.sql' |
| 84 | + * ``` |
100 | 85 | *
|
101 | 86 | * ## Example with multi-databases
|
102 |
| - * |
103 |
| - * modules: |
104 |
| - * enabled: |
105 |
| - * - Db: |
106 |
| - * dsn: 'mysql:host=localhost;dbname=testdb' |
107 |
| - * user: 'root' |
108 |
| - * password: '' |
109 |
| - * databases: |
| 87 | + * ```yaml |
| 88 | + * modules: |
| 89 | + * enabled: |
| 90 | + * - Db: |
| 91 | + * dsn: 'mysql:host=localhost;dbname=testdb' |
| 92 | + * user: 'root' |
| 93 | + * password: '' |
| 94 | + * databases: |
110 | 95 | * db2:
|
111 |
| - * dsn: 'mysql:host=localhost;dbname=testdb2' |
112 |
| - * user: 'userdb2' |
113 |
| - * password: '' |
114 |
| - * |
115 |
| - * ## Example with Sqlite |
| 96 | + * dsn: 'mysql:host=localhost;dbname=testdb2' |
| 97 | + * user: 'userdb2' |
| 98 | + * password: '' |
| 99 | + * ``` |
116 | 100 | *
|
117 |
| - * modules: |
118 |
| - * enabled: |
119 |
| - * - Db: |
120 |
| - * dsn: 'sqlite:relative/path/to/sqlite-database.db' |
121 |
| - * user: '' |
122 |
| - * password: '' |
| 101 | + * ## Example with SQLite |
| 102 | + * ```yaml |
| 103 | + * modules: |
| 104 | + * enabled: |
| 105 | + * - Db: |
| 106 | + * dsn: 'sqlite:relative/path/to/sqlite-database.db' |
| 107 | + * user: '' |
| 108 | + * password: '' |
| 109 | + * ``` |
123 | 110 | *
|
124 | 111 | * ## SQL data dump
|
125 | 112 | *
|
|
134 | 121 | *
|
135 | 122 | * ```yaml
|
136 | 123 | * modules:
|
137 |
| - * enabled: |
138 |
| - * - Db: |
139 |
| - * dsn: 'mysql:host=localhost;dbname=testdb' |
140 |
| - * user: 'root' |
141 |
| - * password: '' |
142 |
| - * dump: 'tests/_data/dump.sql' |
143 |
| - * populate: true # run populator before all tests |
144 |
| - * cleanup: true # run populator before each test |
145 |
| - * populator: 'mysql -u $user -h $host $dbname < $dump' |
| 124 | + * enabled: |
| 125 | + * - Db: |
| 126 | + * dsn: 'mysql:host=localhost;dbname=testdb' |
| 127 | + * user: 'root' |
| 128 | + * password: '' |
| 129 | + * dump: 'tests/Support/Data/dump.sql' |
| 130 | + * populate: true # run populator before all tests |
| 131 | + * cleanup: true # run populator before each test |
| 132 | + * populator: 'mysql -u $user -h $host $dbname < $dump' |
146 | 133 | * ```
|
147 | 134 | *
|
148 |
| - * For PostgreSQL (using pg_restore) |
| 135 | + * For PostgreSQL (using `pg_restore`) |
149 | 136 | *
|
150 |
| - * ``` |
| 137 | + * ```yaml |
151 | 138 | * modules:
|
152 |
| - * enabled: |
153 |
| - * - Db: |
154 |
| - * dsn: 'pgsql:host=localhost;dbname=testdb' |
155 |
| - * user: 'root' |
156 |
| - * password: '' |
157 |
| - * dump: 'tests/_data/db_backup.dump' |
158 |
| - * populate: true # run populator before all tests |
159 |
| - * cleanup: true # run populator before each test |
160 |
| - * populator: 'pg_restore -u $user -h $host -D $dbname < $dump' |
| 139 | + * enabled: |
| 140 | + * - Db: |
| 141 | + * dsn: 'pgsql:host=localhost;dbname=testdb' |
| 142 | + * user: 'root' |
| 143 | + * password: '' |
| 144 | + * dump: 'tests/Support/Data/db_backup.dump' |
| 145 | + * populate: true # run populator before all tests |
| 146 | + * cleanup: true # run populator before each test |
| 147 | + * populator: 'pg_restore -u $user -h $host -D $dbname < $dump' |
161 | 148 | * ```
|
162 | 149 | *
|
163 | 150 | * Variable names are being taken from config and DSN which has a `keyword=value` format, so you should expect to have a variable named as the
|
|
0 commit comments