Completed
Push — ezp-31088-refactor-content-mod... ( 3726c8...1a7fc2 )
by
unknown
12:33
created

GatewayFactoryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 0
Metric Value
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 11
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
        );
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ')'
Loading history...
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