-
-
Notifications
You must be signed in to change notification settings - Fork 877
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
9 changed files
with
267 additions
and
7 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
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
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,63 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\State\Provider; | ||
|
||
use ApiPlatform\Metadata\Post; | ||
use ApiPlatform\State\Provider\ContentNegotiationProvider; | ||
use ApiPlatform\State\ProviderInterface; | ||
use Negotiation\Negotiator; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Argument; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class ContentNegotiationProviderTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function testRequestWithEmptyContentType(): void | ||
{ | ||
$expectedResult = new \stdClass(); | ||
|
||
$decorated = $this->prophesize(ProviderInterface::class); | ||
$decorated->provide(Argument::cetera())->willReturn($expectedResult); | ||
|
||
$negotiator = new Negotiator(); | ||
$formats = ['jsonld' => ['application/ld+json']]; | ||
$errorFormats = ['jsonld' => ['application/ld+json']]; | ||
|
||
$provider = new ContentNegotiationProvider($decorated->reveal(), $negotiator, $formats, $errorFormats); | ||
|
||
// in Symfony (at least up to 7.0.2, 6.4.2, 6.3.11, 5.4.34), a request | ||
// without a content-type and content-length header will result in the | ||
// variables set to an empty string, not null | ||
|
||
$request = new Request( | ||
server: [ | ||
'REQUEST_METHOD' => 'POST', | ||
'REQUEST_URI' => '/', | ||
'CONTENT_TYPE' => '', | ||
'CONTENT_LENGTH' => '', | ||
], | ||
content: '' | ||
); | ||
|
||
$operation = new Post(); | ||
$context = ['request' => $request]; | ||
|
||
$result = $provider->provide($operation, [], $context); | ||
|
||
$this->assertSame($expectedResult, $result); | ||
} | ||
} |
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,63 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\State\Provider; | ||
|
||
use ApiPlatform\Metadata\Post; | ||
use ApiPlatform\Serializer\SerializerContextBuilderInterface; | ||
use ApiPlatform\State\Provider\DeserializeProvider; | ||
use ApiPlatform\State\ProviderInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Argument; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
class DeserializeProviderTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function testRequestWithEmptyContentType(): void | ||
{ | ||
$expectedResult = new \stdClass(); | ||
|
||
$decorated = $this->prophesize(ProviderInterface::class); | ||
$decorated->provide(Argument::cetera())->willReturn($expectedResult); | ||
|
||
$serializer = $this->prophesize(SerializerInterface::class); | ||
$serializerContextBuilder = $this->prophesize(SerializerContextBuilderInterface::class); | ||
|
||
$provider = new DeserializeProvider($decorated->reveal(), $serializer->reveal(), $serializerContextBuilder->reveal()); | ||
|
||
// in Symfony (at least up to 7.0.2, 6.4.2, 6.3.11, 5.4.34), a request | ||
// without a content-type and content-length header will result in the | ||
// variables set to an empty string, not null | ||
|
||
$request = new Request( | ||
server: [ | ||
'REQUEST_METHOD' => 'POST', | ||
'REQUEST_URI' => '/', | ||
'CONTENT_TYPE' => '', | ||
'CONTENT_LENGTH' => '', | ||
], | ||
content: '' | ||
); | ||
|
||
$operation = new Post(deserialize: true); | ||
$context = ['request' => $request]; | ||
|
||
$this->expectException(UnsupportedMediaTypeHttpException::class); | ||
$result = $provider->provide($operation, [], $context); | ||
} | ||
} |
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