ClosureTreeMappingTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Gedmo\Mapping\Xml;
  3. use Doctrine\Common\Annotations\AnnotationReader;
  4. use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
  5. use Doctrine\Common\EventManager;
  6. use Doctrine\ORM\Mapping\Driver\DriverChain;
  7. use Doctrine\ORM\Mapping\Driver\XmlDriver;
  8. use Gedmo\Tree\TreeListener;
  9. use Tool\BaseTestCaseOM;
  10. /**
  11. * These are mapping extension tests
  12. *
  13. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  14. * @link http://www.gediminasm.org
  15. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  16. */
  17. class ClosureTreeMappingTest extends BaseTestCaseOM
  18. {
  19. /**
  20. * @var Doctrine\ORM\EntityManager
  21. */
  22. private $em;
  23. /**
  24. * @var Gedmo\Tree\TreeListener
  25. */
  26. private $tree;
  27. public function setUp()
  28. {
  29. parent::setUp();
  30. $reader = new AnnotationReader();
  31. $annotationDriver = new AnnotationDriver($reader);
  32. $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml');
  33. $chain = new DriverChain;
  34. $chain->addDriver($xmlDriver, 'Mapping\Fixture\Xml');
  35. $chain->addDriver($annotationDriver, 'Mapping\Fixture');
  36. $chain->addDriver($annotationDriver, 'Gedmo\Tree');
  37. $this->tree = new TreeListener;
  38. $this->evm = new EventManager;
  39. $this->evm->addEventSubscriber($this->tree);
  40. $this->em = $this->getMockSqliteEntityManager(array(
  41. 'Mapping\Fixture\Xml\ClosureTree',
  42. 'Mapping\Fixture\ClosureTreeClosure'
  43. ), $chain);
  44. }
  45. public function testTreeMetadata()
  46. {
  47. $meta = $this->em->getClassMetadata('Mapping\Fixture\Xml\ClosureTree');
  48. $config = $this->tree->getConfiguration($this->em, $meta->name);
  49. $this->assertArrayHasKey('strategy', $config);
  50. $this->assertEquals('closure', $config['strategy']);
  51. $this->assertArrayHasKey('closure', $config);
  52. $this->assertEquals('Mapping\Fixture\ClosureTreeClosure', $config['closure']);
  53. $this->assertArrayHasKey('parent', $config);
  54. $this->assertEquals('parent', $config['parent']);
  55. }
  56. }