|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <[email protected]> |
| 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\Doctrine; |
| 15 | + |
| 16 | +use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; |
| 17 | +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue6039\UserApi; |
| 18 | +use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue6039\Issue6039EntityUser; |
| 19 | +use ApiPlatform\Tests\RecreateSchemaTrait; |
| 20 | +use ApiPlatform\Tests\SetupClassResourcesTrait; |
| 21 | + |
| 22 | +final class StateOptionTest extends ApiTestCase |
| 23 | +{ |
| 24 | + use RecreateSchemaTrait; |
| 25 | + use SetupClassResourcesTrait; |
| 26 | + |
| 27 | + protected static ?bool $alwaysBootKernel = false; |
| 28 | + |
| 29 | + /** |
| 30 | + * @return class-string[] |
| 31 | + */ |
| 32 | + public static function getResources(): array |
| 33 | + { |
| 34 | + return [UserApi::class]; |
| 35 | + } |
| 36 | + |
| 37 | + public function testDtoWithEntityClassOptionCollection(): void |
| 38 | + { |
| 39 | + if ($this->isMongoDB()) { |
| 40 | + $this->markTestSkipped('This test is not for MongoDB.'); |
| 41 | + } |
| 42 | + |
| 43 | + $this->recreateSchema([Issue6039EntityUser::class]); |
| 44 | + $manager = static::getContainer()->get('doctrine')->getManager(); |
| 45 | + |
| 46 | + $user = new Issue6039EntityUser(); |
| 47 | + $user->name = 'name'; |
| 48 | + $user->bar = 'bar'; |
| 49 | + $manager->persist($user); |
| 50 | + $manager->flush(); |
| 51 | + |
| 52 | + $response = static::createClient()->request('GET', '/issue6039_user_apis', ['headers' => ['Accept' => 'application/ld+json']]); |
| 53 | + |
| 54 | + $this->assertResponseStatusCodeSame(200); |
| 55 | + $this->assertArrayNotHasKey('bar', $response->toArray()['hydra:member'][0]); |
| 56 | + } |
| 57 | +} |
0 commit comments