-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Flat3\Lodata\PathSegment; | ||
|
||
use Flat3\Lodata\Controller\Transaction; | ||
use Flat3\Lodata\Exception\Internal\PathNotHandledException; | ||
use Flat3\Lodata\Exception\Protocol\BadRequestException; | ||
use Flat3\Lodata\Helper\Constants; | ||
use Flat3\Lodata\Interfaces\PipeInterface; | ||
use Flat3\Lodata\Interfaces\ResponseInterface; | ||
use Illuminate\Http\Request; | ||
|
||
/** | ||
* Query | ||
* @package Flat3\Lodata\PathSegment | ||
*/ | ||
class Query implements PipeInterface | ||
{ | ||
public static function pipe( | ||
Transaction $transaction, | ||
string $currentSegment, | ||
?string $nextSegment, | ||
?PipeInterface $argument | ||
): PipeInterface { | ||
if ($currentSegment !== '$query') { | ||
throw new PathNotHandledException(); | ||
} | ||
|
||
$transaction->assertMethod(Request::METHOD_POST); | ||
|
||
if (!$argument instanceof ResponseInterface) { | ||
throw new BadRequestException('bad_argument', 'The provided argument could not provide a response'); | ||
} | ||
|
||
parse_str($transaction->getBody(), $query); | ||
$request = $transaction->getRequest(); | ||
$request->query->replace($query); | ||
$request->setContent(''); | ||
$request->setMethod(Request::METHOD_GET); | ||
$transaction->initialize($request); | ||
|
||
return $argument; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Flat3\Lodata\Tests\Unit\Protocol; | ||
|
||
use Flat3\Lodata\Tests\Request; | ||
use Flat3\Lodata\Tests\TestCase; | ||
|
||
class QueryBodyTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->withFlightModel(); | ||
} | ||
|
||
public function test_wrong_content_type() | ||
{ | ||
$this->assertNotAcceptable( | ||
Request::factory() | ||
->path('flights/$query') | ||
->post() | ||
); | ||
} | ||
|
||
public function test_wrong_method() | ||
{ | ||
$this->assertMethodNotAllowed( | ||
Request::factory() | ||
->text() | ||
->path('flights/$query') | ||
); | ||
} | ||
|
||
public function test_query() | ||
{ | ||
$this->assertJsonResponse( | ||
Request::factory() | ||
->path('flights/$query') | ||
->post() | ||
->text() | ||
->body(http_build_query([ | ||
'$count' => 'true', | ||
'$filter' => "destination eq 'lax'", | ||
])) | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/Unit/Protocol/__snapshots__/QueryBodyTest__test_query__1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"@context": "http://localhost/odata/$metadata#flights", | ||
"value": [ | ||
{ | ||
"id": 1, | ||
"origin": "lhr", | ||
"destination": "lax", | ||
"gate": null, | ||
"duration": "PT11H25M0S" | ||
}, | ||
{ | ||
"id": 3, | ||
"origin": "sfo", | ||
"destination": "lax", | ||
"gate": null, | ||
"duration": "PT35M33S" | ||
} | ||
], | ||
"@count": 2 | ||
} |
4 changes: 4 additions & 0 deletions
4
tests/Unit/Protocol/__snapshots__/QueryBodyTest__test_wrong_content_type__1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"code": "unsupported_content_type", | ||
"message": "This route does not support the requested content type, unsupported parameters may have been supplied" | ||
} |
4 changes: 4 additions & 0 deletions
4
tests/Unit/Protocol/__snapshots__/QueryBodyTest__test_wrong_method__1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"code": "method_not_allowed", | ||
"message": "The GET method is not allowed" | ||
} |