Completed
Pull Request — master (#440)
by Alejandro
12:02
created

properServiceFallbackOccursWhenInvoked()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Common\Doctrine;
5
6
use Doctrine\DBAL\Connection;
7
use Doctrine\ORM\EntityManager;
8
use Doctrine\ORM\EntityManagerInterface;
9
use PHPUnit\Framework\TestCase;
10
use Prophecy\Prophecy\ObjectProphecy;
11
use Psr\Container\ContainerInterface;
12
use Shlinkio\Shlink\Common\Doctrine\ConnectionFactory;
13
14
class ConnectionFactoryTest extends TestCase
15
{
16
    /** @var ConnectionFactory */
17
    private $factory;
18
    /** @var ObjectProphecy */
19
    private $container;
20
    /** @var ObjectProphecy */
21
    private $em;
22
23
    public function setUp(): void
24
    {
25
        $this->container = $this->prophesize(ContainerInterface::class);
26
        $this->em = $this->prophesize(EntityManagerInterface::class);
27
        $this->container->get(EntityManager::class)->willReturn($this->em->reveal());
28
29
        $this->factory = new ConnectionFactory();
30
    }
31
32
    /** @test */
33
    public function properServiceFallbackOccursWhenInvoked(): void
34
    {
35
        $connection = $this->prophesize(Connection::class)->reveal();
36
        $getConnection = $this->em->getConnection()->willReturn($connection);
37
38
        $result = ($this->factory)($this->container->reveal());
39
40
        $this->assertSame($connection, $result);
41
        $getConnection->shouldHaveBeenCalledOnce();
42
        $this->container->get(EntityManager::class)->shouldHaveBeenCalledOnce();
43
    }
44
}
45