ORMPurgerFactoryTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. namespace Purger;
  4. use Doctrine\Bundle\FixturesBundle\Purger\ORMPurgerFactory;
  5. use Doctrine\Common\DataFixtures\Purger\ORMPurger;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use PHPUnit\Framework\MockObject\MockObject;
  8. use PHPUnit\Framework\TestCase;
  9. class ORMPurgerFactoryTest extends TestCase
  10. {
  11. /** @var ORMPurgerFactory */
  12. private $factory;
  13. /** @var EntityManagerInterface|MockObject */
  14. private $em;
  15. protected function setUp() : void
  16. {
  17. $this->factory = new ORMPurgerFactory();
  18. $this->em = $this->createMock(EntityManagerInterface::class);
  19. }
  20. public function testCreateDefault() : void
  21. {
  22. /** @var ORMPurger $purger */
  23. $purger = $this->factory->createForEntityManager(null, $this->em);
  24. self::assertInstanceOf(ORMPurger::class, $purger);
  25. self::assertSame(ORMPurger::PURGE_MODE_DELETE, $purger->getPurgeMode());
  26. self::assertSame([], (function () {
  27. return $this->excluded;
  28. })->call($purger));
  29. }
  30. public function testCreateWithExclusions() : void
  31. {
  32. /** @var ORMPurger $purger */
  33. $purger = $this->factory->createForEntityManager(null, $this->em, ['tableName']);
  34. self::assertInstanceOf(ORMPurger::class, $purger);
  35. self::assertSame(ORMPurger::PURGE_MODE_DELETE, $purger->getPurgeMode());
  36. self::assertSame(['tableName'], (function () {
  37. return $this->excluded;
  38. })->call($purger));
  39. }
  40. public function testCreateWithTruncate() : void
  41. {
  42. /** @var ORMPurger $purger */
  43. $purger = $this->factory->createForEntityManager(null, $this->em, [], true);
  44. self::assertInstanceOf(ORMPurger::class, $purger);
  45. self::assertSame(ORMPurger::PURGE_MODE_TRUNCATE, $purger->getPurgeMode());
  46. self::assertSame([], (function () {
  47. return $this->excluded;
  48. })->call($purger));
  49. }
  50. }