Skip to content

Instantly share code, notes, and snippets.

@doctrinebot
Created December 13, 2015 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doctrinebot/dc80c18ef0726240bcad to your computer and use it in GitHub Desktop.
Save doctrinebot/dc80c18ef0726240bcad to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-115 - https://github.com/doctrine/doctrine2/issues/1750
Index: tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
===================================================================
--- tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php (revision 6662)
+++ tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php (working copy)
@@ -16,17 +16,10 @@
{
public function testGetMetadataForSingleClass()
{
- $driverMock = new DriverMock();
- $config = new \Doctrine\ORM\Configuration();
- $config->setProxyDir(__DIR__ . '/../../Proxies');
- $config->setProxyNamespace('Doctrine\Tests\Proxies');
- $eventManager = new EventManager();
- $conn = new ConnectionMock(array(), $driverMock, $config, $eventManager);
$mockDriver = new MetadataDriverMock();
- $config->setMetadataDriverImpl($mockDriver);
+ $entityManager = $this->_createEntityManager($mockDriver);
- $entityManager = EntityManagerMock::create($conn, $config, $eventManager);
-
+ $conn = $entityManager->getConnection();
$mockPlatform = $conn->getDatabasePlatform();
$mockPlatform->setPrefersSequences(true);
$mockPlatform->setPrefersIdentityColumns(false);
@@ -65,6 +58,37 @@
$this->assertTrue($cm1->hasField('name'));
$this->assertEquals(ClassMetadata::GENERATOR_TYPE_SEQUENCE, $cm1->generatorType);
}
+
+ public function testGetMetadataGlobalNamespaceModel()
+ {
+ require_once __DIR__."/../../Models/Global/GlobalNamespaceModel.php";
+
+ $reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache);
+ $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
+ $metadataDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
+ $metadataDriver->setClassDirectory(__DIR__."/../../Models/Global/");
+
+ $entityManager = $this->_createEntityManager($metadataDriver);
+
+ $m1 = $entityManager->getMetadataFactory()->getMetadataFor("DoctrineGlobal_Article");
+ $m2 = $entityManager->getMetadataFactory()->getMetadataFor("\DoctrineGlobal_Article");
+
+ $this->assertSame($m1, $m2);
+ }
+
+ protected function _createEntityManager($metadataDriver)
+ {
+ $driverMock = new DriverMock();
+ $config = new \Doctrine\ORM\Configuration();
+ $config->setProxyDir(__DIR__ . '/../../Proxies');
+ $config->setProxyNamespace('Doctrine\Tests\Proxies');
+ $eventManager = new EventManager();
+ $conn = new ConnectionMock(array(), $driverMock, $config, $eventManager);
+ $mockDriver = new MetadataDriverMock();
+ $config->setMetadataDriverImpl($metadataDriver);
+
+ return EntityManagerMock::create($conn, $config, $eventManager);
+ }
}
/* Test subject class with overriden factory method for mocking purposes */
<?php
/**
* @entity
* @table(name="articles")
*/
class DoctrineGlobal_Article
{
/**
* @id
* @column(type="int")
*/
protected $id;
/**
* @column(type="string")
*/
protected $headline;
/**
* @column(type="text")
*/
protected $text;
/**
* @ManyToMany(targetEntity="DoctrineGlobal_User")
* @JoinTable(name="author_articles",
* joinColumns={@JoinColumn(name="article_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="author_id", referencedColumnName="id", unique=true)}
* )
*/
protected $author;
/**
* @ManyToMany(targetEntity="\DoctrineGlobal_User")
* @JoinTable(name="editor_articles",
* joinColumns={@JoinColumn(name="article_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="editor_id", referencedColumnName="id", unique=true)}
* )
*/
protected $editor;
}
/**
* @Entity
* @Table(name="users")
*/
class DoctrineGlobal_User
{
/**
* @Id
* @column(type="integer")
* @var int
*/
private $id;
/**
* @column(type="string", length=64)
* @var string
*/
private $username;
/**
* @column(type="string", length=128)
* @var string
*/
private $email;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment