ConnectionFactoryTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

2 Methods

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