Passed
Pull Request — master (#2893)
by Šimon
06:35
created

filtersSequencesDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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
9
class PostgreSQLSchemaManagerTest extends \PHPUnit\Framework\TestCase
10
{
11
    /**
12
     * @var \Doctrine\DBAL\Schema\PostgreSQLSchemaManager
13
     */
14
    private $schemaManager;
15
16
    /**
17
     * @var \Doctrine\DBAL\Connection|\PHPUnit_Framework_MockObject_MockObject
18
     */
19
    private $connection;
20
21
    protected function setUp()
22
    {
23
        $driverMock = $this->createMock('Doctrine\DBAL\Driver');
24
        $platform = $this->createMock('Doctrine\DBAL\Platforms\PostgreSqlPlatform');
25
26
        $this->connection = $this->getMockBuilder('Doctrine\DBAL\Connection')
27
            ->setConstructorArgs([['platform' => $platform], $driverMock])
28
            ->getMock();
29
30
        $this->schemaManager = new PostgreSqlSchemaManager($this->connection, $platform);
31
    }
32
33
    /**
34
     * @group DBAL-474
35
     * @dataProvider filtersSequencesDataProvider
36
     */
37
    public function testFiltersSequences(int $postgreSQLVersion)
38
    {
39
        $configuration = new Configuration();
40
        $configuration->setFilterSchemaAssetsExpression('/^schema/');
41
42
        $sequences = [
43
            ['relname' => 'foo', 'schemaname' => 'schema'],
44
            ['relname' => 'bar', 'schemaname' => 'schema'],
45
            ['relname' => 'baz', 'schemaname' => ''],
46
            ['relname' => 'bloo', 'schemaname' => 'bloo_schema'],
47
        ];
48
49
        $this->connection->expects($this->any())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\DBAL\Connection.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
50
            ->method('getConfiguration')
51
            ->will($this->returnValue($configuration));
52
53
        $this->connection->expects($this->any())
54
            ->method('getServerVersion')
55
            ->will($this->returnValue($postgreSQLVersion));
56
57
        $this->connection->expects($this->at(0))
58
            ->method('fetchAll')
59
            ->will($this->returnValue($sequences));
60
61
        $this->connection->expects($this->at(3))
62
            ->method('fetchAll')
63
            ->will($this->returnValue([['min_value' => 1, 'increment_by' => 1]]));
64
65
        $this->connection->expects($this->at(5))
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()
82
    {
83
        return [
84
            [9],
85
            [10]
86
        ];
87
    }
88
}
89