Unverified Commit 6f8f1e14 authored by Gawain Lynch's avatar Gawain Lynch Committed by Luís Cobucci

[Tests] Check for correct collation when column names are similar

parent 0e8ad2c7
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\Tests\DBAL\Schema; namespace Doctrine\Tests\DBAL\Schema;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\SqliteSchemaManager; use Doctrine\DBAL\Schema\SqliteSchemaManager;
...@@ -9,37 +10,32 @@ class SqliteSchemaManagerTest extends \PHPUnit\Framework\TestCase ...@@ -9,37 +10,32 @@ class SqliteSchemaManagerTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @dataProvider getDataColumnCollation * @dataProvider getDataColumnCollation
*
* @group 2865
*/ */
public function testParseColumnCollation($collation, $column, $sql) public function testParseColumnCollation($collation, string $column, string $sql) : void
{ {
$conn = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock(); $conn = $this->createMock(Connection::class);
$conn->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue(new SqlitePlatform())); $conn->method('getDatabasePlatform')->willReturn(new SqlitePlatform());
$manager = new SqliteSchemaManager($conn); $manager = new SqliteSchemaManager($conn);
$ref = new \ReflectionMethod($manager, 'parseColumnCollationFromSQL'); $ref = new \ReflectionMethod($manager, 'parseColumnCollationFromSQL');
$ref->setAccessible(true); $ref->setAccessible(true);
self::assertEquals($collation, $ref->invoke($manager, $column, $sql)); self::assertSame($collation, $ref->invoke($manager, $column, $sql));
} }
public function getDataColumnCollation() public function getDataColumnCollation()
{ {
return array( return [
array( ['RTRIM', 'a', 'CREATE TABLE "a" ("a" text DEFAULT "aa" COLLATE "RTRIM" NOT NULL)'],
'RTRIM', 'a', 'CREATE TABLE "a" ("a" text DEFAULT "aa" COLLATE "RTRIM" NOT NULL)' ['utf-8', 'a', 'CREATE TABLE "a" ("b" text UNIQUE NOT NULL COLLATE NOCASE, "a" text DEFAULT "aa" COLLATE "utf-8" NOT NULL)'],
), ['NOCASE', 'a', 'CREATE TABLE "a" ("a" text DEFAULT (lower(ltrim(" a") || rtrim("a "))) CHECK ("a") NOT NULL COLLATE NOCASE UNIQUE, "b" text COLLATE RTRIM)'],
array( [false, 'a', 'CREATE TABLE "a" ("a" text CHECK ("a") NOT NULL, "b" text COLLATE RTRIM)'],
'utf-8', 'a', 'CREATE TABLE "a" ("b" text UNIQUE NOT NULL COLLATE NOCASE, "a" text DEFAULT "aa" COLLATE "utf-8" NOT NULL)' ['RTRIM', 'a"b', 'CREATE TABLE "a" ("a""b" text COLLATE RTRIM)'],
), ['BINARY', 'b', 'CREATE TABLE "a" (bb TEXT COLLATE RTRIM, b VARCHAR(42) NOT NULL COLLATE BINARY)'],
array( ['BINARY', 'b', 'CREATE TABLE "a" (bbb TEXT COLLATE NOCASE, bb TEXT COLLATE RTRIM, b VARCHAR(42) NOT NULL COLLATE BINARY)'],
'NOCASE', 'a', 'CREATE TABLE "a" ("a" text DEFAULT (lower(ltrim(" a") || rtrim("a "))) CHECK ("a") NOT NULL COLLATE NOCASE UNIQUE, "b" text COLLATE RTRIM)' ['BINARY', 'b', 'CREATE TABLE "a" (b VARCHAR(42) NOT NULL COLLATE BINARY, bb TEXT COLLATE RTRIM)'],
), ];
array(
false, 'a', 'CREATE TABLE "a" ("a" text CHECK ("a") NOT NULL, "b" text COLLATE RTRIM)'
),
array(
'RTRIM', 'a"b', 'CREATE TABLE "a" ("a""b" text COLLATE RTRIM)'
),
);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment