From 95a2ea2ab724bceea9b48fc3981ad2d37dbd1bac Mon Sep 17 00:00:00 2001 From: Adrian Suter Date: Wed, 5 Jun 2019 23:45:17 +0200 Subject: [PATCH] Add method to customize the response factory class --- Slim/Factory/Psr17/SlimHttpPsr17Factory.php | 11 ++++++++ .../Psr17/SlimHttpPsr17FactoryTest.php | 27 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/Factory/Psr17/SlimHttpPsr17FactoryTest.php diff --git a/Slim/Factory/Psr17/SlimHttpPsr17Factory.php b/Slim/Factory/Psr17/SlimHttpPsr17Factory.php index 59691ee82..acc85482f 100644 --- a/Slim/Factory/Psr17/SlimHttpPsr17Factory.php +++ b/Slim/Factory/Psr17/SlimHttpPsr17Factory.php @@ -27,4 +27,15 @@ public static function createDecoratedResponseFactory( ): ResponseFactoryInterface { return new static::$responseFactoryClass($responseFactory, $streamFactory); } + + /** + * Set the response factory class the method `createDecoratedResponseFactory` + * should use. + * + * @param string $responseFactoryClass + */ + public static function setResponseFactory(string $responseFactoryClass): void + { + static::$responseFactoryClass = $responseFactoryClass; + } } diff --git a/tests/Factory/Psr17/SlimHttpPsr17FactoryTest.php b/tests/Factory/Psr17/SlimHttpPsr17FactoryTest.php new file mode 100644 index 000000000..b6a5ee38a --- /dev/null +++ b/tests/Factory/Psr17/SlimHttpPsr17FactoryTest.php @@ -0,0 +1,27 @@ +setAccessible(true); + + $this->assertEquals( + 'Slim\Http\Factory\AnotherDecoratedResponseFactory', + $responseFactoryClassProperty->getValue() + ); + } +}