1515
1616use ApiPlatform \Symfony \Bundle \Test \ApiTestCase ;
1717use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \FilterWithStateOptions ;
18+ use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \FilterWithStateOptionsAndNoApiFilter ;
1819use ApiPlatform \Tests \Fixtures \TestBundle \Document \SearchFilterParameter as SearchFilterParameterDocument ;
20+ use ApiPlatform \Tests \Fixtures \TestBundle \Entity \FilterWithStateOptionsAndNoApiFilterEntity ;
1921use ApiPlatform \Tests \Fixtures \TestBundle \Entity \FilterWithStateOptionsEntity ;
2022use ApiPlatform \Tests \Fixtures \TestBundle \Entity \ProductWithQueryParameter ;
2123use ApiPlatform \Tests \Fixtures \TestBundle \Entity \SearchFilterParameter ;
@@ -35,7 +37,7 @@ final class DoctrineTest extends ApiTestCase
3537 */
3638 public static function getResources (): array
3739 {
38- return [SearchFilterParameter::class, FilterWithStateOptions::class, ProductWithQueryParameter::class];
40+ return [SearchFilterParameter::class, FilterWithStateOptions::class, FilterWithStateOptionsAndNoApiFilter::class, ProductWithQueryParameter::class];
3941 }
4042
4143 public function testDoctrineEntitySearchFilter (): void
@@ -147,6 +149,38 @@ public function testStateOptions(): void
147149 $ this ->assertEquals ('after ' , $ a ['hydra:member ' ][0 ]['name ' ]);
148150 }
149151
152+ public function testStateOptionsAndNoApiFilter (): void
153+ {
154+ if ($ this ->isMongoDB ()) {
155+ $ this ->markTestSkipped ('Not tested with mongodb. ' );
156+ }
157+
158+ static ::bootKernel ();
159+ $ container = static ::$ kernel ->getContainer ();
160+ $ this ->recreateSchema ([FilterWithStateOptionsAndNoApiFilterEntity::class]);
161+ $ manager = $ container ->get ('doctrine ' )->getManager ();
162+
163+ $ d = new \DateTimeImmutable ();
164+ $ manager ->persist (new FilterWithStateOptionsAndNoApiFilterEntity (dummyDate: $ d , name: 'current ' ));
165+ $ manager ->persist (new FilterWithStateOptionsAndNoApiFilterEntity (name: 'null ' ));
166+ $ manager ->persist (new FilterWithStateOptionsAndNoApiFilterEntity (dummyDate: $ d ->add (\DateInterval::createFromDateString ('1 day ' )), name: 'after ' ));
167+ $ manager ->flush ();
168+
169+ $ response = self ::createClient ()->request ('GET ' , '/filter_with_state_options_and_no_api_filters ' );
170+ $ this ->assertResponseIsSuccessful ();
171+ $ a = $ response ->toArray ();
172+ $ this ->assertSame ('hydra:Collection ' , $ a ['@type ' ]);
173+ $ this ->assertSame (3 , $ a ['hydra:totalItems ' ]);
174+ $ this ->assertCount (3 , $ a ['hydra:member ' ]);
175+
176+ $ response = self ::createClient ()->request ('GET ' , '/filter_with_state_options_and_no_api_filters?search[name]=aft ' );
177+ $ this ->assertResponseIsSuccessful ();
178+ $ a = $ response ->toArray ();
179+ $ this ->assertSame ('hydra:Collection ' , $ a ['@type ' ]);
180+ $ this ->assertSame (1 , $ a ['hydra:totalItems ' ]);
181+ $ this ->assertCount (1 , $ a ['hydra:member ' ]);
182+ }
183+
150184 #[DataProvider('partialFilterParameterProviderForSearchFilterParameter ' )]
151185 public function testPartialSearchFilterWithSearchFilterParameter (string $ url , int $ expectedCount , array $ expectedFoos ): void
152186 {
0 commit comments