Issue #3269091 by gambry, yogeshmpawar, jonathanshaw, joachim, alexpott: Undocumented behaviour for Schema::findTables() when an underscore is used

merge-requests/2142/head
Alex Pott 2022-04-19 09:18:44 +01:00
parent 0a110d3487
commit e9294d88bf
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
2 changed files with 61 additions and 1 deletions

View File

@ -180,7 +180,12 @@ abstract class Schema implements PlaceholderInterface {
* Finds all tables that are like the specified base table name.
*
* @param string $table_expression
* An SQL expression, for example "cache_%" (without the quotes).
* A case-insensitive pattern against which table names are compared. Both
* '_' and '%' are treated like wildcards in MySQL 'LIKE' expressions, where
* '_' matches any single character and '%' matches an arbitrary number of
* characters (including zero characters). So 'foo%bar' matches table names
* like 'foobar', 'fooXBar', 'fooXBaR', or 'fooXxBar'; whereas 'foo_bar'
* matches 'fooXBar' and 'fooXBaR' but not 'fooBar' or 'fooXxxBar'.
*
* @return array
* Both the keys and the values are the matching tables.

View File

@ -1320,6 +1320,61 @@ class SchemaTest extends KernelTestBase {
];
$this->assertEquals($expected, $tables, 'Two tables were found.');
// Check '_' and '%' wildcards.
$test_schema->createTable('test3table', $table_specification);
$test_schema->createTable('test4', $table_specification);
$test_schema->createTable('testTable', $table_specification);
$test_schema->createTable('test', $table_specification);
$tables = $test_schema->findTables('test%');
sort($tables);
$expected = [
'test',
'test3table',
'test4',
'testTable',
'test_1_table',
'test_2_table',
];
$this->assertEquals($expected, $tables, 'All "test" prefixed tables were found.');
$tables = $test_schema->findTables('test_%');
sort($tables);
$expected = [
'test3table',
'test4',
'testTable',
'test_1_table',
'test_2_table',
];
$this->assertEquals($expected, $tables, 'All "/^test..*?/" tables were found.');
$tables = $test_schema->findTables('test%table');
sort($tables);
$expected = [
'test3table',
'testTable',
'test_1_table',
'test_2_table',
];
$this->assertEquals($expected, $tables, 'All "/^test.*?table/" tables were found.');
$tables = $test_schema->findTables('test_%table');
sort($tables);
$expected = [
'test3table',
'test_1_table',
'test_2_table',
];
$this->assertEquals($expected, $tables, 'All "/^test..*?table/" tables were found.');
$tables = $test_schema->findTables('test_');
sort($tables);
$expected = [
'test4',
];
$this->assertEquals($expected, $tables, 'All "/^test./" tables were found.');
// Go back to the initial connection.
Database::setActiveConnection('default');
}