Skip to content

Commit 8406f70

Browse files
committed
chubbyphp/chubbyphp-parsing 2.0
1 parent 7c370ea commit 8406f70

File tree

9 files changed

+59
-26
lines changed

9 files changed

+59
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ A simple skeleton to build api's based on the [mezzio][1] framework.
1919
* [chubbyphp/chubbyphp-laminas-config-doctrine][7]: ^3.0.2
2020
* [chubbyphp/chubbyphp-laminas-config-factory][8]: ^1.4
2121
* [chubbyphp/chubbyphp-negotiation][9]: ^2.2
22-
* [chubbyphp/chubbyphp-parsing][10]: ^1.4.1
22+
* [chubbyphp/chubbyphp-parsing][10]: ^2.0
2323
* [doctrine/orm][11]: ^3.5.2
2424
* [mezzio/mezzio-fastroute][12]: ^3.13
2525
* [mezzio/mezzio][13]: ^3.21

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"chubbyphp/chubbyphp-laminas-config-doctrine": "^3.0.2",
2525
"chubbyphp/chubbyphp-laminas-config-factory": "^1.4",
2626
"chubbyphp/chubbyphp-negotiation": "^2.2",
27-
"chubbyphp/chubbyphp-parsing": "^1.4.1",
27+
"chubbyphp/chubbyphp-parsing": "^2.0",
2828
"doctrine/orm": "^3.3.2",
2929
"mezzio/mezzio-fastroute": "^3.13",
3030
"mezzio/mezzio": "^3.21",

src/RequestHandler/Api/Crud/CreateRequestHandler.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Chubbyphp\DecodeEncode\Decoder\DecoderInterface;
1111
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
1212
use Chubbyphp\HttpException\HttpException;
13-
use Chubbyphp\Parsing\ParserErrorException;
13+
use Chubbyphp\Parsing\ErrorsException;
1414
use Psr\Http\Message\ResponseFactoryInterface;
1515
use Psr\Http\Message\ResponseInterface;
1616
use Psr\Http\Message\ServerRequestInterface;
@@ -36,8 +36,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface
3636
try {
3737
/** @var ModelRequestInterface $modelRequest */
3838
$modelRequest = $this->parsing->getModelRequestSchema($request)->parse($input);
39-
} catch (ParserErrorException $e) {
40-
throw HttpException::createUnprocessableEntity(['invalidParameters' => $e->getApiProblemErrorMessages()]);
39+
} catch (ErrorsException $e) {
40+
throw HttpException::createUnprocessableEntity([
41+
'invalidParameters' => $e->errors->toApiProblemInvalidParameters(),
42+
]);
4143
}
4244

4345
$model = $modelRequest->createModel();

src/RequestHandler/Api/Crud/ListRequestHandler.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use App\Repository\RepositoryInterface;
1010
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
1111
use Chubbyphp\HttpException\HttpException;
12-
use Chubbyphp\Parsing\ParserErrorException;
12+
use Chubbyphp\Parsing\ErrorsException;
1313
use Psr\Http\Message\ResponseFactoryInterface;
1414
use Psr\Http\Message\ResponseInterface;
1515
use Psr\Http\Message\ServerRequestInterface;
@@ -33,8 +33,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface
3333
try {
3434
/** @var CollectionRequestInterface $collectionRequest */
3535
$collectionRequest = $this->parsing->getCollectionRequestSchema($request)->parse($input);
36-
} catch (ParserErrorException $e) {
37-
throw HttpException::createBadRequest(['invalidParameters' => $e->getApiProblemErrorMessages()]);
36+
} catch (ErrorsException $e) {
37+
throw HttpException::createBadRequest([
38+
'invalidParameters' => $e->errors->toApiProblemInvalidParameters(),
39+
]);
3840
}
3941

4042
$collection = $collectionRequest->createCollection();

