diff --git a/features/doctrine/issue6039/entity_class_option.feature b/features/doctrine/issue6039/entity_class_option.feature deleted file mode 100644 index 18609626a2e..00000000000 --- a/features/doctrine/issue6039/entity_class_option.feature +++ /dev/null @@ -1,12 +0,0 @@ -Feature: Test entity class option on collections - In order to retrieve a collections of resources mapped to a DTO automatically - As a client software developer - - @createSchema - @!mongodb - Scenario: Get collection - Given there are issue6039 users - And I add "Accept" header equal to "application/ld+json" - When I send a "GET" request to "/issue6039_user_apis" - Then the response status code should be 200 - And the JSON node "hydra:member[0].bar" should not exist diff --git a/tests/Functional/Doctrine/StateOptionTest.php b/tests/Functional/Doctrine/StateOptionTest.php new file mode 100644 index 00000000000..705d1e99c14 --- /dev/null +++ b/tests/Functional/Doctrine/StateOptionTest.php @@ -0,0 +1,57 @@ + + * + * 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\Functional\Doctrine; + +use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; +use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue6039\UserApi; +use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue6039\Issue6039EntityUser; +use ApiPlatform\Tests\RecreateSchemaTrait; +use ApiPlatform\Tests\SetupClassResourcesTrait; + +final class StateOptionTest extends ApiTestCase +{ + use RecreateSchemaTrait; + use SetupClassResourcesTrait; + + protected static ?bool $alwaysBootKernel = false; + + /** + * @return class-string[] + */ + public static function getResources(): array + { + return [UserApi::class]; + } + + public function testDtoWithEntityClassOptionCollection(): void + { + if ($this->isMongoDB()) { + $this->markTestSkipped('This test is not for MongoDB.'); + } + + $this->recreateSchema([Issue6039EntityUser::class]); + $manager = static::getContainer()->get('doctrine')->getManager(); + + $user = new Issue6039EntityUser(); + $user->name = 'name'; + $user->bar = 'bar'; + $manager->persist($user); + $manager->flush(); + + $response = static::createClient()->request('GET', '/issue6039_user_apis', ['headers' => ['Accept' => 'application/ld+json']]); + + $this->assertResponseStatusCodeSame(200); + $this->assertArrayNotHasKey('bar', $response->toArray()['hydra:member'][0]); + } +}