Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Incompatibility for doctrine #988

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/enqueue/Doctrine/DoctrineConnectionFactoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Enqueue\Doctrine;

use Doctrine\Common\Persistence\ManagerRegistry;
use Enqueue\ConnectionFactoryFactoryInterface;
use Enqueue\Dbal\ManagerRegistryConnectionFactory;
use Enqueue\Dsn\Dsn;
use Interop\Queue\ConnectionFactory;
use Symfony\Bridge\Doctrine\RegistryInterface;

class DoctrineConnectionFactoryFactory implements ConnectionFactoryFactoryInterface
{
/**
* @var RegistryInterface
* @var ManagerRegistry
*/
private $doctrine;

Expand All @@ -20,7 +20,7 @@ class DoctrineConnectionFactoryFactory implements ConnectionFactoryFactoryInterf
*/
private $fallbackFactory;

public function __construct(RegistryInterface $doctrine, ConnectionFactoryFactoryInterface $fallbackFactory)
public function __construct(ManagerRegistry $doctrine, ConnectionFactoryFactoryInterface $fallbackFactory)
{
$this->doctrine = $doctrine;
$this->fallbackFactory = $fallbackFactory;
Expand Down
67 changes: 67 additions & 0 deletions pkg/enqueue/Tests/DoctrineConnectionFactoryFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

namespace Enqueue\Tests;

use Doctrine\Common\Persistence\ManagerRegistry;
use Enqueue\ConnectionFactoryFactoryInterface;
use Enqueue\Dbal\ManagerRegistryConnectionFactory;
use Enqueue\Doctrine\DoctrineConnectionFactoryFactory;

class DoctrineConnectionFactoryFactoryTest extends \PHPUnit_Framework_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://']);
}
}