src/RequestHandler/Api/Crud/UpdateRequestHandler.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Chubbyphp\DecodeEncode\Decoder\DecoderInterface;
1111
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
1212
use Chubbyphp\HttpException\HttpException;
13-
use Chubbyphp\Parsing\ParserErrorException;
13+
use Chubbyphp\Parsing\ErrorsException;
1414
use Psr\Http\Message\ResponseFactoryInterface;
1515
use Psr\Http\Message\ResponseInterface;
1616
use Psr\Http\Message\ServerRequestInterface;
@@ -42,8 +42,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface
4242
try {
4343
/** @var ModelModelRequestInterface $modelRequest */
4444
$modelRequest = $this->parsing->getModelRequestSchema($request)->parse($input);
45-
} catch (ParserErrorException $e) {
46-
throw HttpException::createUnprocessableEntity(['invalidParameters' => $e->getApiProblemErrorMessages()]);
45+
} catch (ErrorsException $e) {
46+
throw HttpException::createUnprocessableEntity([
47+
'invalidParameters' => $e->errors->toApiProblemInvalidParameters(),
48+
]);
4749
}
4850

4951
$model = $modelRequest->updateModel($model);

tests/Unit/Parsing/PetParsingTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use App\Parsing\PetParsing;
1010
use Chubbyphp\Mock\MockMethod\WithReturn;
1111
use Chubbyphp\Mock\MockObjectBuilder;
12+
use Chubbyphp\Parsing\ErrorsException;
1213
use Chubbyphp\Parsing\Parser;
13-
use Chubbyphp\Parsing\ParserErrorException;
1414
use Mezzio\Router\RouterInterface;
1515
use PHPUnit\Framework\TestCase;
1616
use Psr\Http\Message\ServerRequestInterface;
@@ -370,7 +370,7 @@ public function testGetModelRequestSchema(): void
370370
]);
371371

372372
throw new \Exception('Expect fail');
373-
} catch (ParserErrorException $e) {
373+
} catch (ErrorsException $e) {
374374
self::assertSame([
375375
[
376376
'name' => 'name',
@@ -399,7 +399,7 @@ public function testGetModelRequestSchema(): void
399399
'given' => 0,
400400
],
401401
],
402-
], $e->getApiProblemErrorMessages());
402+
], $e->errors->toApiProblemInvalidParameters());
403403
}
404404
}
405405

tests/Unit/RequestHandler/Api/Crud/CreateRequestHandlerTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
use Chubbyphp\Mock\MockMethod\WithReturn;
1717
use Chubbyphp\Mock\MockMethod\WithReturnSelf;
1818
use Chubbyphp\Mock\MockObjectBuilder;
19-
use Chubbyphp\Parsing\ParserErrorException;
19+
use Chubbyphp\Parsing\Error;
20+
use Chubbyphp\Parsing\ErrorsException;
2021
use Chubbyphp\Parsing\Schema\ObjectSchemaInterface;
2122
use PHPUnit\Framework\TestCase;
2223
use Psr\Http\Message\ResponseFactoryInterface;
@@ -33,7 +34,7 @@ final class CreateRequestHandlerTest extends TestCase
3334
{
3435
public function testWithParsingError(): void
3536
{
36-
$parserErrorException = new ParserErrorException();
37+
$errorsException = new ErrorsException(new Error('code', 'template', []));
3738

3839
$inputAsStdClass = new \stdClass();
3940
$inputAsStdClass->name = 'test';
@@ -61,7 +62,7 @@ public function testWithParsingError(): void
6162

6263
/** @var ObjectSchemaInterface $modelRequestSchema */
6364
$modelRequestSchema = $builder->create(ObjectSchemaInterface::class, [
64-
new WithException('parse', [$inputAsArray], $parserErrorException),
65+
new WithException('parse', [$inputAsArray], $errorsException),
6566
]);
6667

6768
/** @var ParsingInterface $parsing */
@@ -96,7 +97,15 @@ public function testWithParsingError(): void
9697
'title' => 'Unprocessable Entity',
9798
'detail' => null,
9899
'instance' => null,
99-
'invalidParameters' => [],
100+
'invalidParameters' => [
101+
[
102+
'name' => '',
103+
'reason' => 'template',
104+
'details' => [
105+
'_template' => 'template',
106+
],
107+
],
108+
],
100109
], $e->jsonSerialize());
101110
}
102111
}

