Passed
Push — master ( b2b84f...109e7c )
by Thomas Mauro
03:02
created

DoctrineDBALTransportFactoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 50
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\Laminas\Messenger\Test\Transport\Doctrine;
6
7
use Doctrine\DBAL\Connection;
8
use InvalidArgumentException;
9
use PHPUnit\Framework\TestCase;
10
use Prophecy\PhpUnit\ProphecyTrait;
11
use Psr\Container\ContainerInterface;
12
use Symfony\Component\Messenger\Exception\TransportException;
13
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport;
14
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
15
use TMV\Laminas\Messenger\Transport\Doctrine\DoctrineDBALTransportFactory;
16
17
class DoctrineDBALTransportFactoryTest extends TestCase
18
{
19
    use ProphecyTrait;
20
21
    public function testCreateTransport(): void
22
    {
23
        $container = $this->prophesize(ContainerInterface::class);
24
        $serializer = $this->prophesize(SerializerInterface::class);
25
26
        $dsn = 'doctrinedbal://hostname';
27
        $options = [];
28
29
        $connection = $this->prophesize(Connection::class);
30
31
        $container->get('hostname')->shouldBeCalled()->willReturn($connection->reveal());
32
33
        $factory = new DoctrineDBALTransportFactory($container->reveal());
34
35
        $transport = $factory->createTransport($dsn, $options, $serializer->reveal());
36
37
        $this->assertInstanceOf(DoctrineTransport::class, $transport);
38
    }
39
40
    public function testCreateTransportShouldFailOnConnectionNotFound(): void
41
    {
42
        $this->expectException(TransportException::class);
43
        $this->expectExceptionMessage('Could not find Doctrine connection from Messenger DSN "doctrinedbal://hostname"');
44
45
        $container = $this->prophesize(ContainerInterface::class);
46
        $serializer = $this->prophesize(SerializerInterface::class);
47
48
        $dsn = 'doctrinedbal://hostname';
49
        $options = [];
50
51
        $container->get('hostname')->shouldBeCalled()->willThrow(new InvalidArgumentException('No service'));
52
53
        $factory = new DoctrineDBALTransportFactory($container->reveal());
54
55
        $factory->createTransport($dsn, $options, $serializer->reveal());
56
    }
57
58
    public function testSupports(): void
59
    {
60
        $container = $this->prophesize(ContainerInterface::class);
61
62
        $factory = new DoctrineDBALTransportFactory($container->reveal());
63
64
        $this->assertTrue($factory->supports('doctrinedbal://hostname', []));
65
        $this->assertFalse($factory->supports('doctrinedbal2://hostname', []));
66
        $this->assertFalse($factory->supports('doctrine://hostname', []));
67
    }
68
}
69