Passed
Pull Request — master (#50)
by
unknown
06:27 queued 02:33
created

DoctrineTenantStorageTest::testFindById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 14
rs 9.9332
1
<?php declare(strict_types = 1);
2
3
namespace AtlassianConnectBundle\Tests\Service;
4
5
use AtlassianConnectBundle\Entity\Tenant;
6
use AtlassianConnectBundle\Storage\DoctrineTenantStorage;
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\Persistence\ObjectRepository;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * Class DoctrineTenantStorageTest
13
 *
14
 * @covers \AtlassianConnectBundle\Storage\DoctrineTenantStorage
15
 */
16
class DoctrineTenantStorageTest extends TestCase
17
{
18
    /**
19
     * @var EntityManagerInterface|\PHPUnit\Framework\MockObject\MockObject
20
     */
21
    private $entityManager;
22
23
    /**
24
     * @var DoctrineTenantStorage
25
     */
26
    private $doctrineTenantStorage;
27
28
    /**
29
     * @var string
30
     */
31
    private $tenantEntityClass;
32
33
    /**
34
     * Setup properties
35
     */
36
    protected function setUp(): void
37
    {
38
        $this->entityManager = $this->createMock(EntityManagerInterface::class);
39
        $this->tenantEntityClass = Tenant::class;
40
41
        $this->doctrineTenantStorage = new DoctrineTenantStorage(
42
            $this->entityManager,
43
            $this->tenantEntityClass
44
        );
45
    }
46
47
    /**
48
     * @return void
49
     */
50
    public function testFindByClientKey(): void
51
    {
52
        $repository = $this->createMock(ObjectRepository::class);
53
        $repository
54
            ->expects(static::once())
55
            ->method('findOneBy')
56
            ->with(['clientKey' => 'key']);
57
58
        $this->entityManager
59
            ->expects($this->once())
60
            ->method('getRepository')
61
            ->willReturn($repository);
62
63
        $this->doctrineTenantStorage->findByClientKey('key');
64
    }
65
66
    /**
67
     * @return void
68
     */
69
    public function testFindById(): void
70
    {
71
        $repository = $this->createMock(ObjectRepository::class);
72
        $repository
73
            ->expects(static::once())
74
            ->method('find')
75
            ->with(1);
76
77
        $this->entityManager
78
            ->expects($this->once())
79
            ->method('getRepository')
80
            ->willReturn($repository);
81
82
        $this->doctrineTenantStorage->findById(1);
83
    }
84
85
    /**
86
     * @return void
87
     */
88
    public function testPersist(): void
89
    {
90
        $tenantClassName = $this->tenantEntityClass;
91
        $tenant = new $tenantClassName();
92
93
        $this->entityManager
94
            ->expects($this->once())
95
            ->method('persist')
96
            ->with($tenant);
97
98
        $this->entityManager
99
            ->expects($this->once())
100
            ->method('flush');
101
102
        $this->doctrineTenantStorage->persist($tenant);
103
    }
104
}
105