SoftDeleteableMappingTest.php 2.1 KB

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. * @link http://www.gediminasm.org
  16. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  17. */
  18. class SoftDeleteableMappingTest extends BaseTestCaseOM
  19. {
  20. /**
  21. * @var Doctrine\ORM\EntityManager
  22. */
  23. private $em;
  24. /**
  25. * @var Gedmo\SoftDeleteable\SoftDeleteableListener
  26. */
  27. private $softDeleteable;
  28. public function setUp()
  29. {
  30. parent::setUp();
  31. $reader = new AnnotationReader();
  32. $annotationDriver = new AnnotationDriver($reader);
  33. $yamlDriver = new YamlDriver(__DIR__.'/Driver/Yaml');
  34. $chain = new DriverChain;
  35. $chain->addDriver($yamlDriver, 'Mapping\Fixture\Yaml');
  36. $chain->addDriver($annotationDriver, 'Mapping\Fixture');
  37. $this->softDeleteable = new SoftDeleteableListener();
  38. $this->evm = new EventManager;
  39. $this->evm->addEventSubscriber($this->softDeleteable);
  40. $this->em = $this->getMockSqliteEntityManager(array(
  41. 'Mapping\Fixture\Yaml\SoftDeleteable',
  42. 'Mapping\Fixture\SoftDeleteable'
  43. ), $chain);
  44. }
  45. public function testYamlMapping()
  46. {
  47. $meta = $this->em->getClassMetadata('Mapping\Fixture\Yaml\SoftDeleteable');
  48. $config = $this->softDeleteable->getConfiguration($this->em, $meta->name);
  49. $this->assertArrayHasKey('softDeleteable', $config);
  50. $this->assertTrue($config['softDeleteable']);
  51. $this->assertArrayHasKey('timeAware', $config);
  52. $this->assertFalse($config['timeAware']);
  53. $this->assertArrayHasKey('fieldName', $config);
  54. $this->assertEquals('deletedAt', $config['fieldName']);
  55. }
  56. }