diff --git a/composer.json b/composer.json index 5c5528a..c708488 100644 --- a/composer.json +++ b/composer.json @@ -56,6 +56,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.47.1", + "league/container": "^4.2", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^10.0", "symfony/yaml": "^6.0|^7.0", diff --git a/src/Adapters/Slim/OpenApiResponseVerifier.php b/src/Adapters/Slim/OpenApiResponseVerifier.php index c77c392..ed83570 100644 --- a/src/Adapters/Slim/OpenApiResponseVerifier.php +++ b/src/Adapters/Slim/OpenApiResponseVerifier.php @@ -25,6 +25,8 @@ public function registerOpenApiVerifier(?App $app, ?string $specification = null $container[OpenApiVerifierMiddleware::OPENAPI_VERFIER_CONTAINER_KEY] = $this; } elseif (method_exists($container, 'set')) { $container->set(OpenApiVerifierMiddleware::OPENAPI_VERFIER_CONTAINER_KEY, $this); + } elseif (method_exists($container, 'add')) { + $container->add(OpenApiVerifierMiddleware::OPENAPI_VERFIER_CONTAINER_KEY, $this); } else { throw new \RuntimeException('Unusable container'); } diff --git a/tests/Adapters/SlimAdapterTest.php b/tests/Adapters/SlimAdapterTest.php index 5d65625..5ccf97a 100644 --- a/tests/Adapters/SlimAdapterTest.php +++ b/tests/Adapters/SlimAdapterTest.php @@ -2,11 +2,11 @@ namespace Radebatz\OpenApi\Verifier\Tests\Adapters; +use League\Container\Container; use Nyholm\Psr7\Factory\Psr17Factory; use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Psr\Container\ContainerInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Radebatz\OpenApi\Verifier\Adapters\Slim\OpenApiResponseVerifier; @@ -62,7 +62,7 @@ protected function runApp(string $requestMethod, string $requestUri, bool $valid { $request = (new Psr17Factory())->createServerRequest($requestMethod, $requestUri); - $app = AppFactory::create(container: $this->container()); + $app = AppFactory::create(container: new Container()); // register test route as we do not have an actual app... if ($valid) { @@ -95,26 +95,4 @@ protected function runApp(string $requestMethod, string $requestUri, bool $valid return $app->handle($request); } - - protected function container(): ContainerInterface - { - return new class() implements ContainerInterface { - protected $container = []; - - public function get(string $id) - { - return $this->container[$id] ?? null; - } - - public function has(string $id) - { - return array_key_exists($id, $this->container); - } - - public function set(string $id, $value) - { - $this->container[$id] = $value; - } - }; - } }