-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
DoctrineTransportFactoryTest.php
72 lines (61 loc) · 2.92 KB
/
DoctrineTransportFactoryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\SchemaConfig;
use Doctrine\Persistence\ConnectionRegistry;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransportFactory;
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\PostgreSqlConnection;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
class DoctrineTransportFactoryTest extends TestCase
{
public function testSupports()
{
$factory = new DoctrineTransportFactory(
$this->createMock(ConnectionRegistry::class)
);
$this->assertTrue($factory->supports('doctrine://default', []));
$this->assertFalse($factory->supports('amqp://localhost', []));
}
public function testCreateTransport()
{
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);
$schemaManager = $this->createMock(AbstractSchemaManager::class);
$schemaConfig = $this->createMock(SchemaConfig::class);
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
$registry = $this->createMock(ConnectionRegistry::class);
$registry->expects($this->once())
->method('getConnection')
->willReturn($driverConnection);
$factory = new DoctrineTransportFactory($registry);
$serializer = $this->createMock(SerializerInterface::class);
$this->assertEquals(
new DoctrineTransport(new Connection(PostgreSqlConnection::buildConfiguration('doctrine://default'), $driverConnection), $serializer),
$factory->createTransport('doctrine://default', [], $serializer)
);
}
public function testCreateTransportMustThrowAnExceptionIfManagerIsNotFound()
{
$this->expectException('Symfony\Component\Messenger\Exception\TransportException');
$this->expectExceptionMessage('Could not find Doctrine connection from Messenger DSN "doctrine://default".');
$registry = $this->createMock(ConnectionRegistry::class);
$registry->expects($this->once())
->method('getConnection')
->willReturnCallback(function () {
throw new \InvalidArgumentException();
});
$factory = new DoctrineTransportFactory($registry);
$factory->createTransport('doctrine://default', [], $this->createMock(SerializerInterface::class));
}
}