1 | <?php |
||
31 | abstract class TestCase extends BaseTestCase |
||
32 | { |
||
33 | /** |
||
34 | * DSN used for the DB backend. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $dsn; |
||
39 | |||
40 | /** |
||
41 | * Name of the DB, extracted from DSN. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $db; |
||
46 | |||
47 | /** |
||
48 | * Database handler -- to not be constructed twice for one test. |
||
49 | * |
||
50 | * @internal |
||
51 | * @var \eZ\Publish\Core\Persistence\Database\DatabaseHandler |
||
52 | */ |
||
53 | protected $handler; |
||
54 | |||
55 | /** |
||
56 | * Doctrine Database connection -- to not be constructed twice for one test. |
||
57 | * |
||
58 | * @internal |
||
59 | * @var \Doctrine\DBAL\Connection |
||
60 | */ |
||
61 | protected $connection; |
||
62 | |||
63 | /** @var \eZ\Publish\Core\Persistence\Legacy\SharedGateway\Gateway */ |
||
64 | private $sharedGateway; |
||
65 | |||
66 | /** |
||
67 | * Get data source name. |
||
68 | * |
||
69 | * The database connection string is read from an optional environment |
||
70 | * variable "DATABASE" and defaults to an in-memory SQLite database. |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | protected function getDsn() |
||
86 | |||
87 | /** |
||
88 | * Get a eZ Doctrine database connection handler. |
||
89 | * |
||
90 | * Get a ConnectionHandler, which can be used to interact with the configured |
||
91 | * database. The database connection string is read from an optional |
||
92 | * environment variable "DATABASE" and defaults to an in-memory SQLite |
||
93 | * database. |
||
94 | * |
||
95 | * @return \eZ\Publish\Core\Persistence\Doctrine\ConnectionHandler |
||
96 | */ |
||
97 | final public function getDatabaseHandler() |
||
106 | |||
107 | /** |
||
108 | * Get native Doctrine database connection. |
||
109 | * |
||
110 | * @throws \Doctrine\DBAL\DBALException |
||
111 | */ |
||
112 | final public function getDatabaseConnection(): Connection |
||
126 | |||
127 | /** |
||
128 | * @throws \Doctrine\DBAL\DBALException |
||
129 | */ |
||
130 | final public function getSharedGateway(): SharedGateway\Gateway |
||
146 | |||
147 | /** |
||
148 | * Resets the database on test setup, so we always operate on a clean |
||
149 | * database. |
||
150 | */ |
||
151 | protected function setUp(): void |
||
171 | |||
172 | protected function tearDown(): void |
||
177 | |||
178 | /** |
||
179 | * Get a text representation of a result set. |
||
180 | * |
||
181 | * @param array $result |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | protected static function getResultTextRepresentation(array $result) |
||
197 | |||
198 | /** |
||
199 | * Inserts database fixture from $file. |
||
200 | * |
||
201 | * @param string $file |
||
202 | */ |
||
203 | protected function insertDatabaseFixture($file) |
||
250 | |||
251 | /** |
||
252 | * Reset DB sequences. |
||
253 | */ |
||
254 | public function resetSequences() |
||
268 | |||
269 | /** |
||
270 | * Assert query result as correct. |
||
271 | * |
||
272 | * Builds text representations of the asserted and fetched query result, |
||
273 | * based on a eZ\Publish\Core\Persistence\Database\SelectQuery object. Compares them using classic diff for |
||
274 | * maximum readability of the differences between expectations and real |
||
275 | * results. |
||
276 | * |
||
277 | * The expectation MUST be passed as a two dimensional array containing |
||
278 | * rows of columns. |
||
279 | * |
||
280 | * @param array $expectation |
||
281 | * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query |
||
282 | * @param string $message |
||
283 | */ |
||
284 | public static function assertQueryResult(array $expectation, SelectQuery $query, $message = '') |
||
300 | |||
301 | /** |
||
302 | * Asserts correct property values on $object. |
||
303 | * |
||
304 | * Asserts that for all keys in $properties a corresponding property |
||
305 | * exists in $object with the *same* value as in $properties. |
||
306 | * |
||
307 | * @param array $properties |
||
308 | * @param object $object |
||
309 | */ |
||
310 | protected function assertPropertiesCorrect(array $properties, $object) |
||
325 | |||
326 | /** |
||
327 | * Asserts $expStruct equals $actStruct in at least $propertyNames. |
||
328 | * |
||
329 | * Asserts that properties of $actStruct equal properties of $expStruct (not |
||
330 | * vice versa!). If $propertyNames is null, all properties are checked. |
||
331 | * Otherwise, $propertyNames provides a white list. |
||
332 | * |
||
333 | * @param object $expStruct |
||
334 | * @param object $actStruct |
||
335 | * @param array $propertyNames |
||
336 | */ |
||
337 | protected function assertStructsEqual( |
||
353 | |||
354 | /** |
||
355 | * Returns public property names in $object. |
||
356 | * |
||
357 | * @param object $object |
||
358 | * |
||
359 | * @return array |
||
360 | */ |
||
361 | protected function getPublicPropertyNames($object) |
||
372 | |||
373 | /** |
||
374 | * @return string |
||
375 | */ |
||
376 | protected static function getInstallationDir() |
||
386 | } |
||
387 |