forked from api-platform/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(serializer): json non-resource intermitent class (api-platform#5937)
fixes api-platform#5926
- Loading branch information
Showing
8 changed files
with
182 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Feature: Issue 5926 | ||
In order to reproduce the issue at https://github.com/api-platform/core/issues/5926 | ||
As a client software developer | ||
I need to be able to use every operation on a resource with non-resources embed objects | ||
|
||
@!mongodb | ||
Scenario: Create and retrieve a WriteResource | ||
When I add "Accept" header equal to "application/json" | ||
And I send a "GET" request to "/test_issue5926s/1" | ||
Then the response status code should be 200 | ||
And the response should be in JSON | ||
And the header "Content-Type" should be equal to "application/json; charset=utf-8" |
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
29 changes: 29 additions & 0 deletions
29
tests/Fixtures/TestBundle/Entity/Issue5926/ContentItemCollection.php
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,29 @@ | ||
<?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\Fixtures\TestBundle\Entity\Issue5926; | ||
|
||
class ContentItemCollection implements \IteratorAggregate | ||
{ | ||
private array $items; | ||
|
||
public function __construct(ContentItemInterface ...$items) | ||
{ | ||
$this->items = $items; | ||
} | ||
|
||
public function getIterator(): \Traversable | ||
{ | ||
return new \ArrayIterator($this->items); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/Fixtures/TestBundle/Entity/Issue5926/ContentItemInterface.php
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,18 @@ | ||
<?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\Fixtures\TestBundle\Entity\Issue5926; | ||
|
||
interface ContentItemInterface | ||
{ | ||
} |
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,36 @@ | ||
<?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\Fixtures\TestBundle\Entity\Issue5926; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
|
||
#[ApiResource] | ||
class Media | ||
{ | ||
public function __construct( | ||
private readonly string $id, | ||
private readonly string $title, | ||
) { | ||
} | ||
|
||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getTitle(): string | ||
{ | ||
return $this->title; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/Fixtures/TestBundle/Entity/Issue5926/MediaContentItem.php
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,27 @@ | ||
<?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\Fixtures\TestBundle\Entity\Issue5926; | ||
|
||
class MediaContentItem implements ContentItemInterface | ||
{ | ||
public function __construct( | ||
private readonly Media $media, | ||
) { | ||
} | ||
|
||
public function getMedia(): Media | ||
{ | ||
return $this->media; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
tests/Fixtures/TestBundle/Entity/Issue5926/TestIssue5926.php
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,56 @@ | ||
<?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\Fixtures\TestBundle\Entity\Issue5926; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\Operation; | ||
|
||
#[ApiResource( | ||
operations: [ | ||
new Get( | ||
provider: [TestIssue5926::class, 'provide'] | ||
), | ||
] | ||
)] | ||
class TestIssue5926 | ||
{ | ||
public function __construct( | ||
private readonly string $id, | ||
private readonly ?ContentItemCollection $content, | ||
) { | ||
} | ||
|
||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getContent(): ?ContentItemCollection | ||
{ | ||
return $this->content; | ||
} | ||
|
||
public static function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null | ||
{ | ||
$media = new Media('1', 'My media'); | ||
$contentItem1 = new MediaContentItem($media); | ||
$media = new Media('2', 'My media 2'); | ||
$contentItem2 = new MediaContentItem($media); | ||
|
||
$collection = new ContentItemCollection($contentItem1, $contentItem2); | ||
|
||
return new self('1', $collection); | ||
} | ||
} |