Completed
Push — ezp-31088-refactor-content-mod... ( ab3ba3 )
by
unknown
13:24 queued 33s
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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 19 2
A testBuildSharedGateway() 0 9 1
A getTestBuildSharedGatewayData() 0 25 2
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;
0 ignored issues
show
Bug introduced by
The variable $databasePlatform does not exist. Did you mean $databasePlatformGatewayPairs?

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.

Loading history...
Bug introduced by
The variable $sharedGateway does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The variable $databasePlatform does not exist. Did you mean $databasePlatformGatewayPairs?

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.

Loading history...
92
93
            yield [
94
                $connectionMock,
95
                $sharedGateway,
96
            ];
97
        }
98
    }
99
}
100