Skip to content

Commit 1a0c8e0

Browse files
author
danielRConsid
committed
fix: Disable or change exit code on error
fix: add the new unit test syntax for Unitary 2
1 parent 3c770c5 commit 1a0c8e0

5 files changed

Lines changed: 23 additions & 16 deletions

File tree

src/Handlers/AbstractHandler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ abstract class AbstractHandler implements AbstractHandlerInterface
5454
* If you want Blunder to trigger a specific exit code on error,
5555
* specify the code using this method.
5656
*
57-
* @param ?int $code The exit code to use.
57+
* @param int|bool|null $code The exit code to use.
5858
* @return $this
5959
*/
60-
public function setExitCode(?int $code): self
60+
public function setExitCode(int|null|bool $code): self
6161
{
62+
if(is_bool($code)) {
63+
$code = ($code === false) ? null : 1;
64+
}
6265
self::$exitCode = $code;
6366
return $this;
6467
}

src/Interfaces/AbstractHandlerInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public function setSeverity(SeverityLevelPool $severity): self;
7878
/**
7979
* You can disable exit code 1 so Blunder can be used in test cases
8080
*
81-
* @param int $code
81+
* @param int|bool|null $code
8282
* @return $this
8383
*/
84-
public function setExitCode(int $code): self;
84+
public function setExitCode(int|null|bool $code): self;
8585
}

src/Run.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,28 @@ public function __construct(AbstractHandlerInterface $handler, ?HttpMessagingInt
3737
}
3838

3939
/**
40-
* You can disable exit code 1 so Blunder can be used in test cases
40+
* You can change exit code form default 1 on failure or disable it completely by passing null or false
4141
*
42-
* @param int $code
42+
* @param int|bool|null $code
4343
* @return $this
4444
*/
45-
public function setExitCode(int $code): self
45+
public function setExitCode(int|null|bool $code): self
4646
{
4747
$this->handler->setExitCode($code);
4848
return $this;
4949
}
5050

51+
/**
52+
* Disable exit on failure
53+
*
54+
* @return $this
55+
*/
56+
public function disableExitCode(): self
57+
{
58+
$this->handler->setExitCode(false);
59+
return $this;
60+
}
61+
5162
/**
5263
* Enable or disable the removal of the 'Location' header to prevent redirections.
5364
*

tests/unitary-blunder-event.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
// If you add true to Unit it will run in quite mode
1313
// and only report if it finds any errors!
1414

15-
$unit = new Unit();
1615

17-
$unit->case("MaplePHP Blunder event test", function ($inst) {
16+
group("MaplePHP Blunder event test", function ($inst) {
1817

1918
// SilentHandler will hide the error that I have added in this file
2019
// and is using to test the Blunder library
@@ -53,5 +52,3 @@
5352
$run->load();
5453
echo $helloworld;
5554
});
56-
57-
//$unit->execute();

tests/unitary-blunder-redirect.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
// If you add true to Unit it will run in quite mode
1212
// and only report if it finds any errors!
1313

14-
$unit = new Unit();
15-
16-
$unit->case("MaplePHP Blunder redirect test", function ($inst) {
14+
group("MaplePHP Blunder redirect test", function ($inst) {
1715

1816
// SilentHandler will hide the error that I have added in this file
1917
// and is using to test the Blunder library
@@ -41,5 +39,3 @@
4139
$run->load();
4240
echo $helloWorld;
4341
});
44-
45-
return $unit;

0 commit comments

Comments
 (0)