|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Enqueue\Tests; |
| 6 | + |
| 7 | +use Doctrine\Common\Persistence\ManagerRegistry; |
| 8 | +use Enqueue\ConnectionFactoryFactoryInterface; |
| 9 | +use Enqueue\Dbal\ManagerRegistryConnectionFactory; |
| 10 | +use Enqueue\Doctrine\DoctrineConnectionFactoryFactory; |
| 11 | + |
| 12 | +class DoctrineConnectionFactoryFactoryTest extends \PHPUnit_Framework_TestCase |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @var ManagerRegistry|\Prophecy\Prophecy\ObjectProphecy |
| 16 | + */ |
| 17 | + private $registry; |
| 18 | + /** |
| 19 | + * @var ConnectionFactoryFactoryInterface|\Prophecy\Prophecy\ObjectProphecy |
| 20 | + */ |
| 21 | + private $fallbackFactory; |
| 22 | + /** |
| 23 | + * @var DoctrineConnectionFactoryFactory |
| 24 | + */ |
| 25 | + private $factory; |
| 26 | + |
| 27 | + protected function setUp() |
| 28 | + { |
| 29 | + $this->registry = $this->prophesize(ManagerRegistry::class); |
| 30 | + $this->fallbackFactory = $this->prophesize(ConnectionFactoryFactoryInterface::class); |
| 31 | + |
| 32 | + $this->factory = new DoctrineConnectionFactoryFactory($this->registry->reveal(), $this->fallbackFactory->reveal()); |
| 33 | + } |
| 34 | + |
| 35 | + public function testCreateWithoutArray() |
| 36 | + { |
| 37 | + $this->expectException(\InvalidArgumentException::class); |
| 38 | + $this->expectExceptionMessage('The config must be either array or DSN string.'); |
| 39 | + |
| 40 | + $this->factory->create(true); |
| 41 | + } |
| 42 | + |
| 43 | + public function testCreateWithoutDsn() |
| 44 | + { |
| 45 | + $this->expectExceptionMessage(\InvalidArgumentException::class); |
| 46 | + $this->expectExceptionMessage('The config must have dsn key set.'); |
| 47 | + |
| 48 | + $this->factory->create(['foo' => 'bar']); |
| 49 | + } |
| 50 | + |
| 51 | + public function testCreateWithDoctrineSchema() |
| 52 | + { |
| 53 | + $this->assertInstanceOf( |
| 54 | + ManagerRegistryConnectionFactory::class, |
| 55 | + $this->factory->create('doctrine://localhost:3306') |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + public function testCreateFallback() |
| 60 | + { |
| 61 | + $this->fallbackFactory |
| 62 | + ->create(['dsn' => 'fallback://']) |
| 63 | + ->shouldBeCalled(); |
| 64 | + |
| 65 | + $this->factory->create(['dsn' => 'fallback://']); |
| 66 | + } |
| 67 | +} |
0 commit comments