tests/Unit/RequestHandler/Api/Crud/ListRequestHandlerTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
use Chubbyphp\Mock\MockMethod\WithReturn;
1717
use Chubbyphp\Mock\MockMethod\WithReturnSelf;
1818
use Chubbyphp\Mock\MockObjectBuilder;
19-
use Chubbyphp\Parsing\ParserErrorException;
19+
use Chubbyphp\Parsing\Error;
20+
use Chubbyphp\Parsing\ErrorsException;
2021
use Chubbyphp\Parsing\Schema\ObjectSchemaInterface;
2122
use PHPUnit\Framework\TestCase;
2223
use Psr\Http\Message\ResponseFactoryInterface;
@@ -33,7 +34,7 @@ final class ListRequestHandlerTest extends TestCase
3334
{
3435
public function testWithParsingError(): void
3536
{
36-
$parserErrorException = new ParserErrorException();
37+
$errorsException = new ErrorsException(new Error('code', 'template', []));
3738

3839
$queryAsStdClass = new \stdClass();
3940
$queryAsStdClass->name = 'test';
@@ -48,7 +49,7 @@ public function testWithParsingError(): void
4849
]);
4950

5051
$collectionRequestSchema = $builder->create(ObjectSchemaInterface::class, [
51-
new WithException('parse', [$queryAsArray], $parserErrorException),
52+
new WithException('parse', [$queryAsArray], $errorsException),
5253
]);
5354

5455
/** @var ParsingInterface $parsing */
@@ -82,7 +83,15 @@ public function testWithParsingError(): void
8283
'title' => 'Bad Request',
8384
'detail' => null,
8485
'instance' => null,
85-
'invalidParameters' => [],
86+
'invalidParameters' => [
87+
[
88+
'name' => '',
89+
'reason' => 'template',
90+
'details' => [
91+
'_template' => 'template',
92+
],
93+
],
94+
],
8695
], $e->jsonSerialize());
8796
}
8897
}

tests/Unit/RequestHandler/Api/Crud/UpdateRequestHandlerTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
use Chubbyphp\Mock\MockMethod\WithReturn;
1717
use Chubbyphp\Mock\MockMethod\WithReturnSelf;
1818
use Chubbyphp\Mock\MockObjectBuilder;
19-
use Chubbyphp\Parsing\ParserErrorException;
19+
use Chubbyphp\Parsing\Error;
20+
use Chubbyphp\Parsing\ErrorsException;
2021
use Chubbyphp\Parsing\Schema\ObjectSchemaInterface;
2122
use PHPUnit\Framework\TestCase;
2223
use Psr\Http\Message\ResponseFactoryInterface;
@@ -122,7 +123,7 @@ public function testResourceNotFoundMissingModel(): void
122123

123124
public function testWithParsingError(): void
124125
{
125-
$parserErrorException = new ParserErrorException();
126+
$errorsException = new ErrorsException(new Error('code', 'template', []));
126127

127128
$inputAsStdClass = new \stdClass();
128129
$inputAsStdClass->name = 'test';
@@ -154,7 +155,7 @@ public function testWithParsingError(): void
154155

155156
/** @var ObjectSchemaInterface $modelRequestSchema */
156157
$modelRequestSchema = $builder->create(ObjectSchemaInterface::class, [
157-
new WithException('parse', [$inputAsArray], $parserErrorException),
158+
new WithException('parse', [$inputAsArray], $errorsException),
158159
]);
159160

160161
/** @var ParsingInterface $parsing */
@@ -192,7 +193,15 @@ public function testWithParsingError(): void
192193
'title' => 'Unprocessable Entity',
193194
'detail' => null,
194195
'instance' => null,
195-
'invalidParameters' => [],
196+
'invalidParameters' => [
197+
[
198+
'name' => '',
199+
'reason' => 'template',
200+
'details' => [
201+
'_template' => 'template',
202+
],
203+
],
204+
],
196205
], $e->jsonSerialize());
197206
}
198207
}

0 commit comments

Comments
 (0)