From fad38fc961c5a8dcb1885c4b4ba228859dfcd58f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 13 Apr 2024 11:55:11 +0200 Subject: [PATCH] Test task skipping --- .../tests/Unit/BuildTaskUnitTest.php | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/BuildTaskUnitTest.php b/packages/framework/tests/Unit/BuildTaskUnitTest.php index 41aa5ea099b..9f066185215 100644 --- a/packages/framework/tests/Unit/BuildTaskUnitTest.php +++ b/packages/framework/tests/Unit/BuildTaskUnitTest.php @@ -184,6 +184,36 @@ public function testWithExecutionTime() $this->assertSame(' in 1,234.56ms', $task->buffer[0]); } + public function testTaskSkipping() + { + $task = new BufferedTestBuildTask(); + + $task->mockHandle(function (BufferedTestBuildTask $task) { + $task->skip(); + }); + + $task->run(); + + $this->assertSame(0, $task->property('exitCode')); + $this->assertSame('Skipped', $task->buffer[1]); + $this->assertSame(' > Task was skipped', $task->buffer[2]); + } + + public function testTaskSkippingWithCustomMessage() + { + $task = new BufferedTestBuildTask(); + + $task->mockHandle(function (BufferedTestBuildTask $task) { + $task->skip('Custom reason'); + }); + + $task->run(); + + $this->assertSame(0, $task->property('exitCode')); + $this->assertSame('Skipped', $task->buffer[1]); + $this->assertSame(' > Custom reason', $task->buffer[2]); + } + public function testExceptionHandling() { $task = new BufferedTestBuildTask(); @@ -217,7 +247,7 @@ class InspectableTestBuildTask extends BuildTask public function handle(): void { if (isset($this->mockHandle)) { - ($this->mockHandle)(); + ($this->mockHandle)($this); } else { $this->wasHandled = true; }