forked from php-db/phpdb-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdapterServiceFactoryTest.php
More file actions
118 lines (101 loc) · 3.57 KB
/
AdapterServiceFactoryTest.php
File metadata and controls
118 lines (101 loc) · 3.57 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace PhpDbTest\Adapter\Sqlite;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\ServiceManager\ServiceManager;
use Override;
use PhpDb\Adapter\Profiler\Profiler;
use PhpDb\Adapter\Profiler\ProfilerInterface;
use PhpDb\Adapter\Sqlite\Adapter;
use PhpDb\Adapter\Sqlite\AdapterServiceFactory;
use PhpDb\Adapter\Sqlite\ConfigProvider;
use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use function array_key_exists;
use function extension_loaded;
use function is_array;
#[CoversMethod(AdapterServiceFactory::class, '__invoke')]
final class AdapterServiceFactoryTest extends TestCase
{
private AdapterServiceFactory $factory;
protected function createServiceManager(array $dbConfig): ServiceLocatorInterface
{
$config = (new ConfigProvider())->getDependencies();
if (array_key_exists('services', $config) && is_array($config['services'])) {
$config['services']['config'] = $dbConfig;
}
return new ServiceManager($config);
}
#[Override]
protected function setUp(): void
{
if (! extension_loaded('pdo_sqlite')) {
$this->markTestSkipped('Adapter factory tests require pdo_sqlite');
}
$this->factory = new AdapterServiceFactory();
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function testV3FactoryReturnsDefaultAdapter(): void
{
$this->expectNotToPerformAssertions();
$services = $this->createServiceManager([
'db' => [
'driver' => 'Pdo_Sqlite',
'database' => ':memory:',
],
]);
$this->factory->__invoke($services, Adapter::class);
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function testV3FactoryReturnsDefaultAdapterWithDefaultProfiler(): void
{
$services = $this->createServiceManager([
'db' => [
'driver' => 'Pdo_Sqlite',
'database' => ':memory:',
'profiler' => true,
],
]);
$adapter = $this->factory->__invoke($services, Adapter::class);
self::assertInstanceOf(ProfilerInterface::class, $adapter->getProfiler());
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function testV3FactoryReturnsDefaultAdapterWithProfilerClassname(): void
{
$services = $this->createServiceManager([
'db' => [
'driver' => 'Pdo_Sqlite',
'database' => ':memory:',
'profiler' => Profiler::class,
],
]);
$adapter = $this->factory->__invoke($services, Adapter::class);
self::assertInstanceOf(ProfilerInterface::class, $adapter->getProfiler());
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function testV3FactoryReturnsDefaultAdapterWithProfilerInstance(): void
{
$services = $this->createServiceManager([
'db' => [
'driver' => 'Pdo_Sqlite',
'database' => ':memory:',
'profiler' => $this->getMockBuilder(ProfilerInterface::class)->getMock(),
],
]);
$adapter = $this->factory->__invoke($services, Adapter::class);
self::assertInstanceOf(ProfilerInterface::class, $adapter->getProfiler());
}
}