diff --git a/UPGRADE.md b/UPGRADE.md index 75154b08f88..2a830dcf922 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 `Connection::ping()` returns `void`. 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 69af7a5eadc..2a71f88dde8 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -234,16 +234,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 b71c0249ae0..cae1835500b 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() : void $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 46b8fd3949e..bcf2622b295 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 @@ -50,7 +51,9 @@ protected function setUp() : void */ public function testListTableNamesFiltersAssetNamesCorrectly() : void { - $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'], @@ -67,35 +70,6 @@ public function testListTableNamesFiltersAssetNamesCorrectly() : void ); } - /** - * @group DBAL-2701 - */ - public function testAssetFilteringSetsACallable() : void - { - $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()); - } - public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() : void { $accepted = ['T_FOO', 'T_BAR']; @@ -117,79 +91,5 @@ public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() : voi ], $this->manager->listTableNames() ); - - $this->assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); - } - - public function testSettingNullExpressionWillResetCallable() : void - { - $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()); - } - - public function testSettingNullAsCallableClearsExpression() : void - { - $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()); } }