diff --git a/UPGRADE.md b/UPGRADE.md index ea4b0f23760..6252cce4b28 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -11,6 +11,8 @@ * Removed `Table::addUnnamedForeignKeyConstraint()` and `Table::addNamedForeignKeyConstraint()`. * Removed `Table::renameColumn()`. * Removed `SQLParserUtils::getPlaceholderPositions()`. + * Removed `AbstractSchemaManager::getFilterSchemaAssetsExpression()`, `Configuration::getFilterSchemaAssetsExpression()` + and `Configuration::getFilterSchemaAssetsExpression()`. * `SQLParserUtils::*_TOKEN` constants made private. ## BC BREAK `AbstractSchemaManager::extractDoctrineTypeFromComment()` changed, `::removeDoctrineTypeFromComment()` removed diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index 7cbca89a26a..9fe9382b89f 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -85,18 +85,6 @@ public function setFilterSchemaAssetsExpression($filterExpression) } } - /** - * Returns filter schema assets expression. - * - * @deprecated Use Configuration::getSchemaAssetsFilter() instead - * - * @return string|null - */ - public function getFilterSchemaAssetsExpression() - { - return $this->_attributes['filterSchemaAssetsExpression'] ?? null; - } - /** * @param string $filterExpression */ diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index d3e38a3d161..44929e79f83 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -233,16 +233,6 @@ protected function filterAssetNames($assetNames) return array_values(array_filter($assetNames, $filter)); } - /** - * @deprecated Use Configuration::getSchemaAssetsFilter() instead - * - * @return string|null - */ - protected function getFilterSchemaAssetsExpression() - { - return $this->_conn->getConfiguration()->getFilterSchemaAssetsExpression(); - } - /** * Lists the tables for this connection. * diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index 21900371795..df130ca1caf 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -18,6 +18,7 @@ use function array_map; use function array_pop; use function count; +use function preg_match; use function strtolower; class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase @@ -30,7 +31,7 @@ protected function tearDown() : void return; } - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression(null); + $this->connection->getConfiguration()->setSchemaAssetsFilter(null); } /** @@ -214,11 +215,15 @@ public function testFilterSchemaExpression() $column = $testTable->addColumn('id', 'integer'); $this->schemaManager->createTable($testTable); - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_#'); + $this->connection->getConfiguration()->setSchemaAssetsFilter(static function (string $name) : bool { + return preg_match('#^dbal204_#', $name) === 1; + }); $names = $this->schemaManager->listTableNames(); self::assertCount(2, $names); - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_test#'); + $this->connection->getConfiguration()->setSchemaAssetsFilter(static function (string $name) : bool { + return preg_match('#^dbal204_test#', $name) === 1; + }); $names = $this->schemaManager->listTableNames(); self::assertCount(1, $names); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php index a653430697e..96591d843d2 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use function in_array; +use function preg_match; /** * @covers \Doctrine\DBAL\Schema\DB2SchemaManager @@ -52,7 +53,9 @@ protected function setUp() : void */ public function testListTableNamesFiltersAssetNamesCorrectly() { - $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/'); + $this->conn->getConfiguration()->setSchemaAssetsFilter(static function (string $name) : bool { + return preg_match('/^(?!T_)/', $name) === 1; + }); $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ ['name' => 'FOO'], ['name' => 'T_FOO'], @@ -69,37 +72,6 @@ public function testListTableNamesFiltersAssetNamesCorrectly() ); } - /** - * @return void - * - * @group DBAL-2701 - */ - public function testAssetFilteringSetsACallable() - { - $filterExpression = '/^(?!T_)/'; - $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); - $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ - ['name' => 'FOO'], - ['name' => 'T_FOO'], - ['name' => 'BAR'], - ['name' => 'T_BAR'], - ])); - - self::assertSame( - [ - 'FOO', - 'BAR', - ], - $this->manager->listTableNames() - ); - - $callable = $this->conn->getConfiguration()->getSchemaAssetsFilter(); - self::assertIsCallable($callable); - - // BC check: Test that regexp expression is still preserved & accessible. - $this->assertEquals($filterExpression, $this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); - } - /** * @return void */ @@ -124,85 +96,5 @@ public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() ], $this->manager->listTableNames() ); - - $this->assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); - } - - /** - * @return void - */ - public function testSettingNullExpressionWillResetCallable() - { - $accepted = ['T_FOO', 'T_BAR']; - $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { - return in_array($assetName, $accepted); - }); - - $this->conn->expects($this->atLeastOnce())->method('fetchAll')->will($this->returnValue([ - ['name' => 'FOO'], - ['name' => 'T_FOO'], - ['name' => 'BAR'], - ['name' => 'T_BAR'], - ])); - - self::assertSame( - [ - 'T_FOO', - 'T_BAR', - ], - $this->manager->listTableNames() - ); - - $this->conn->getConfiguration()->setFilterSchemaAssetsExpression(null); - - self::assertSame( - [ - 'FOO', - 'T_FOO', - 'BAR', - 'T_BAR', - ], - $this->manager->listTableNames() - ); - - $this->assertNull($this->conn->getConfiguration()->getSchemaAssetsFilter()); - } - - /** - * @return void - */ - public function testSettingNullAsCallableClearsExpression() - { - $filterExpression = '/^(?!T_)/'; - $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); - - $this->conn->expects($this->exactly(2))->method('fetchAll')->will($this->returnValue([ - ['name' => 'FOO'], - ['name' => 'T_FOO'], - ['name' => 'BAR'], - ['name' => 'T_BAR'], - ])); - - self::assertSame( - [ - 'FOO', - 'BAR', - ], - $this->manager->listTableNames() - ); - - $this->conn->getConfiguration()->setSchemaAssetsFilter(null); - - self::assertSame( - [ - 'FOO', - 'T_FOO', - 'BAR', - 'T_BAR', - ], - $this->manager->listTableNames() - ); - - $this->assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); } }