|
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
|
|
|
* @covers \AtlassianConnectBundle\Storage\DoctrineTenantStorage |
|
14
|
|
|
*/ |
|
15
|
|
|
class DoctrineTenantStorageTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var EntityManagerInterface|\PHPUnit\Framework\MockObject\MockObject |
|
19
|
|
|
*/ |
|
20
|
|
|
private $entityManager; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var DoctrineTenantStorage |
|
23
|
|
|
*/ |
|
24
|
|
|
private $doctrineTenantStorage; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
private $tenantEntityClass; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Setup properties |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function setUp(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->entityManager = $this->createMock(EntityManagerInterface::class); |
|
36
|
|
|
$this->tenantEntityClass = Tenant::class; |
|
37
|
|
|
|
|
38
|
|
|
$this->doctrineTenantStorage = new DoctrineTenantStorage( |
|
39
|
|
|
$this->entityManager, |
|
40
|
|
|
$this->tenantEntityClass |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testFindByClientKey(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$repository = $this->createMock(ObjectRepository::class); |
|
50
|
|
|
$repository |
|
51
|
|
|
->expects(static::once()) |
|
52
|
|
|
->method('findOneBy') |
|
53
|
|
|
->with(['clientKey' => 'key']); |
|
54
|
|
|
|
|
55
|
|
|
$this->entityManager |
|
56
|
|
|
->expects($this->once()) |
|
57
|
|
|
->method('getRepository') |
|
58
|
|
|
->willReturn($repository); |
|
59
|
|
|
|
|
60
|
|
|
$this->doctrineTenantStorage->findByClientKey('key'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return void |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testFindById(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$repository = $this->createMock(ObjectRepository::class); |
|
69
|
|
|
$repository |
|
70
|
|
|
->expects(static::once()) |
|
71
|
|
|
->method('find') |
|
72
|
|
|
->with(1); |
|
73
|
|
|
|
|
74
|
|
|
$this->entityManager |
|
75
|
|
|
->expects($this->once()) |
|
76
|
|
|
->method('getRepository') |
|
77
|
|
|
->willReturn($repository); |
|
78
|
|
|
|
|
79
|
|
|
$this->doctrineTenantStorage->findById(1); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return void |
|
84
|
|
|
*/ |
|
85
|
|
|
public function testPersist(): void |
|
86
|
|
|
{ |
|
87
|
|
|
$tenantClassName = $this->tenantEntityClass; |
|
88
|
|
|
$tenant = new $tenantClassName(); |
|
89
|
|
|
|
|
90
|
|
|
$this->entityManager |
|
91
|
|
|
->expects($this->once()) |
|
92
|
|
|
->method('persist') |
|
93
|
|
|
->with($tenant); |
|
94
|
|
|
|
|
95
|
|
|
$this->entityManager |
|
96
|
|
|
->expects($this->once()) |
|
97
|
|
|
->method('flush'); |
|
98
|
|
|
|
|
99
|
|
|
$this->doctrineTenantStorage->persist($tenant); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|