|
| 1 | +<?php declare(strict_types=1); |
| 2 | +/* |
| 3 | + * Copyright 2022 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\deployer\base\test\taskHider; |
| 19 | + |
| 20 | +use de\codenamephp\deployer\base\taskHider\ByTaskListAndMatchers; |
| 21 | +use de\codenamephp\deployer\base\taskMatcher\iTaskMatcher; |
| 22 | +use Deployer\Deployer; |
| 23 | +use Deployer\Task\Task; |
| 24 | +use PHPUnit\Framework\TestCase; |
| 25 | + |
| 26 | +final class ByTaskListAndMatchersTest extends TestCase { |
| 27 | + |
| 28 | + private ByTaskListAndMatchers $sut; |
| 29 | + |
| 30 | + protected function setUp() : void { |
| 31 | + parent::setUp(); |
| 32 | + |
| 33 | + $taskMatcher = $this->createMock(iTaskMatcher::class); |
| 34 | + $deployer = $this->createMock(Deployer::class); |
| 35 | + |
| 36 | + $this->sut = new ByTaskListAndMatchers($taskMatcher, $deployer); |
| 37 | + } |
| 38 | + |
| 39 | + public function test__construct() : void { |
| 40 | + $taskMatcher = $this->createMock(iTaskMatcher::class); |
| 41 | + $deployer = $this->createMock(Deployer::class); |
| 42 | + |
| 43 | + $this->sut = new ByTaskListAndMatchers($taskMatcher, $deployer); |
| 44 | + |
| 45 | + self::assertSame($taskMatcher, $this->sut->taskMatcher); |
| 46 | + self::assertSame($deployer, $this->sut->deployer); |
| 47 | + } |
| 48 | + |
| 49 | + public function testHide() : void { |
| 50 | + $task1 = $this->createMock(Task::class); |
| 51 | + $task1->expects(self::once())->method('hidden')->with(true); |
| 52 | + $task2 = $this->createMock(Task::class); |
| 53 | + $task2->expects(self::never())->method('hidden'); |
| 54 | + $task3 = $this->createMock(Task::class); |
| 55 | + $task3->expects(self::never())->method('hidden'); |
| 56 | + $task4 = $this->createMock(Task::class); |
| 57 | + $task4->expects(self::once())->method('hidden')->with(true); |
| 58 | + $task5 = $this->createMock(Task::class); |
| 59 | + $task5->expects(self::once())->method('hidden')->with(true); |
| 60 | + |
| 61 | + $this->sut->deployer = $this->createMock(Deployer::class); |
| 62 | + $this->sut->deployer->expects(self::once())->method('__get')->with('tasks')->willReturn([$task1, $task2, $task3, $task4, $task5]); |
| 63 | + |
| 64 | + $this->sut->taskMatcher = $this->createMock(iTaskMatcher::class); |
| 65 | + $this->sut->taskMatcher |
| 66 | + ->expects(self::exactly(5)) |
| 67 | + ->method('matches') |
| 68 | + ->withConsecutive([$task1], [$task2], [$task3], [$task4], [$task5]) |
| 69 | + ->willReturnOnConsecutiveCalls(true, false, false, true, true); |
| 70 | + |
| 71 | + $this->sut->hide(); |
| 72 | + } |
| 73 | +} |
0 commit comments