Repository navigation
Expand file tree
/
Copy pathManagerRegistryConnectionFactoryTest.php
More file actions
91 lines (72 loc) · 2.73 KB
/
Copy pathManagerRegistryConnectionFactoryTest.php
File metadata and controls
91 lines (72 loc) · 2.73 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Enqueue\Dbal\Tests;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\DBAL\Connection;
use Enqueue\Dbal\DbalContext;
use Enqueue\Dbal\ManagerRegistryConnectionFactory;
use Enqueue\Test\ClassExtensionTrait;
use Interop\Queue\ConnectionFactory;
use PHPUnit\Framework\TestCase;
class ManagerRegistryConnectionFactoryTest extends TestCase
{
use ClassExtensionTrait;
public function testShouldImplementConnectionFactoryInterface()
{
$this->assertClassImplements(ConnectionFactory::class, ManagerRegistryConnectionFactory::class);
}
public function testCouldBeConstructedWithEmptyConfiguration()
{
$factory = new ManagerRegistryConnectionFactory($this->createManagerRegistryMock());
$this->assertAttributeEquals([
'lazy' => true,
'connection_name' => null,
], 'config', $factory);
}
public function testCouldBeConstructedWithCustomConfiguration()
{
$factory = new ManagerRegistryConnectionFactory($this->createManagerRegistryMock(), [
'connection_name' => 'theConnectionName',
'lazy' => false,
]);
$this->assertAttributeEquals([
'lazy' => false,
'connection_name' => 'theConnectionName',
], 'config', $factory);
}
public function testShouldCreateContext()
{
$registry = $this->createManagerRegistryMock();
$registry
->expects($this->once())
->method('getConnection')
->willReturn($this->createConnectionMock())
;
$factory = new ManagerRegistryConnectionFactory($registry, ['lazy' => false]);
$context = $factory->createContext();
$this->assertInstanceOf(DbalContext::class, $context);
$this->assertAttributeInstanceOf(Connection::class, 'connection', $context);
$this->assertAttributeSame(null, 'connectionFactory', $context);
}
public function testShouldCreateLazyContext()
{
$factory = new ManagerRegistryConnectionFactory($this->createManagerRegistryMock(), ['lazy' => true]);
$context = $factory->createContext();
$this->assertInstanceOf(DbalContext::class, $context);
$this->assertAttributeEquals(null, 'connection', $context);
$this->assertAttributeInternalType('callable', 'connectionFactory', $context);
}
/**
* @return \PHPUnit_Framework_MockObject_MockObject|ManagerRegistry
*/
private function createManagerRegistryMock()
{
return $this->createMock(ManagerRegistry::class);
}
/**
* @return \PHPUnit_Framework_MockObject_MockObject|Connection
*/
private function createConnectionMock()
{
return $this->createMock(Connection::class);
}
}