Skip to content

Commit dec2393

Browse files
Added test for sequential collection
1 parent 4fec6a7 commit dec2393

7 files changed

Lines changed: 81 additions & 3 deletions

File tree

.idea/deploymentchecks.base.iml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/phpunit.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ It's very easy to run multiple checks:
6565
```php
6666
<?php declare(strict_types=1);
6767

68-
use de\codenamephp\deploymentchecks\base\Check\Collection\SequentialCollection;
68+
use de\codenamephp\deploymentchecks\base\Check\Collection\SequentialCheckCollection;
6969
use de\codenamephp\deploymentchecks\base\Check\Result\WithExitCodeInterface;
7070
use de\codenamephp\deploymentchecks\base\ExitCode\DefaultExitCodes;
7171
use de\codenamephp\deploymentchecks\http\Check\HttpCheck;
@@ -74,7 +74,7 @@ use GuzzleHttp\Psr7\Request;
7474

7575
require_once __DIR__ . '/../vendor/autoload.php';
7676

77-
$result = (new SequentialCollection(
77+
$result = (new SequentialCheckCollection(
7878
new HttpCheck(
7979
new Request('GET', 'https://localhost'),
8080
'Frontpage should be available',

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@
5050
"composer-require-checker": "Checks for missing required composer packages",
5151
"infection": "Creates mutation tests to discover missing test coverage",
5252
"ci-all": "Runs all ci tools in sequence"
53+
},
54+
"require-dev": {
55+
"mockery/mockery": "^1.5"
5356
}
5457
}

src/Check/Collection/SequentialCollection.php renamed to src/Check/Collection/SequentialCheckCollection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424

2525
/**
2626
* Collects multiple checks and executes them sequentially and adds their results to a result collection
27+
*
28+
* @psalm-api
2729
*/
28-
final class SequentialCollection implements CheckInterface {
30+
final class SequentialCheckCollection implements CheckInterface {
2931

3032
public readonly array $checks;
3133

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)