|
| 1 | +<?php declare(strict_types=1); |
| 2 | +/* |
| 3 | + * Copyright 2023 Bastian Schwarz <bastian@codename-php.de>. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +namespace de\codenamephp\deploymentchecks\base\test\Unit\Check\Collection; |
| 19 | + |
| 20 | +use de\codenamephp\deploymentchecks\base\Check\CheckInterface; |
| 21 | +use de\codenamephp\deploymentchecks\base\Check\Collection\SequentialCheckCollection; |
| 22 | +use de\codenamephp\deploymentchecks\base\Check\Result\Collection\ResultCollection; |
| 23 | +use de\codenamephp\deploymentchecks\base\Check\Result\Collection\ResultCollectionInterface; |
| 24 | +use de\codenamephp\deploymentchecks\base\Check\Result\ResultInterface; |
| 25 | +use Mockery; |
| 26 | +use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; |
| 27 | +use PHPUnit\Framework\TestCase; |
| 28 | + |
| 29 | +final class SequentialCheckCollectionTest extends TestCase { |
| 30 | + |
| 31 | + use MockeryPHPUnitIntegration; |
| 32 | + |
| 33 | + public function test__construct() : void { |
| 34 | + $check1 = $this->createMock(CheckInterface::class); |
| 35 | + $check2 = $this->createMock(CheckInterface::class); |
| 36 | + $check3 = $this->createMock(CheckInterface::class); |
| 37 | + |
| 38 | + $collection = new SequentialCheckCollection($check1, $check2, $check3); |
| 39 | + |
| 40 | + self::assertSame([$check1, $check2, $check3], $collection->checks); |
| 41 | + self::assertInstanceOf(ResultCollection::class, $collection->resultCollection); |
| 42 | + } |
| 43 | + |
| 44 | + public function testRun() : void { |
| 45 | + $result1 = $this->createMock(ResultInterface::class); |
| 46 | + $check1 = $this->createMock(CheckInterface::class); |
| 47 | + $check1->expects(self::once())->method('run')->willReturn($result1); |
| 48 | + |
| 49 | + $result2 = $this->createMock(ResultInterface::class); |
| 50 | + $check2 = $this->createMock(CheckInterface::class); |
| 51 | + $check2->expects(self::once())->method('run')->willReturn($result2); |
| 52 | + |
| 53 | + $result3 = $this->createMock(ResultInterface::class); |
| 54 | + $check3 = $this->createMock(CheckInterface::class); |
| 55 | + $check3->expects(self::once())->method('run')->willReturn($result3); |
| 56 | + |
| 57 | + $resultCollection = Mockery::mock(ResultCollectionInterface::class); |
| 58 | + $resultCollection->expects('add')->once()->with($result1); |
| 59 | + $resultCollection->expects('add')->once()->with($result2); |
| 60 | + $resultCollection->expects('add')->once()->with($result3); |
| 61 | + |
| 62 | + $collection = new SequentialCheckCollection($check1, $check2, $check3); |
| 63 | + $collection->resultCollection = $resultCollection; |
| 64 | + |
| 65 | + self::assertSame($resultCollection, $collection->run()); |
| 66 | + } |
| 67 | +} |
0 commit comments