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 Symfony\Component\DependencyInjection\Argument\RewindableGenerator; |
18
|
|
|
use Traversable; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\SharedGateway\GatewayFactory |
22
|
|
|
*/ |
23
|
|
|
final class GatewayFactoryTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
/** @var \eZ\Publish\Core\Persistence\Legacy\SharedGateway\GatewayFactory */ |
26
|
|
|
private $factory; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @throws \Doctrine\DBAL\DBALException |
30
|
|
|
*/ |
31
|
|
|
public function setUp(): void |
32
|
|
|
{ |
33
|
|
|
$gateways = [ |
34
|
|
|
'sqlite' => new SqliteGateway($this->createMock(Connection::class)), |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
$this->factory = new GatewayFactory( |
38
|
|
|
new FallbackGateway($this->createMock(Connection::class)), |
39
|
|
|
// mock Symfony container behavior for the test to be more accurate |
40
|
|
|
new RewindableGenerator( |
41
|
|
|
function () use ($gateways): Traversable { |
42
|
|
|
foreach ($gateways as $databasePlatformName => $gateway) { |
43
|
|
|
yield $databasePlatformName => $gateway; |
44
|
|
|
} |
45
|
|
|
}, |
46
|
|
|
count($gateways) |
47
|
|
|
) |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\SharedGateway\GatewayFactory::buildSharedGateway |
53
|
|
|
* |
54
|
|
|
* @dataProvider getTestBuildSharedGatewayData |
55
|
|
|
* |
56
|
|
|
* @param \Doctrine\DBAL\Connection $connectionMock |
57
|
|
|
* @param string $expectedInstance |
58
|
|
|
* |
59
|
|
|
* @throws \Doctrine\DBAL\DBALException |
60
|
|
|
*/ |
61
|
|
|
public function testBuildSharedGateway( |
62
|
|
|
Connection $connectionMock, |
63
|
|
|
string $expectedInstance |
64
|
|
|
): void { |
65
|
|
|
self::assertInstanceOf( |
66
|
|
|
$expectedInstance, |
67
|
|
|
$this->factory->buildSharedGateway($connectionMock) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return \Doctrine\DBAL\Connection[]|\PHPUnit\Framework\MockObject\MockObject[]|\Traversable |
73
|
|
|
*/ |
74
|
|
|
public function getTestBuildSharedGatewayData(): Traversable |
75
|
|
|
{ |
76
|
|
|
$databasePlatformGatewayPairs = [ |
77
|
|
|
[new Platforms\SqlitePlatform(), SqliteGateway::class], |
78
|
|
|
[new Platforms\MySQL80Platform(), FallbackGateway::class], |
79
|
|
|
[new Platforms\MySqlPlatform(), FallbackGateway::class], |
80
|
|
|
[new Platforms\PostgreSqlPlatform(), FallbackGateway::class], |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
foreach ($databasePlatformGatewayPairs as $databasePlatformGatewayPair) { |
84
|
|
|
[$databasePlatform, $sharedGateway] = $databasePlatformGatewayPair; |
|
|
|
|
85
|
|
|
/** @var \Doctrine\DBAL\Platforms\AbstractPlatform $databasePlatform */ |
86
|
|
|
$connectionMock = $this |
87
|
|
|
->createMock(Connection::class); |
88
|
|
|
$connectionMock |
89
|
|
|
->expects($this->any()) |
90
|
|
|
->method('getDatabasePlatform') |
91
|
|
|
->willReturn($databasePlatform); |
|
|
|
|
92
|
|
|
|
93
|
|
|
yield [ |
94
|
|
|
$connectionMock, |
95
|
|
|
$sharedGateway, |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.