|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Enqueue\Tests\Router; |
| 4 | + |
| 5 | +use Enqueue\AmqpExt\AmqpConnectionFactory; |
| 6 | +use Enqueue\Fs\FsConnectionFactory; |
| 7 | +use Enqueue\Null\NullConnectionFactory; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | + |
| 10 | +class DsnToConnectionFactoryFunctionTest extends TestCase |
| 11 | +{ |
| 12 | + public function testThrowIfDsnEmpty() |
| 13 | + { |
| 14 | + $this->expectException(\LogicException::class); |
| 15 | + $this->expectExceptionMessage('The scheme could not be parsed from DSN ""'); |
| 16 | + |
| 17 | + \Enqueue\dsn_to_connection_factory(''); |
| 18 | + } |
| 19 | + |
| 20 | + public function testThrowIfDsnMissingScheme() |
| 21 | + { |
| 22 | + $this->expectException(\LogicException::class); |
| 23 | + $this->expectExceptionMessage('The scheme could not be parsed from DSN "dsnMissingScheme"'); |
| 24 | + |
| 25 | + \Enqueue\dsn_to_connection_factory('dsnMissingScheme'); |
| 26 | + } |
| 27 | + |
| 28 | + public function testThrowIfDsnNotSupported() |
| 29 | + { |
| 30 | + $this->expectException(\LogicException::class); |
| 31 | + $this->expectExceptionMessage('The scheme "http" is not supported. Supported "file", "amqp", "null"'); |
| 32 | + |
| 33 | + \Enqueue\dsn_to_connection_factory('http://schemeNotSupported'); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @dataProvider provideDSNs |
| 38 | + * |
| 39 | + * @param mixed $dsn |
| 40 | + * @param mixed $expectedFactoryClass |
| 41 | + */ |
| 42 | + public function testReturnsExpectedFactoryInstance($dsn, $expectedFactoryClass) |
| 43 | + { |
| 44 | + $factory = \Enqueue\dsn_to_connection_factory($dsn); |
| 45 | + |
| 46 | + $this->assertInstanceOf($expectedFactoryClass, $factory); |
| 47 | + } |
| 48 | + |
| 49 | + public static function provideDSNs() |
| 50 | + { |
| 51 | + yield ['amqp://', AmqpConnectionFactory::class]; |
| 52 | + |
| 53 | + yield ['amqp://user:pass@foo/vhost', AmqpConnectionFactory::class]; |
| 54 | + |
| 55 | + yield ['file://', FsConnectionFactory::class]; |
| 56 | + |
| 57 | + yield ['file://foo/bar/baz', FsConnectionFactory::class]; |
| 58 | + |
| 59 | + yield ['null://', NullConnectionFactory::class]; |
| 60 | + } |
| 61 | +} |
0 commit comments