forked from api-platform/core
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(serializer): find parent class operation
fixes api-platform#5438
- Loading branch information
Showing
7 changed files
with
194 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Feature: Inheritance with correct IRIs | ||
In order to fix (https://github.com/api-platform/core/issues/5438) | ||
|
||
Scenario: Get the collection of people with its employees | ||
When I add "Accept" header equal to "application/json" | ||
And I send a "GET" request to "/people_5438" | ||
Then print last JSON response | ||
|
||
Scenario: Get the collection of people with its employees | ||
When I add "Accept" header equal to "application/ld+json" | ||
And I send a "GET" request to "/people_5438" | ||
Then print last JSON response |
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
33 changes: 33 additions & 0 deletions
33
tests/Fixtures/TestBundle/ApiResource/Issue5438/Contractor.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,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* 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\ApiResource\Issue5438; | ||
|
||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\Operation; | ||
|
||
#[Get( | ||
shortName: 'Contractor5438', | ||
uriTemplate: 'contractor_5438/{id}', | ||
provider: [Contractor::class, 'getContractor'], | ||
)] | ||
class Contractor extends Person | ||
{ | ||
public static function getContractor(Operation $operation, array $uriVariables = []): self | ||
{ | ||
return new self( | ||
$uriVariables['id'], | ||
'a' | ||
); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/Fixtures/TestBundle/ApiResource/Issue5438/Employee.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,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* 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\ApiResource\Issue5438; | ||
|
||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\Operation; | ||
|
||
#[Get( | ||
shortName: 'Employee5438', | ||
uriTemplate: 'employee_5438/{id}', | ||
provider: [Employee::class, 'getEmployee'] | ||
)] | ||
class Employee extends Person | ||
{ | ||
public static function getEmployee(Operation $operation, array $uriVariables = []): self | ||
{ | ||
return new self( | ||
$uriVariables['id'], | ||
'a' | ||
); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/Fixtures/TestBundle/ApiResource/Issue5438/Person.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,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* 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\ApiResource\Issue5438; | ||
|
||
use ApiPlatform\Metadata\GetCollection; | ||
use ApiPlatform\Metadata\Operation; | ||
|
||
#[GetCollection( | ||
shortName: 'People5438', | ||
uriTemplate: 'people_5438', | ||
provider: [Person::class, 'getData'] | ||
)] | ||
abstract class Person | ||
{ | ||
public function __construct(public readonly ?int $id = null, public readonly ?string $name = null) | ||
{ | ||
} | ||
|
||
public static function getData(Operation $operation, array $uriVariables = []): iterable | ||
{ | ||
return [ | ||
new Contractor( | ||
1, | ||
'a' | ||
), | ||
new Employee( | ||
2, | ||
'b' | ||
), | ||
]; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/Fixtures/TestBundle/Dto/ValueObjectPropertyFilter.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,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* 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\Dto; | ||
|
||
class ValueObjectPropertyFilter implements \Stringable | ||
{ | ||
public function __construct(public ?string $foo = null, public ?string $bar = null) | ||
{ | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->foo; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/Fixtures/TestBundle/Entity/DummyWithArrayOfNotResourceObjects.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,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* 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; | ||
|
||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Dto\NonResourceClass; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ApiResource(filters: ['my_dummy.property'])] | ||
#[ORM\Entity] | ||
class DummyWithArrayOfNotResourceObjects | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column(type: 'integer')] | ||
private $id; | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getNotResourceObject(): NonResourceClass | ||
{ | ||
return new NonResourceClass('foo', 'foo'); | ||
} | ||
|
||
public function getArrayOfNotResourceObjects(): array | ||
{ | ||
return [ | ||
new NonResourceClass('bar', 'bar'), | ||
new NonResourceClass('baz', 'baz'), | ||
]; | ||
} | ||
} |