-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFacadeTest.php
More file actions
80 lines (65 loc) · 2.4 KB
/
Copy pathFacadeTest.php
File metadata and controls
80 lines (65 loc) · 2.4 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
declare(strict_types=1);
namespace InitORM\Database\Tests;
use InitORM\Database\Database;
use InitORM\Database\Exceptions\DatabaseException;
use InitORM\Database\Facade\DB;
use InitORM\Database\Interfaces\DatabaseInterface;
use InitORM\Database\Tests\Support\SqliteHelper;
use PHPUnit\Framework\TestCase;
final class FacadeTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
DB::replaceImmutable(null);
}
public function test_get_database_before_init_throws(): void
{
$this->expectException(DatabaseException::class);
DB::getDatabase();
}
public function test_create_immutable_then_get(): void
{
$instance = DB::createImmutable(SqliteHelper::makeConnection());
self::assertSame($instance, DB::getDatabase());
self::assertInstanceOf(DatabaseInterface::class, $instance);
}
public function test_connect_does_not_touch_facade_slot(): void
{
$first = DB::connect(SqliteHelper::makeConnection());
self::assertInstanceOf(DatabaseInterface::class, $first);
// The facade slot is still empty since connect() doesn't set it.
$this->expectException(DatabaseException::class);
DB::getDatabase();
}
public function test_replace_immutable_accepts_a_database_instance(): void
{
$custom = SqliteHelper::makeDatabase();
$result = DB::replaceImmutable($custom);
self::assertSame($custom, $result);
self::assertSame($custom, DB::getDatabase());
}
public function test_replace_immutable_with_null_clears_facade(): void
{
DB::createImmutable(SqliteHelper::makeConnection());
self::assertNull(DB::replaceImmutable(null));
$this->expectException(DatabaseException::class);
DB::getDatabase();
}
public function test_static_call_forwards_to_underlying_database(): void
{
$connection = SqliteHelper::makeConnection();
SqliteHelper::seedUsers($connection);
DB::createImmutable($connection);
$rows = DB::read('users')->asAssoc()->rows();
self::assertCount(3, $rows);
}
public function test_facade_constructor_is_private(): void
{
$reflection = new \ReflectionClass(DB::class);
$constructor = $reflection->getConstructor();
self::assertNotNull($constructor);
self::assertTrue($constructor->isPrivate());
}
}