|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <dunglas@gmail.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace ApiPlatform\Tests\Functional\JsonLd; |
| 15 | + |
| 16 | +use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; |
| 17 | +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5438\Contractor; |
| 18 | +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5438\Employee; |
| 19 | +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5438\Person; |
| 20 | +use ApiPlatform\Tests\SetupClassResourcesTrait; |
| 21 | + |
| 22 | +final class InheritanceIriTest extends ApiTestCase |
| 23 | +{ |
| 24 | + use SetupClassResourcesTrait; |
| 25 | + |
| 26 | + protected static ?bool $alwaysBootKernel = false; |
| 27 | + |
| 28 | + /** |
| 29 | + * @return class-string[] |
| 30 | + */ |
| 31 | + public static function getResources(): array |
| 32 | + { |
| 33 | + return [Person::class, Contractor::class, Employee::class]; |
| 34 | + } |
| 35 | + |
| 36 | + public function testCollectionItemsUseConcreteSubtypeIris(): void |
| 37 | + { |
| 38 | + $response = self::createClient()->request('GET', '/people_5438', [ |
| 39 | + 'headers' => ['Accept' => 'application/ld+json'], |
| 40 | + ]); |
| 41 | + |
| 42 | + $this->assertResponseIsSuccessful(); |
| 43 | + $body = $response->toArray(); |
| 44 | + $this->assertSame('/contexts/People5438', $body['@context']); |
| 45 | + $this->assertSame('/people_5438', $body['@id']); |
| 46 | + $this->assertSame('hydra:Collection', $body['@type']); |
| 47 | + $this->assertSame(2, $body['hydra:totalItems']); |
| 48 | + |
| 49 | + $this->assertSame([ |
| 50 | + [ |
| 51 | + '@id' => '/contractor_5438/1', |
| 52 | + '@type' => 'Contractor', |
| 53 | + 'id' => 1, |
| 54 | + 'name' => 'a', |
| 55 | + ], |
| 56 | + [ |
| 57 | + '@id' => '/employee_5438/2', |
| 58 | + '@type' => 'Employee', |
| 59 | + 'id' => 2, |
| 60 | + 'name' => 'b', |
| 61 | + ], |
| 62 | + ], $body['hydra:member']); |
| 63 | + } |
| 64 | +} |
0 commit comments