Skip to content

Commit

Permalink
Merge pull request #2702 from asgrim/filter-tablenames-in-db2-schema-…
Browse files Browse the repository at this point in the history
…manager

Added missing filtering of table name assets in DB2SchemaManager
  • Loading branch information
Ocramius authored May 2, 2017
2 parents 0061022 + 31195d9 commit 1b3c36b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/DB2SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function listTableNames()

$tables = $this->_conn->fetchAll($sql);

return $this->_getPortableTablesList($tables);
return $this->filterAssetNames($this->_getPortableTablesList($tables));
}

/**
Expand Down
71 changes: 71 additions & 0 deletions tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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
*/
final class DB2SchemaManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Connection|\PHPUnit_Framework_MockObject_MockObject
*/
private $conn;

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

protected function setUp()
{
$eventManager = new EventManager();
$driverMock = $this->getMock(Driver::class);
$platform = $this->getMock(DB2Platform::class);
$this->conn = $this->getMock(
Connection::class,
['fetchAll'],
[['platform' => $platform], $driverMock, new Configuration(), $eventManager]
);
$this->manager = new DB2SchemaManager($this->conn);
}

/**
* @group DBAL-2701
* @see https://github.com/doctrine/dbal/issues/2701
* @return void
*/
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',
],
]));

$this->assertSame(
[
'FOO',
'BAR',
],
$this->manager->listTableNames()
);
}
}

0 comments on commit 1b3c36b

Please sign in to comment.