1111use Nyholm \Psr7 \Factory \Psr17Factory ;
1212use PhpMyAdmin \Http \Factory \ResponseFactory ;
1313use PhpMyAdmin \Http \Response ;
14- use PHPUnit \Framework \Attributes \BackupStaticProperties ;
1514use PHPUnit \Framework \Attributes \CoversClass ;
1615use PHPUnit \Framework \Attributes \DataProvider ;
1716use PHPUnit \Framework \TestCase ;
2625#[CoversClass(ResponseFactory::class)]
2726final class ResponseFactoryTest extends TestCase
2827{
28+ private ReflectionProperty $ providersProperty ;
29+
30+ private mixed $ originalProviders ;
31+
32+ protected function setUp (): void
33+ {
34+ parent ::setUp ();
35+
36+ $ this ->providersProperty = new ReflectionProperty (ResponseFactory::class, 'providers ' );
37+ $ this ->originalProviders = $ this ->providersProperty ->getValue ();
38+ }
39+
40+ protected function tearDown (): void
41+ {
42+ $ this ->providersProperty ->setValue (null , $ this ->originalProviders );
43+
44+ parent ::tearDown ();
45+ }
46+
2947 /**
3048 * @psalm-param class-string<ResponseFactoryInterface> $provider
3149 * @psalm-param class-string<ResponseInterface> $expectedResponse
@@ -54,11 +72,10 @@ public static function providerForTestCreateResponse(): iterable
5472
5573 /** @psalm-param class-string<ResponseFactoryInterface> $provider */
5674 #[DataProvider('providerForTestCreate ' )]
57- #[BackupStaticProperties(true )]
5875 public function testCreate (string $ provider ): void
5976 {
6077 $ this ->skipIfNotAvailable ($ provider );
61- ( new ReflectionProperty (ResponseFactory::class, ' providers ' )) ->setValue (null , [$ provider ]);
78+ $ this -> providersProperty ->setValue (null , [$ provider ]);
6279 $ responseFactory = ResponseFactory::create ();
6380 $ actual = (new ReflectionProperty (ResponseFactory::class, 'responseFactory ' ))->getValue ($ responseFactory );
6481 self ::assertInstanceOf ($ provider , $ actual );
@@ -74,10 +91,9 @@ public static function providerForTestCreate(): iterable
7491 yield 'httpsoft/http-message ' => [HttpSoftResponseFactory::class];
7592 }
7693
77- #[BackupStaticProperties(true )]
7894 public function testCreateWithoutProvider (): void
7995 {
80- ( new ReflectionProperty (ResponseFactory::class, ' providers ' )) ->setValue (null , ['InvalidResponseFactoryClass ' ]);
96+ $ this -> providersProperty ->setValue (null , ['InvalidResponseFactoryClass ' ]);
8197 $ this ->expectException (RuntimeException::class);
8298 $ this ->expectExceptionMessage ('No HTTP response factories found. ' );
8399 ResponseFactory::create ();
0 commit comments