Issue #3269091 by gambry, yogeshmpawar, jonathanshaw, joachim, alexpott: Undocumented behaviour for Schema::findTables() when an underscore is used
parent
0a110d3487
commit
e9294d88bf
|
@ -180,7 +180,12 @@ abstract class Schema implements PlaceholderInterface {
|
||||||
* Finds all tables that are like the specified base table name.
|
* Finds all tables that are like the specified base table name.
|
||||||
*
|
*
|
||||||
* @param string $table_expression
|
* @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
|
* @return array
|
||||||
* Both the keys and the values are the matching tables.
|
* Both the keys and the values are the matching tables.
|
||||||
|
|
|
@ -1320,6 +1320,61 @@ class SchemaTest extends KernelTestBase {
|
||||||
];
|
];
|
||||||
$this->assertEquals($expected, $tables, 'Two tables were found.');
|
$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.
|
// Go back to the initial connection.
|
||||||
Database::setActiveConnection('default');
|
Database::setActiveConnection('default');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue