55namespace App \Tests ;
66
77use Doctrine \ORM \EntityManagerInterface ;
8- use Symfony \Bundle \FrameworkBundle \ Test \WebTestCase ;
9- use Symfony \Component \ BrowserKit \ AbstractBrowser ;
10- use Symfony \Component \ HttpFoundation \ Response ;
8+ use ApiPlatform \ Symfony \Bundle \Test \ApiTestCase as TestCase ;
9+ use ApiPlatform \ Symfony \Bundle \ Test \ Client ;
10+ use Symfony \Contracts \ HttpClient \ ResponseInterface ;
1111
12- abstract class ApiTestCase extends WebTestCase
12+ abstract class ApiTestCase extends TestCase
1313{
14- protected ?AbstractBrowser $ client = null ;
14+
15+ protected ?Client $ client ;
1516
1617 protected function request (
1718 string $ method ,
@@ -20,29 +21,28 @@ protected function request(
2021 array $ files = [],
2122 array $ server = [],
2223 ?string $ content = null
23- ): Response {
24- $ server ['CONTENT_TYPE ' ] = $ server ['CONTENT_TYPE ' ] ?? 'application/json ' ;
25- $ server ['HTTP_ACCEPT ' ] = $ server ['HTTP_ACCEPT ' ] ?? 'application/json ' ;
26- $ server ['HTTP_AUTHORIZATION ' ] = 'client:secret ' ;
27-
24+ ): ResponseInterface {
25+
2826 if (empty ($ content ) && !empty ($ params ) && in_array ($ method , ['POST ' , 'PUT ' , 'DELETE ' , 'PATCH ' ], true )) {
2927 $ content = json_encode ($ params );
3028 }
3129
32- $ this ->client ->request ($ method , $ uri , $ params , $ files , $ server , $ content );
30+ $ headers ['Authorization ' ] = 'client:secret ' ;
31+ $ headers ['Content-Type ' ] = $ server ['CONTENT_TYPE ' ] ?? 'application/json ' ;
3332
34- /** @var Response $response */
35- $ response = $ this -> client -> getResponse ();
36-
37- return $ response ;
33+ return $ this -> client -> request ( $ method , $ uri , [
34+ ' headers ' => $ headers ,
35+ ' json ' => $ params
36+ ]) ;
3837 }
3938
4039 protected function setUp (): void
4140 {
42- if (!static ::$ booted ) {
43- $ this ->client = static ::createClient ();
44- $ this ->client ->disableReboot ();
45- }
41+ parent ::setUp ();
42+
43+ $ this ->client = static ::createClient ();
44+ // $this->client->disableReboot();
45+
4646 }
4747
4848 protected function tearDown (): void
0 commit comments