SoftDeleteableMappingTest.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Gedmo\Mapping;
  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\YamlDriver;
  8. use Gedmo\SoftDeleteable\SoftDeleteableListener;
  9. use Tool\BaseTestCaseOM;
  10. /**
  11. * These are mapping tests for SoftDeleteable extension
  12. *
  13. * @author Gustavo Falco <comfortablynumb84@gmail.com>
  14. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  15. * @package Gedmo.Mapping
  16. * @link http://www.gediminasm.org
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. class SoftDeleteableMappingTest extends BaseTestCaseOM
  20. {
  21. /**
  22. * @var Doctrine\ORM\EntityManager
  23. */
  24. private $em;
  25. /**
  26. * @var Gedmo\SoftDeleteable\SoftDeleteableListener
  27. */
  28. private $softDeleteable;
  29. public function setUp()
  30. {
  31. parent::setUp();
  32. $reader = new AnnotationReader();
  33. $annotationDriver = new AnnotationDriver($reader);
  34. $yamlDriver = new YamlDriver(__DIR__.'/Driver/Yaml');
  35. $chain = new DriverChain;
  36. $chain->addDriver($yamlDriver, 'Mapping\Fixture\Yaml');
  37. $chain->addDriver($annotationDriver, 'Mapping\Fixture');
  38. $this->softDeleteable = new SoftDeleteableListener();
  39. $this->evm = new EventManager;
  40. $this->evm->addEventSubscriber($this->softDeleteable);
  41. $this->em = $this->getMockSqliteEntityManager(array(
  42. 'Mapping\Fixture\Yaml\SoftDeleteable',
  43. 'Mapping\Fixture\SoftDeleteable'
  44. ), $chain);
  45. }
  46. public function testYamlMapping()
  47. {
  48. $meta = $this->em->getClassMetadata('Mapping\Fixture\Yaml\SoftDeleteable');
  49. $config = $this->softDeleteable->getConfiguration($this->em, $meta->name);
  50. $this->assertArrayHasKey('softDeleteable', $config);
  51. $this->assertTrue($config['softDeleteable']);
  52. $this->assertArrayHasKey('fieldName', $config);
  53. $this->assertEquals('deletedAt', $config['fieldName']);
  54. }
  55. }