Skip to content

Commit 85c005f

Browse files
committed
Fixes #984
1 parent 32d2c07 commit 85c005f

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

Diff for: pkg/enqueue/Doctrine/DoctrineConnectionFactoryFactory.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Enqueue\Doctrine;
44

5-
use Doctrine\Bundle\DoctrineBundle\Registry;
5+
use Doctrine\Common\Persistence\ManagerRegistry;
66
use Enqueue\ConnectionFactoryFactoryInterface;
77
use Enqueue\Dbal\ManagerRegistryConnectionFactory;
88
use Enqueue\Dsn\Dsn;
@@ -11,7 +11,7 @@
1111
class DoctrineConnectionFactoryFactory implements ConnectionFactoryFactoryInterface
1212
{
1313
/**
14-
* @var Registry
14+
* @var ManagerRegistry
1515
*/
1616
private $doctrine;
1717

@@ -20,7 +20,7 @@ class DoctrineConnectionFactoryFactory implements ConnectionFactoryFactoryInterf
2020
*/
2121
private $fallbackFactory;
2222

23-
public function __construct(Registry $doctrine, ConnectionFactoryFactoryInterface $fallbackFactory)
23+
public function __construct(ManagerRegistry $doctrine, ConnectionFactoryFactoryInterface $fallbackFactory)
2424
{
2525
$this->doctrine = $doctrine;
2626
$this->fallbackFactory = $fallbackFactory;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Enqueue\Tests;
6+
7+
use Doctrine\Common\Persistence\ManagerRegistry;
8+
use Enqueue\ConnectionFactoryFactoryInterface;
9+
use Enqueue\Dbal\ManagerRegistryConnectionFactory;
10+
use Enqueue\Doctrine\DoctrineConnectionFactoryFactory;
11+
12+
class DoctrineConnectionFactoryFactoryTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var ManagerRegistry|\Prophecy\Prophecy\ObjectProphecy
16+
*/
17+
private $registry;
18+
/**
19+
* @var ConnectionFactoryFactoryInterface|\Prophecy\Prophecy\ObjectProphecy
20+
*/
21+
private $fallbackFactory;
22+
/**
23+
* @var DoctrineConnectionFactoryFactory
24+
*/
25+
private $factory;
26+
27+
protected function setUp()
28+
{
29+
$this->registry = $this->prophesize(ManagerRegistry::class);
30+
$this->fallbackFactory = $this->prophesize(ConnectionFactoryFactoryInterface::class);
31+
32+
$this->factory = new DoctrineConnectionFactoryFactory($this->registry->reveal(), $this->fallbackFactory->reveal());
33+
}
34+
35+
public function testCreateWithoutArray()
36+
{
37+
$this->expectException(\InvalidArgumentException::class);
38+
$this->expectExceptionMessage('The config must be either array or DSN string.');
39+
40+
$this->factory->create(true);
41+
}
42+
43+
public function testCreateWithoutDsn()
44+
{
45+
$this->expectExceptionMessage(\InvalidArgumentException::class);
46+
$this->expectExceptionMessage('The config must have dsn key set.');
47+
48+
$this->factory->create(['foo' => 'bar']);
49+
}
50+
51+
public function testCreateWithDoctrineSchema()
52+
{
53+
$this->assertInstanceOf(
54+
ManagerRegistryConnectionFactory::class,
55+
$this->factory->create('doctrine://localhost:3306')
56+
);
57+
}
58+
59+
public function testCreateFallback()
60+
{
61+
$this->fallbackFactory
62+
->create(['dsn' => 'fallback://'])
63+
->shouldBeCalled();
64+
65+
$this->factory->create(['dsn' => 'fallback://']);
66+
}
67+
}

0 commit comments

Comments
 (0)