Skip to content

Commit c4cc70b

Browse files
committed
Fix cs
1 parent 26525b4 commit c4cc70b

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/Validation/ValidationException.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ class ValidationException extends DomainException
2323
* @param int $code [optional] The Exception code
2424
* @param Throwable|null $previous [optional] The previous throwable used for the exception chaining
2525
*/
26-
public function __construct(ValidationResult $validationResult, string $message = '', int $code = 0, Throwable $previous = null)
27-
{
26+
public function __construct(
27+
ValidationResult $validationResult,
28+
string $message = '',
29+
int $code = 0,
30+
Throwable $previous = null
31+
) {
2832
parent::__construct($message, $code, $previous);
2933

3034
$this->validationResult = $validationResult;

tests/ValidationExceptionTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Odan\Validation\ValidationException;
66
use PHPUnit\Framework\TestCase;
7+
use RuntimeException;
78

89
/**
910
* Tests.
@@ -50,7 +51,13 @@ public function testValidationFailedAction()
5051
*/
5152
protected function withJson($data): string
5253
{
53-
return json_encode($data);
54+
$result = json_encode($data);
55+
56+
if ($result === false) {
57+
throw new RuntimeException('Json encoding failed');
58+
}
59+
60+
return $result;
5461
}
5562

5663
/**

tests/ValidationResultTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ public function testErrorsWithMessage()
9090
$result = $val->isFailed();
9191
$this->assertTrue($result);
9292
$expected = ['field' => 'email', 'message' => 'required', 'code' => '5000'];
93+
$firstError = $val->getFirstError();
9394

94-
$this->assertEquals($expected, $val->getFirstError()->toArray());
95+
$this->assertEquals($expected, $firstError ? $firstError->toArray() : null);
9596
}
9697

9798
/**
@@ -112,7 +113,9 @@ public function testAddErrorMessage()
112113

113114
$expected = ['field' => 'email', 'message' => 'required', 'code' => '5000'];
114115

115-
$this->assertEquals($expected, $val->getFirstError()->toArray());
116+
$firstError = $val->getFirstError();
117+
118+
$this->assertEquals($expected, $firstError ? $firstError->toArray() : null);
116119
}
117120

118121
/**

0 commit comments

Comments
 (0)