PostgreSQLSchemaManagerTest.php 2.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php

namespace Doctrine\Tests\DBAL\Schema;

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Schema\PostgreSqlSchemaManager;
use Doctrine\DBAL\Schema\Sequence;

class PostgreSQLSchemaManagerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var \Doctrine\DBAL\Schema\PostgreSQLSchemaManager
     */
    private $schemaManager;

    /**
     * @var \Doctrine\DBAL\Connection|\PHPUnit_Framework_MockObject_MockObject
     */
    private $connection;

    protected function setUp()
    {
23 24 25 26 27
        $driverMock = $this->createMock('Doctrine\DBAL\Driver');
        $platform = $this->createMock('Doctrine\DBAL\Platforms\PostgreSqlPlatform');
        $this->connection = $this->getMockBuilder('Doctrine\DBAL\Connection')
            ->setConstructorArgs(array(array('platform' => $platform), $driverMock))
            ->getMock();
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
        $this->schemaManager = new PostgreSqlSchemaManager($this->connection, $platform);
    }

    /**
     * @group DBAL-474
     */
    public function testFiltersSequences()
    {
        $configuration = new Configuration();
        $configuration->setFilterSchemaAssetsExpression('/^schema/');

        $sequences = array(
            array('relname' => 'foo', 'schemaname' => 'schema'),
            array('relname' => 'bar', 'schemaname' => 'schema'),
            array('relname' => 'baz', 'schemaname' => ''),
            array('relname' => 'bloo', 'schemaname' => 'bloo_schema'),
        );

        $this->connection->expects($this->any())
            ->method('getConfiguration')
            ->will($this->returnValue($configuration));

        $this->connection->expects($this->at(0))
            ->method('fetchAll')
            ->will($this->returnValue($sequences));

        $this->connection->expects($this->at(1))
            ->method('fetchAll')
            ->will($this->returnValue(array(array('min_value' => 1, 'increment_by' => 1))));

        $this->connection->expects($this->at(2))
            ->method('fetchAll')
            ->will($this->returnValue(array(array('min_value' => 2, 'increment_by' => 2))));

        $this->connection->expects($this->exactly(3))
            ->method('fetchAll');

        $this->assertEquals(
            array(
                new Sequence('schema.foo', 2, 2),
                new Sequence('schema.bar', 1, 1),
            ),
            $this->schemaManager->listSequences('database')
        );
    }
}