MultiManagerMappingTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace Gedmo\Mapping;
  3. use Doctrine\Common\Annotations\AnnotationReader;
  4. use Doctrine\ORM\Mapping\Driver\DriverChain;
  5. use Doctrine\ORM\Mapping\Driver\YamlDriver;
  6. use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
  7. use Gedmo\Mapping\ExtensionMetadataFactory;
  8. use Tool\BaseTestCaseOM;
  9. /**
  10. * These are mapping extension tests
  11. *
  12. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  13. * @link http://www.gediminasm.org
  14. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  15. */
  16. class MultiManagerMappingTest extends BaseTestCaseOM
  17. {
  18. /**
  19. * @var Doctrine\ORM\EntityManager
  20. */
  21. private $em1;
  22. /**
  23. * @var Doctrine\ORM\EntityManager
  24. */
  25. private $em2;
  26. /**
  27. * @var Doctrine\ODM\MongoDB\DocumentManager
  28. */
  29. private $dm1;
  30. public function setUp()
  31. {
  32. parent::setUp();
  33. // EM with standard annotation mapping
  34. $this->em1 = $this->getMockSqliteEntityManager(array(
  35. 'Sluggable\Fixture\Article'
  36. ));
  37. // EM with yaml and annotation mapping
  38. $reader = new AnnotationReader();
  39. $annotationDriver = new AnnotationDriver($reader);
  40. $reader = new AnnotationReader();
  41. $annotationDriver2 = new AnnotationDriver($reader);
  42. $yamlDriver = new YamlDriver(__DIR__.'/Driver/Yaml');
  43. $chain = new DriverChain;
  44. $chain->addDriver($annotationDriver, 'Translatable\Fixture');
  45. $chain->addDriver($yamlDriver, 'Mapping\Fixture\Yaml');
  46. $chain->addDriver($annotationDriver2, 'Gedmo\Translatable');
  47. $this->em2 = $this->getMockSqliteEntityManager(array(
  48. 'Translatable\Fixture\PersonTranslation',
  49. 'Mapping\Fixture\Yaml\User',
  50. ), $chain);
  51. // DM with standard annotation mapping
  52. $this->dm1 = $this->getMockDocumentManager('gedmo_extensions_test');
  53. }
  54. public function testTwoDiferentManager()
  55. {
  56. $meta = $this->dm1->getClassMetadata('Sluggable\Fixture\Document\Article');
  57. $dmArticle = new \Sluggable\Fixture\Document\Article;
  58. $dmArticle->setCode('code');
  59. $dmArticle->setTitle('title');
  60. $this->dm1->persist($dmArticle);
  61. $this->dm1->flush();
  62. $this->assertEquals('title-code', $dmArticle->getSlug());
  63. $em1Article = new \Sluggable\Fixture\Article;
  64. $em1Article->setCode('code');
  65. $em1Article->setTitle('title');
  66. $this->em1->persist($em1Article);
  67. $this->em1->flush();
  68. $this->assertEquals('title-code', $em1Article->getSlug());
  69. }
  70. public function testTwoSameManagers()
  71. {
  72. $em1Article = new \Sluggable\Fixture\Article;
  73. $em1Article->setCode('code');
  74. $em1Article->setTitle('title');
  75. $this->em1->persist($em1Article);
  76. $this->em1->flush();
  77. $this->assertEquals('title-code', $em1Article->getSlug());
  78. $user = new \Mapping\Fixture\Yaml\User;
  79. $user->setUsername('user');
  80. $user->setPassword('secret');
  81. $this->em2->persist($user);
  82. $this->em2->flush();
  83. $this->assertEquals(1, $user->getId());
  84. }
  85. }