Completed
Pull Request — master (#440)
by Alejandro
17:40 queued 14:38
created

ConnectionFactoryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 14
c 1
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A properServiceFallbackOccursWhenInvoked() 0 10 1
A setUp() 0 7 1
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