Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue8113;
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\JoinedInheritanceSerializerGroups;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use Doctrine\ORM\Mapping as ORM;

#[ApiResource(operations: [new Get()])]
#[ApiResource(operations: [new Get(shortName: 'JoinedInheritanceSerializerGroupsBase', uriTemplate: '/joined-inheritance-serializer-groups/base/{id}')])]
#[ORM\Entity]
#[ORM\InheritanceType('JOINED')]
#[ORM\DiscriminatorColumn(name: 'discr', type: 'string')]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue8113;
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\JoinedInheritanceSerializerGroups;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(operations: [new Get()])]
#[ApiResource(operations: [new Get(shortName: 'JoinedInheritanceSerializerGroupsBarA', uriTemplate: '/joined-inheritance-serializer-groups/bar-a/{id}')])]
#[ORM\Entity]
class BarJoinedA extends BarJoined
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue8113;
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\JoinedInheritanceSerializerGroups;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(operations: [new Get()])]
#[ApiResource(operations: [new Get(shortName: 'JoinedInheritanceSerializerGroupsBarB', uriTemplate: '/joined-inheritance-serializer-groups/bar-b/{id}')])]
#[ORM\Entity]
class BarJoinedB extends BarJoined
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue8113;
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\JoinedInheritanceSerializerGroups;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(operations: [new Get(normalizationContext: ['groups' => ['foo']])])]
#[ApiResource(operations: [new Get(shortName: 'JoinedInheritanceSerializerGroupsOwner', uriTemplate: '/joined-inheritance-serializer-groups/{id}', normalizationContext: ['groups' => ['foo']])])]
#[ORM\Entity]
class Foo
class SerializerGroupsOwner
{
#[ORM\Id]
#[ORM\Column(type: 'integer')]
Expand Down
25 changes: 13 additions & 12 deletions tests/Functional/Doctrine/JoinedInheritanceSerializerGroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
namespace ApiPlatform\Tests\Functional\Doctrine;

use ApiPlatform\Test\ApiTestCase;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue8113\BarJoined;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue8113\BarJoinedA;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue8113\BarJoinedB;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue8113\Foo;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Foo as ExistingFoo;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\JoinedInheritanceSerializerGroups\BarJoined;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\JoinedInheritanceSerializerGroups\BarJoinedA;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\JoinedInheritanceSerializerGroups\BarJoinedB;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\JoinedInheritanceSerializerGroups\SerializerGroupsOwner;
use ApiPlatform\Tests\RecreateSchemaTrait;
use ApiPlatform\Tests\SetupClassResourcesTrait;

Expand All @@ -33,7 +34,7 @@ final class JoinedInheritanceSerializerGroupsTest extends ApiTestCase
*/
public static function getResources(): array
{
return [Foo::class, BarJoined::class, BarJoinedA::class, BarJoinedB::class];
return [ExistingFoo::class, SerializerGroupsOwner::class, BarJoined::class, BarJoinedA::class, BarJoinedB::class];
}

public function testJoinedInheritanceSubclassGroupsEmbedRelation(): void
Expand All @@ -42,27 +43,27 @@ public function testJoinedInheritanceSubclassGroupsEmbedRelation(): void
$this->markTestSkipped('Not tested with mongodb.');
}

$this->recreateSchema([Foo::class, BarJoined::class, BarJoinedA::class, BarJoinedB::class]);
$this->recreateSchema([SerializerGroupsOwner::class, BarJoined::class, BarJoinedA::class, BarJoinedB::class]);

$manager = $this->getManager();
$barJoinedA = new BarJoinedA();
$barJoinedA->setY('y_value');
$manager->persist($barJoinedA);

$foo = new Foo();
$foo->setBarJoined($barJoinedA);
$manager->persist($foo);
$serializerGroupsOwner = new SerializerGroupsOwner();
$serializerGroupsOwner->setBarJoined($barJoinedA);
$manager->persist($serializerGroupsOwner);
$manager->flush();

$response = self::createClient()->request('GET', '/foos/1', [
$response = self::createClient()->request('GET', '/joined-inheritance-serializer-groups/1', [
'headers' => ['Accept' => 'application/ld+json'],
]);

$this->assertResponseIsSuccessful();
$this->assertJsonContains([
'@id' => '/foos/1',
'@id' => '/joined-inheritance-serializer-groups/1',
'barJoined' => [
'@type' => 'BarJoinedA',
'@type' => 'JoinedInheritanceSerializerGroupsBarA',
'y' => 'y_value',
],
]);
Expand Down
Loading