|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ArpTest\LaminasDoctrineFixtures\Service\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Arp\LaminasDoctrineFixtures\Service\Repository\ReferenceRepository; |
|
8
|
|
|
use Doctrine\Persistence\ObjectManager; |
|
9
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @covers \Arp\LaminasDoctrineFixtures\Service\Repository\ReferenceRepository |
|
14
|
|
|
* |
|
15
|
|
|
* @author Alex Patterson <[email protected]> |
|
16
|
|
|
* @package ArpTest\LaminasDoctrineFixtures\Service\Repository |
|
17
|
|
|
*/ |
|
18
|
|
|
final class ReferenceRepositoryTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var ObjectManager&MockObject |
|
22
|
|
|
*/ |
|
23
|
|
|
private $objectManager; |
|
24
|
|
|
|
|
25
|
|
|
public function setUp(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->objectManager = $this->getMockForAbstractClass(ObjectManager::class); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Assert that the ReferenceRepository is of type ReferenceRepository |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testExtendsReferenceRepository(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$referenceRepository = new ReferenceRepository($this->objectManager); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertInstanceOf(ReferenceRepository::class, $referenceRepository); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Assert a collection reference can be set and get on a ReferenceRepository via |
|
42
|
|
|
* setCollectionReference() and getCollectionReference() |
|
43
|
|
|
* |
|
44
|
|
|
* @throws \OutOfBoundsException |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testSetAndGetCollectionReference(): void |
|
47
|
|
|
{ |
|
48
|
|
|
/** @var ReferenceRepository&MockObject $collectionReference */ |
|
49
|
|
|
$collectionReference = $this->getMockBuilder(ReferenceRepository::class) |
|
50
|
|
|
->setConstructorArgs([$this->objectManager]) |
|
51
|
|
|
->onlyMethods(['setReference', 'getReference']) |
|
52
|
|
|
->getMock(); |
|
53
|
|
|
|
|
54
|
|
|
$collectionName = 'FooCollection'; |
|
55
|
|
|
|
|
56
|
|
|
$data = [ |
|
57
|
|
|
'A' => new \stdClass(), |
|
58
|
|
|
'B' => new \stdClass(), |
|
59
|
|
|
'C' => new \stdClass(), |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
|
|
$setReferenceArgs = $getReferenceArgs = []; |
|
63
|
|
|
foreach ($data as $index => $item) { |
|
64
|
|
|
$itemName = $collectionName . '.' . $index; |
|
65
|
|
|
$setReferenceArgs[] = [$itemName, $item]; |
|
66
|
|
|
$getReferenceArgs[] = [$itemName]; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$collectionReference->expects($this->exactly(count($setReferenceArgs))) |
|
70
|
|
|
->method('setReference') |
|
71
|
|
|
->withConsecutive(...$setReferenceArgs); |
|
72
|
|
|
|
|
73
|
|
|
$collectionReference->expects($this->exactly(count($setReferenceArgs))) |
|
74
|
|
|
->method('getReference') |
|
75
|
|
|
->withConsecutive(...$getReferenceArgs) |
|
76
|
|
|
->willReturn(...array_values($data)); |
|
77
|
|
|
|
|
78
|
|
|
$collectionReference->setCollectionReference($collectionName, $data); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertSame($data, $collectionReference->getCollectionReference($collectionName)); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|