-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionStoreTest.php
More file actions
73 lines (60 loc) · 2.29 KB
/
ConnectionStoreTest.php
File metadata and controls
73 lines (60 loc) · 2.29 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
<?php
namespace NeuronTests\Database;
use Neuron\Database\ConnectionStore;
use Neuron\Database\DatabaseDriver;
use Neuron\Database\DatabaseManager;
use Neuron\Database\Exceptions\DuplicateNameException;
use Neuron\Database\Exceptions\NotConnectedException;
use Neuron\Extensibility\ExtensionsInterface;
use Neuron\Extensibility\ExtensionStore;
use Neuron\Extensibility\InstantiatorInterface;
use NeuronTests\Database\Drivers\MockDatabaseDriver;
use PHPUnit\Framework\TestCase;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
class ConnectionStoreTest extends TestCase
{
private ConnectionStore $store;
private InstantiatorInterface $instantiator;
private LoggerInterface $logger;
private ExtensionsInterface $extensions;
private DatabaseManager $database;
private EventDispatcherInterface $eventDispatcher;
protected function setUp(): void
{
$this->logger = $this->createMock(LoggerInterface::class);
$this->instantiator = $this->createMock(InstantiatorInterface::class);
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->extensions = new ExtensionStore(
$this->instantiator,
$this->logger,
$this->eventDispatcher
);
$this->database = new DatabaseManager(
$this->logger,
$this->extensions,
$this->eventDispatcher
);
$this->store = $this->database->getConnectionStore();
$this->extensions
->getRegistry()
->register(DatabaseDriver::class, MockDatabaseDriver::class);
}
public function testAddThrowsDuplicateNameException(): void
{
$this->store->add('test', MockDatabaseDriver::class);
$this->expectException(DuplicateNameException::class);
$this->store->add('test', MockDatabaseDriver::class);
}
public function testGetThrowsNotConnectedException(): void
{
$this->expectException(NotConnectedException::class);
$this->store->get('nonexistent');
}
public function testHasReturnsCorrectly(): void
{
$this->store->add('existing', MockDatabaseDriver::class);
$this->assertTrue($this->store->has('existing'));
$this->assertFalse($this->store->has('nonexisting'));
}
}