Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORMPurger: quote table names using reserved keywords #250

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace Doctrine\Common\DataFixtures\Purger;

use Doctrine\DBAL\Schema\Table;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter;
use Doctrine\ORM\Mapping\ClassMetadata;
Expand Down Expand Up @@ -244,7 +245,9 @@ private function getTableName($class, $platform)
return $class->table['schema'].'.'.$this->em->getConfiguration()->getQuoteStrategy()->getTableName($class, $platform);
}

return $this->em->getConfiguration()->getQuoteStrategy()->getTableName($class, $platform);
$tableName = $this->em->getConfiguration()->getQuoteStrategy()->getTableName($class, $platform);
$tableAsset = new Table($tableName);
return $tableAsset->getQuotedName($platform);
}

/**
Expand All @@ -262,4 +265,4 @@ private function getJoinTableName($assoc, $class, $platform)

return $this->em->getConfiguration()->getQuoteStrategy()->getJoinTableName($assoc, $class, $platform);
}
}
}
13 changes: 13 additions & 0 deletions tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ORMPurgerTest extends BaseTest
const TEST_ENTITY_USER = 'Doctrine\Tests\Common\DataFixtures\TestEntity\User';
const TEST_ENTITY_USER_WITH_SCHEMA = 'Doctrine\Tests\Common\DataFixtures\TestEntity\UserWithSchema';
const TEST_ENTITY_QUOTED = 'Doctrine\Tests\Common\DataFixtures\TestEntity\Quoted';
const TEST_ENTITY_RESERVED_KEYWORD = 'Doctrine\Tests\Common\DataFixtures\TestEntity\ReservedKeyword';


public function testGetAssociationTables()
Expand Down Expand Up @@ -65,4 +66,16 @@ public function testTableNameWithSchema()
$this->assertStringStartsWith('test_schema',$tableName);
}

public function testTableNameQuotedIfReservedKeyword()
{
$em = $this->getMockAnnotationReaderEntityManager();
$metadata = $em->getClassMetadata(self::TEST_ENTITY_RESERVED_KEYWORD);
$platform = $em->getConnection()->getDatabasePlatform();
$purger = new ORMPurger($em);
$class = new ReflectionClass('Doctrine\Common\DataFixtures\Purger\ORMPurger');
$method = $class->getMethod('getTableName');
$method->setAccessible(true);
$tableName = $method->invokeArgs($purger, array($metadata, $platform));
$this->assertEquals($tableName, '"SELECT"');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Doctrine\Tests\Common\DataFixtures\TestEntity;

/**
* @Entity
* @Table("SELECT")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
class ReservedKeyword
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="IDENTITY")
*/
private $id;
}