Skip to content

Raise yiisoft/hydrator-validator to ^2.0 #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading