Passed
Pull Request — master (#2893)
by Šimon
14:29 queued 16s
created

PostgreSQLSchemaManagerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Schema;
4
5
use Doctrine\DBAL\Configuration;
6
use Doctrine\DBAL\Schema\PostgreSqlSchemaManager;
7
use Doctrine\DBAL\Schema\Sequence;
8
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
9
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
10
11
class PostgreSQLSchemaManagerTest extends \PHPUnit\Framework\TestCase
12
{
13
    /**
14
     * @var \Doctrine\DBAL\Schema\PostgreSQLSchemaManager
15
     */
16
    private $schemaManager;
17
18
    /**
19
     * @var \Doctrine\DBAL\Connection|\PHPUnit_Framework_MockObject_MockObject
20
     */
21
    private $connection;
22
23
    private function setupConnectionAndManager(string $platformClass) : void
24
    {
25
        $driverMock = $this->createMock('Doctrine\DBAL\Driver');
26
        $platform   = $this->createMock($platformClass);
27
28
        $this->connection = $this->getMockBuilder('Doctrine\DBAL\Connection')
29
            ->setConstructorArgs([['platform' => $platform], $driverMock])
30
            ->getMock();
31
32
        $this->schemaManager = new PostgreSqlSchemaManager($this->connection, $platform);
33
    }
34
35
    /**
36
     * @group DBAL-474
37
     * @dataProvider filtersSequencesDataProvider
38
     */
39
    public function testFiltersSequences(string $platformClass) : void
40
    {
41
        $this->setupConnectionAndManager($platformClass);
42
43
        $configuration = new Configuration();
44
        $configuration->setFilterSchemaAssetsExpression('/^schema/');
45
46
        $sequences = [
47
            ['relname' => 'foo', 'schemaname' => 'schema'],
48
            ['relname' => 'bar', 'schemaname' => 'schema'],
49
            ['relname' => 'baz', 'schemaname' => ''],
50
            ['relname' => 'bloo', 'schemaname' => 'bloo_schema'],
51
        ];
52
53
        $this->connection->expects($this->any())
54
            ->method('getConfiguration')
55
            ->will($this->returnValue($configuration));
56
57
        $this->connection->expects($this->at(0))
58
            ->method('fetchAll')
59
            ->will($this->returnValue($sequences));
60
61
        $this->connection->expects($this->at(2))
62
            ->method('fetchAll')
63
            ->will($this->returnValue([['min_value' => 1, 'increment_by' => 1]]));
64
65
        $this->connection->expects($this->at(3))
66
            ->method('fetchAll')
67
            ->will($this->returnValue([['min_value' => 2, 'increment_by' => 2]]));
68
69
        $this->connection->expects($this->exactly(3))
70
            ->method('fetchAll');
71
72
        self::assertEquals(
73
            [
74
                new Sequence('schema.foo', 1, 1),
75
                new Sequence('schema.bar', 2, 2),
76
            ],
77
            $this->schemaManager->listSequences('database')
78
        );
79
    }
80
81
    public function filtersSequencesDataProvider() : array
82
    {
83
        return [
84
            [PostgreSqlPlatform::class],
85
            [PostgreSQL100Platform::class]
86
        ];
87
    }
88
}
89