|
8 | 8 | namespace Magento\CloudPatches\Test\Unit\Patch; |
9 | 9 |
|
10 | 10 | use Magento\CloudPatches\Patch\AggregatedPatchFactory; |
| 11 | +use Magento\CloudPatches\Patch\Data\AggregatedPatchInterface; |
11 | 12 | use Magento\CloudPatches\Patch\Aggregator; |
12 | 13 | use Magento\CloudPatches\Patch\Data\Patch; |
13 | 14 | use PHPUnit\Framework\MockObject\MockObject; |
@@ -37,39 +38,44 @@ protected function setUp(): void |
37 | 38 | $this->aggregator = new Aggregator($this->aggregatedPatchFactory); |
38 | 39 | } |
39 | 40 |
|
40 | | - /** |
41 | | - * Tests patch aggregation. |
42 | | - */ |
43 | | - public function testAggregate() |
44 | | - { |
45 | | - $patch1CE = $this->createPatch('MC-1', 'Patch1 CE'); |
46 | | - $patch1EE = $this->createPatch('MC-1', 'Patch1 EE'); |
47 | | - $patch1B2B = $this->createPatch('MC-1', 'Patch1 B2B'); |
48 | | - $patch2CE = $this->createPatch('MC-2', 'Patch2 CE'); |
49 | | - $patch2EE = $this->createPatch('MC-2', 'Patch2 EE'); |
50 | | - $patch3 = $this->createPatch('MC-3', 'Patch3'); |
51 | | - |
52 | | - $this->aggregatedPatchFactory->expects($this->exactly(3)) |
| 41 | + /** |
| 42 | + * Tests patch aggregation. |
| 43 | + */ |
| 44 | +public function testAggregate() |
| 45 | +{ |
| 46 | + $patch1CE = $this->createPatch('MC-1', 'Patch1 CE'); |
| 47 | + $patch1EE = $this->createPatch('MC-1', 'Patch1 EE'); |
| 48 | + $patch1B2B = $this->createPatch('MC-1', 'Patch1 B2B'); |
| 49 | + $patch2CE = $this->createPatch('MC-2', 'Patch2 CE'); |
| 50 | + $patch2EE = $this->createPatch('MC-2', 'Patch2 EE'); |
| 51 | + $patch3 = $this->createPatch('MC-3', 'Patch3'); |
| 52 | + |
| 53 | + // Mock AggregatedPatchInterface to return the patches when getPatches is called |
| 54 | + $aggregatedPatchMock1 = $this->createMock(AggregatedPatchInterface::class); |
| 55 | + $aggregatedPatchMock1->method('getRequire')->willReturn([$patch1CE, $patch1EE, $patch1B2B]); |
| 56 | + |
| 57 | + $aggregatedPatchMock2 = $this->createMock(AggregatedPatchInterface::class); |
| 58 | + $aggregatedPatchMock2->method('getRequire')->willReturn([$patch2CE, $patch2EE]); |
| 59 | + |
| 60 | + $aggregatedPatchMock3 = $this->createMock(AggregatedPatchInterface::class); |
| 61 | + $aggregatedPatchMock3->method('getRequire')->willReturn([$patch3]); |
| 62 | + |
| 63 | + // Setting up the factory mock to return AggregatedPatchInterface mocks |
| 64 | + $this->aggregatedPatchFactory->expects($this->exactly(3)) |
53 | 65 | ->method('create') |
54 | | - ->willReturnCallback(function () use (&$callCount) { |
55 | | - $callCount++; |
56 | | - if ($callCount === 1) { |
57 | | - return [$patch1CE, $patch1EE, $patch1B2B]; |
58 | | - } elseif ($callCount === 2) { |
59 | | - return [$patch2CE, $patch2EE]; |
60 | | - } elseif($callCount === 3){ |
61 | | - return [$patch3]; |
62 | | - } |
63 | | - }); |
64 | | - |
65 | | - $this->assertTrue( |
66 | | - is_array( |
67 | | - $this->aggregator->aggregate( |
68 | | - [$patch1CE, $patch1EE, $patch1B2B, $patch2CE, $patch2EE, $patch3] |
69 | | - ) |
70 | | - ) |
| 66 | + ->willReturnOnConsecutiveCalls( |
| 67 | + $aggregatedPatchMock1, // First call returns this AggregatedPatchInterface mock |
| 68 | + $aggregatedPatchMock2, // Second call returns this AggregatedPatchInterface mock |
| 69 | + $aggregatedPatchMock3 // Third call returns this AggregatedPatchInterface mock |
71 | 70 | ); |
72 | | - } |
| 71 | + |
| 72 | + $result = $this->aggregator->aggregate( |
| 73 | + [$patch1CE, $patch1EE, $patch1B2B, $patch2CE, $patch2EE, $patch3] |
| 74 | + ); |
| 75 | + |
| 76 | + $this->assertTrue(is_array($result)); |
| 77 | +} |
| 78 | + |
73 | 79 |
|
74 | 80 | /** |
75 | 81 | * Creates patch mock. |
|
0 commit comments