-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestDatabase.php
More file actions
51 lines (42 loc) · 1.39 KB
/
TestDatabase.php
File metadata and controls
51 lines (42 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php declare(strict_types=1);
namespace Cspray\DatabaseTesting;
use Cspray\DatabaseTesting\ConnectionAdapter\ConnectionAdapter;
use Cspray\DatabaseTesting\DatabaseRepresentation\Table;
use Cspray\DatabaseTesting\Fixture\Fixture;
use Cspray\DatabaseTesting\Internal\ClosureDataProviderTable;
/**
* Represents the public API testing framework extensions should interact with to establish test database connections
* and ensure the state of the database before and after tests.
*
* @api
*/
final class TestDatabase {
private function __construct(
private readonly ConnectionAdapter $connectionAdapter,
) {}
public function connectionAdapter() : ConnectionAdapter {
return $this->connectionAdapter;
}
/**
* @template UnderlyingConnection of object
* @return UnderlyingConnection
*/
public function connection() : object {
return $this->connectionAdapter->underlyingConnection();
}
/**
* @param list<Fixture> $fixtures
*/
public function loadFixtures(array $fixtures) : void {
$this->connectionAdapter->insert($fixtures);
}
/**
* Allow for introspection of a database table.
*
* @param non-empty-string $name
* @return Table
*/
public function table(string $name) : Table {
return new ClosureDataProviderTable($name, fn() => $this->connectionAdapter->selectAll($name));
}
}