Skip to content

Commit

Permalink
Raise yiisoft/hydrator-validator to ^2.0 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Mar 7, 2024
1 parent 5b229f4 commit b3327ed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"psr/http-server-middleware": "^1.0",
"yiisoft/arrays": "^3.0",
"yiisoft/hydrator": "^1.0",
"yiisoft/hydrator-validator": "^1.0",
"yiisoft/hydrator-validator": "^2.0",
"yiisoft/middleware-dispatcher": "^5.1",
"yiisoft/validator": "^1.1",
"yiisoft/request-provider": "^1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/RequestInputParametersResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private function processValidation(mixed $value): void
}

$result = $value->getValidationResult();
if ($result !== null && !$result->isValid()) {
if (!$result->isValid()) {
throw new InputValidationException($result);
}
}
Expand Down
14 changes: 9 additions & 5 deletions tests/RequestInputParametersResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Input\Http\Tests;

use Closure;
use LogicException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
Expand Down Expand Up @@ -98,8 +99,11 @@ public function testWithNonValidatingHydrator(): void
$input = $result['input'];

$this->assertInstanceOf(PersonInput::class, $input);
$this->assertNull($input->getValidationResult());
$this->assertSame('Bo', $input->name);

$this->expectException(LogicException::class);
$this->expectExceptionMessage('Validation result is not set.');
$input->getValidationResult();
}

public function testDoNotThrowExceptionForNonValidatedInput(): void
Expand Down Expand Up @@ -141,7 +145,7 @@ public function testDoNotThrowExceptionForValidInput(): void
$this->assertSame('Bo', $result['input']->name);
}

public function testDoNotThrowExceptionForValidatedInputWithoutValidation(): void
public function testValidatedInputWithoutValidation(): void
{
$request = $this->createMock(ServerRequestInterface::class);
$request->method('getQueryParams')->willReturn(['name' => 'Bo']);
Expand All @@ -153,9 +157,9 @@ public function testDoNotThrowExceptionForValidatedInputWithoutValidation(): voi
);
$parameters = TestHelper::getParameters(static fn(PersonInput $input) => null);

$result = $resolver->resolve($parameters, $request);

$this->assertSame('Bo', $result['input']->name);
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Validation result is not set.');
$resolver->resolve($parameters, $request);
}

public function testThrowExceptionForInvalidInput(): void
Expand Down

0 comments on commit b3327ed

Please sign in to comment.