|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Persistence\Legacy\Tests\SharedGateway; |
|
10
|
|
|
|
|
11
|
|
|
use Doctrine\DBAL\Connection; |
|
12
|
|
|
use Doctrine\DBAL\Platforms; |
|
13
|
|
|
use eZ\Publish\Core\Persistence\Legacy\SharedGateway\DatabasePlatform\FallbackGateway; |
|
14
|
|
|
use eZ\Publish\Core\Persistence\Legacy\SharedGateway\DatabasePlatform\SqliteGateway; |
|
15
|
|
|
use eZ\Publish\Core\Persistence\Legacy\SharedGateway\GatewayFactory; |
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
use Traversable; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\SharedGateway\GatewayFactory |
|
21
|
|
|
*/ |
|
22
|
|
|
final class GatewayFactoryTest extends TestCase |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var \eZ\Publish\Core\Persistence\Legacy\SharedGateway\GatewayFactory */ |
|
25
|
|
|
private $factory; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @throws \Doctrine\DBAL\DBALException |
|
29
|
|
|
*/ |
|
30
|
|
|
public function setUp(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$gateways = [ |
|
33
|
|
|
'sqlite' => new SqliteGateway($this->createMock(Connection::class)), |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
$this->factory = new GatewayFactory( |
|
37
|
|
|
new FallbackGateway($this->createMock(Connection::class)), |
|
38
|
|
|
$gateways, |
|
39
|
|
|
); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\SharedGateway\GatewayFactory::buildSharedGateway |
|
44
|
|
|
* |
|
45
|
|
|
* @dataProvider getTestBuildSharedGatewayData |
|
46
|
|
|
* |
|
47
|
|
|
* @param \Doctrine\DBAL\Connection $connectionMock |
|
48
|
|
|
* @param string $expectedInstance |
|
49
|
|
|
* |
|
50
|
|
|
* @throws \Doctrine\DBAL\DBALException |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testBuildSharedGateway( |
|
53
|
|
|
Connection $connectionMock, |
|
54
|
|
|
string $expectedInstance |
|
55
|
|
|
): void { |
|
56
|
|
|
self::assertInstanceOf( |
|
57
|
|
|
$expectedInstance, |
|
58
|
|
|
$this->factory->buildSharedGateway($connectionMock) |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return \Doctrine\DBAL\Connection[]|\PHPUnit\Framework\MockObject\MockObject[]|\Traversable |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getTestBuildSharedGatewayData(): Traversable |
|
66
|
|
|
{ |
|
67
|
|
|
$databasePlatformGatewayPairs = [ |
|
68
|
|
|
[new Platforms\SqlitePlatform(), SqliteGateway::class], |
|
69
|
|
|
[new Platforms\MySQL80Platform(), FallbackGateway::class], |
|
70
|
|
|
[new Platforms\MySqlPlatform(), FallbackGateway::class], |
|
71
|
|
|
[new Platforms\PostgreSqlPlatform(), FallbackGateway::class], |
|
72
|
|
|
]; |
|
73
|
|
|
|
|
74
|
|
|
foreach ($databasePlatformGatewayPairs as $databasePlatformGatewayPair) { |
|
75
|
|
|
[$databasePlatform, $sharedGateway] = $databasePlatformGatewayPair; |
|
76
|
|
|
/** @var \Doctrine\DBAL\Platforms\AbstractPlatform $databasePlatform */ |
|
77
|
|
|
$connectionMock = $this |
|
78
|
|
|
->createMock(Connection::class); |
|
79
|
|
|
$connectionMock |
|
80
|
|
|
->expects($this->any()) |
|
81
|
|
|
->method('getDatabasePlatform') |
|
82
|
|
|
->willReturn($databasePlatform); |
|
83
|
|
|
|
|
84
|
|
|
yield [ |
|
85
|
|
|
$connectionMock, |
|
86
|
|
|
$sharedGateway, |
|
87
|
|
|
]; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|