diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 35ac87c38..c24fa40cc 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -291,7 +291,8 @@ class SqlWalker implements TreeWalker $tableName .= ($dqlAlias) ? '@[' . $dqlAlias . ']' : ''; if ( ! isset($this->tableAliasMap[$tableName])) { - $this->tableAliasMap[$tableName] = strtolower(substr($tableName, 0, 1)) . $this->tableAliasCounter++ . '_'; + $this->tableAliasMap[$tableName] = (preg_match('/[a-z]/i', $tableName[0]) ? strtolower($tableName[0]) : 't') + . $this->tableAliasCounter++ . '_'; } return $this->tableAliasMap[$tableName]; diff --git a/tests/Doctrine/Tests/ORM/Query/SqlWalkerTest.php b/tests/Doctrine/Tests/ORM/Query/SqlWalkerTest.php new file mode 100644 index 000000000..263cffc56 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Query/SqlWalkerTest.php @@ -0,0 +1,62 @@ +sqlWalker = new SqlWalker(new Query($this->_getTestEntityManager()), new ParserResult(), array()); + } + + /** + * @dataProvider getColumnNamesAndSqlAliases + */ + public function testGetSQLTableAlias($tableName, $expectedAlias) + { + $this->assertSame($expectedAlias, $this->sqlWalker->getSQLTableAlias($tableName)); + } + + /** + * @dataProvider getColumnNamesAndSqlAliases + */ + public function testGetSQLTableAliasIsSameForMultipleCalls($tableName) + { + $this->assertSame( + $this->sqlWalker->getSQLTableAlias($tableName), + $this->sqlWalker->getSQLTableAlias($tableName) + ); + } + + /** + * @private data provider + * + * @return string[][] + */ + public function getColumnNamesAndSqlAliases() + { + return array( + array('aaaaa', 'a0_'), + array('table', 't0_'), + array('çtable', 't0_'), + ); + } +}