LoadDataFixturesDoctrineCommandTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Bundle\FixturesBundle\Tests\Command;
  4. use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand;
  5. use Doctrine\Bundle\FixturesBundle\Loader\SymfonyFixturesLoader;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use PHPUnit\Framework\TestCase;
  8. use Symfony\Component\DependencyInjection\Container;
  9. use TypeError;
  10. use const PHP_VERSION_ID;
  11. use function sprintf;
  12. class LoadDataFixturesDoctrineCommandTest extends TestCase
  13. {
  14. /**
  15. * @group legacy
  16. * @expectedDeprecation Argument 2 of Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand::__construct() expects an instance of Doctrine\Persistence\ManagerRegistry, not passing it will throw a \TypeError in DoctrineFixturesBundle 4.0.
  17. */
  18. public function testInstantiatingWithoutManagerRegistry() : void
  19. {
  20. $loader = new SymfonyFixturesLoader(new Container());
  21. try {
  22. new LoadDataFixturesDoctrineCommand($loader);
  23. } catch (TypeError $e) {
  24. if (PHP_VERSION_ID >= 80000) {
  25. $this->expectExceptionMessage(
  26. <<<'MESSAGE'
  27. Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand::__construct(): Argument #1 ($doctrine) must be of type Doctrine\Persistence\ManagerRegistry, null given, called in /home/runner/work/DoctrineFixturesBundle/DoctrineFixturesBundle/Command/LoadDataFixturesDoctrineCommand.php on line 49
  28. MESSAGE
  29. );
  30. throw $e;
  31. }
  32. $this->expectExceptionMessage(sprintf(
  33. 'Argument 1 passed to Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand::__construct() must be an instance of %s, null given',
  34. ManagerRegistry::class
  35. ));
  36. throw $e;
  37. }
  38. }
  39. /**
  40. * @doesNotPerformAssertions
  41. */
  42. public function testInstantiatingWithManagerRegistry() : void
  43. {
  44. $registry = $this->createMock(ManagerRegistry::class);
  45. $loader = new SymfonyFixturesLoader(new Container());
  46. new LoadDataFixturesDoctrineCommand($loader, $registry);
  47. }
  48. }