forked from php-enqueue/enqueue-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoctrineConnectionFactoryFactoryTest.php
68 lines (55 loc) · 1.9 KB
/
DoctrineConnectionFactoryFactoryTest.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
<?php
declare(strict_types=1);
namespace Enqueue\Tests;
use Doctrine\Persistence\ManagerRegistry;
use Enqueue\ConnectionFactoryFactoryInterface;
use Enqueue\Dbal\ManagerRegistryConnectionFactory;
use Enqueue\Doctrine\DoctrineConnectionFactoryFactory;
use PHPUnit\Framework\TestCase;
class DoctrineConnectionFactoryFactoryTest extends TestCase
{
/**
* @var ManagerRegistry|\Prophecy\Prophecy\ObjectProphecy
*/
private $registry;
/**
* @var ConnectionFactoryFactoryInterface|\Prophecy\Prophecy\ObjectProphecy
*/
private $fallbackFactory;
/**
* @var DoctrineConnectionFactoryFactory
*/
private $factory;
protected function setUp()
{
$this->registry = $this->prophesize(ManagerRegistry::class);
$this->fallbackFactory = $this->prophesize(ConnectionFactoryFactoryInterface::class);
$this->factory = new DoctrineConnectionFactoryFactory($this->registry->reveal(), $this->fallbackFactory->reveal());
}
public function testCreateWithoutArray()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The config must be either array or DSN string.');
$this->factory->create(true);
}
public function testCreateWithoutDsn()
{
$this->expectExceptionMessage(\InvalidArgumentException::class);
$this->expectExceptionMessage('The config must have dsn key set.');
$this->factory->create(['foo' => 'bar']);
}
public function testCreateWithDoctrineSchema()
{
$this->assertInstanceOf(
ManagerRegistryConnectionFactory::class,
$this->factory->create('doctrine://localhost:3306')
);
}
public function testCreateFallback()
{
$this->fallbackFactory
->create(['dsn' => 'fallback://'])
->shouldBeCalled();
$this->factory->create(['dsn' => 'fallback://']);
}
}