Skip to content

Commit

Permalink
Fix container issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann committed Nov 10, 2024
1 parent 1859a00 commit 28a938c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/Adapters/Slim/OpenApiResponseVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
26 changes: 2 additions & 24 deletions tests/Adapters/SlimAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
};
}
}

0 comments on commit 28a938c

Please sign in to comment.