DB2SchemaManagerTest.php 1.82 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<?php

namespace Doctrine\Tests\DBAL\Schema;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\DB2SchemaManager;

/**
 * @covers \Doctrine\DBAL\Schema\DB2SchemaManager
 */
Luís Cobucci's avatar
Luís Cobucci committed
15
final class DB2SchemaManagerTest extends \PHPUnit\Framework\TestCase
16 17
{
    /**
18
     * @var Connection|\PHPUnit_Framework_MockObject_MockObject
19 20 21 22 23 24 25 26 27 28 29
     */
    private $conn;

    /**
     * @var DB2SchemaManager
     */
    private $manager;

    protected function setUp()
    {
        $eventManager = new EventManager();
30 31 32 33 34 35 36
        $driverMock = $this->createMock(Driver::class);
        $platform = $this->createMock(DB2Platform::class);
        $this->conn = $this
            ->getMockBuilder(Connection::class)
            ->setMethods(['fetchAll'])
            ->setConstructorArgs([['platform' => $platform], $driverMock, new Configuration(), $eventManager])
            ->getMock();
37 38 39
        $this->manager = new DB2SchemaManager($this->conn);
    }

40 41 42 43 44
    /**
     * @group DBAL-2701
     * @see https://github.com/doctrine/dbal/issues/2701
     * @return void
     */
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    public function testListTableNamesFiltersAssetNamesCorrectly()
    {
        $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/');
        $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([
            [
                'name' => 'FOO',
            ],
            [
                'name' => 'T_FOO',
            ],
            [
                'name' => 'BAR',
            ],
            [
                'name' => 'T_BAR',
            ],
        ]));

63
        self::assertSame(
64 65 66 67 68 69 70 71
            [
                'FOO',
                'BAR',
            ],
            $this->manager->listTableNames()
        );
    }
}