|
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()) |
|
|
|
|
|
|
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
|
|
|
|
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:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: