diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5f65788..503da53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,10 +15,6 @@ jobs: uses: ./.github/workflows/laravel.yml with: php-versions: '8.2,8.3,8.4,8.5' - call-lumen: - uses: ./.github/workflows/lumen.yml - with: - php-versions: '8.2,8.3,8.4,8.5' call-slim: uses: ./.github/workflows/slim.yml with: diff --git a/.github/workflows/lumen.yml b/.github/workflows/lumen.yml deleted file mode 100644 index 6b356fd..0000000 --- a/.github/workflows/lumen.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: lumen - -on: - workflow_call: - inputs: - php-versions: - required: true - type: string - -jobs: - test: - runs-on: ${{ matrix.operating-system }} - env: - COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}' - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - strategy: - fail-fast: true - matrix: - operating-system: [ ubuntu-latest ] - php: ${{ fromJson(format('[{0}]', inputs.php-versions)) }} - lumen: [ '10.0' ] - dependencies: [ 'highest' ] - - name: PHP ${{ matrix.php }} / Lumen ${{ matrix.lumen }} on ${{ matrix.operating-system }} with ${{ matrix.dependencies }} dependencies - - steps: - - uses: actions/checkout@v6 - name: Checkout repository - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - coverage: pcov - - - name: Install framework deps - run: | - composer require --dev laravel/lumen "^${{ matrix.lumen }}" -W - - - name: Composer install - uses: ramsey/composer-install@v4 - with: - dependency-versions: ${{ matrix.dependencies }} - composer-options: ${{ matrix.composer-options }} - - - name: PHPUnit + Code coverage - run: | - mkdir -p build/logs - vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml diff --git a/.gitignore b/.gitignore index 5928085..55640a2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ composer.lock vendor/ tests/storage/ tests/*/openapi.yaml +/.claude/settings.local.json diff --git a/README.md b/README.md index 99f8174..ea4ea4f 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ Allows to (re-)use [Swagger-PHP](https://github.com/zircote/swagger-php) attribu to configure routes in the following frameworks: * [Laravel](https://github.com/laravel/laravel) -* [Lumen](https://github.com/laravel/lumen) * [Slim](https://github.com/slimphp/Slim) diff --git a/composer.json b/composer.json index ed30ca7..1f40b64 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "php": ">=8.2", "psr/log": "^1.1 || ^2.0 || ^3.0", "psr/simple-cache": "^1.0 || ^2.0 || ^3.0", - "radebatz/openapi-extras": "^3.0 || ^4.0", + "radebatz/openapi-extras": "^4.2", "zircote/swagger-php": "^4.11.1 || ^5.0.2 || ^6.0" }, "require-dev": { diff --git a/src/Adapters/LaravelRoutingAdapter.php b/src/Adapters/LaravelRoutingAdapter.php index 5e8901b..93b220d 100644 --- a/src/Adapters/LaravelRoutingAdapter.php +++ b/src/Adapters/LaravelRoutingAdapter.php @@ -21,7 +21,6 @@ public function __construct(Application $app, array $options = []) $this->app = $app; $this->options = array_merge([ static::OPTION_AUTO_REGEX => true, - static::OPTION_NAMESPACE => 'App\\Http\\Controllers\\', ], $options); } @@ -55,9 +54,6 @@ public function register(Operation $operation, string $controller, array $parame } $controller = str_replace('::__invoke', '', $controller); - if ($namespace = $this->options[static::OPTION_NAMESPACE]) { - $controller = str_replace($namespace, '', $controller); - } /** @var Router $router */ $router = $this->app->get('router'); diff --git a/src/Adapters/LumenRoutingAdapter.php b/src/Adapters/LumenRoutingAdapter.php deleted file mode 100644 index 06b79c9..0000000 --- a/src/Adapters/LumenRoutingAdapter.php +++ /dev/null @@ -1,85 +0,0 @@ -app = $app; - $this->options = array_merge([ - static::OPTION_AUTO_REGEX => true, - static::OPTION_NAMESPACE => 'App\\Http\\Controllers\\', - ], $options); - } - - /** - * @inheritdoc - */ - public function register(Operation $operation, string $controller, array $parameters, array $custom): void - { - $path = $operation->path; - $controller = str_replace('::__invoke', '', $controller); - if ($namespace = $this->options[self::OPTION_NAMESPACE]) { - $controller = str_replace($namespace, '', $controller); - } - - /** @var Parameter $parameter */ - foreach ($parameters as $name => $parameter) { - if (!$parameter['required']) { - if (false !== strpos($path, $needle = "/{{$name}}[/{")) { - // multiple optional parameters - $path = preg_replace("#/{{$name}}(\[?.*}\])#", "[/{{$name}}$1]", $path); - } else { - $path = str_replace("/{{$name}}", "[/{{$name}}]", $path); - } - } - - switch ($parameter['type']) { - case 'regex': - if ($pattern = $parameter['pattern']) { - $path = str_replace("{{$name}}", "{{$name}:$pattern}", $path); - } - break; - - case 'integer': - if ($this->options[self::OPTION_AUTO_REGEX]) { - $path = str_replace("{{$name}}", "{{$name}:[0-9]+}", $path); - } - break; - } - } - - /** @var Router $router */ - $router = $this->app->router; - - $action = [ - 'uses' => str_replace('::', '@', $controller), - ]; - if ($custom[static::X_NAME]) { - $action['as'] = $custom[static::X_NAME]; - } - - $router->addRoute(strtoupper($operation->method), $path, $action); - } - - /** - * @inheritdoc - */ - public function registerCached(): bool - { - return false; - } -} diff --git a/src/RoutingAdapterInterface.php b/src/RoutingAdapterInterface.php index 978ca36..b98a8e7 100644 --- a/src/RoutingAdapterInterface.php +++ b/src/RoutingAdapterInterface.php @@ -13,7 +13,6 @@ interface RoutingAdapterInterface public const X_NAME = 'name'; public const X_MIDDLEWARE = 'middleware'; - public const OPTION_NAMESPACE = 'namespace'; public const OPTION_AUTO_REGEX = 'autoregex'; /** diff --git a/tests/Laravel/LaravelTest.php b/tests/Laravel/LaravelTest.php index 0913184..e2901bf 100644 --- a/tests/Laravel/LaravelTest.php +++ b/tests/Laravel/LaravelTest.php @@ -56,6 +56,6 @@ public function attributesMiddleware() $route = $this->getRouter()->getRoutes()->getByName('attributes'); $this->assertNotNull($route); - $this->assertEquals([BarMiddleware::class, FooMiddleware::class], $route->gatherMiddleware()); + $this->assertSame([FooMiddleware::class, BarMiddleware::class], $route->gatherMiddleware()); } } diff --git a/tests/Lumen/CallsApplicationTrait.php b/tests/Lumen/CallsApplicationTrait.php deleted file mode 100644 index 6158ae8..0000000 --- a/tests/Lumen/CallsApplicationTrait.php +++ /dev/null @@ -1,58 +0,0 @@ -markTestSkipped('not installed.'); - } - parent::setUp(); - } - - /** @inheritdoc */ - public function createApplication() - { - $app = new Application(); - app('config')->set([ - 'app.environment' => 'local', - 'app.debug' => true, - ]); - - $options = [ - OpenApiRouter::OPTION_OA_INFO_INJECT => true, - OpenApiRouter::OPTION_OA_OPERATION_ID_AS_NAME => true, - ]; - - (new OpenApiRouter($this->getFixtureFinder(), new LumenRoutingAdapter($app), $options)) - ->registerRoutes(); - $openapi = (new OpenApiRouter($this->getFixtureFinder(), new LumenRoutingAdapter($app), $options)) - ->scan(); - file_put_contents(__DIR__ . '/openapi.yaml', $openapi->toYaml()); - - return $app; - } - - protected function getRouter(?Application $app = null): Router - { - $app = $app ?: $this->app; - - return $app->router; - } - - public function route($name, $parameters = [], $secure = null) - { - return $this->app['url']->route($name, $parameters, $secure); - } -} diff --git a/tests/Lumen/LumenTest.php b/tests/Lumen/LumenTest.php deleted file mode 100644 index 0f32731..0000000 --- a/tests/Lumen/LumenTest.php +++ /dev/null @@ -1,51 +0,0 @@ -assertTrue(array_key_exists('invoke', $this->getRouter()->namedRoutes)); - } - - /** @test */ - public function invoke() - { - $this->get('/foo/invoke/joe'); - $this->assertEquals(200, $this->response->getStatusCode()); - } - - /** @test */ - public function prefixed() - { - $this->get($this->route('prefixed')); - $this->assertEquals(200, $this->response->getStatusCode()); - - $this->get('foo/prefixed'); - $this->assertEquals(200, $this->response->getStatusCode()); - } - - /** @test */ - public function middleware() - { - $this->get($this->route('mw')); - $this->assertEquals(200, $this->response->getStatusCode()); - } - - /** - * @test - * - * @requires PHP 8.1 - */ - public function attributesPrefixed() - { - $this->get('attributes/prefixed'); - $this->assertEquals(200, $this->response->getStatusCode()); - } -} diff --git a/tests/Lumen/LumenTestCase.php b/tests/Lumen/LumenTestCase.php deleted file mode 100644 index 64a596f..0000000 --- a/tests/Lumen/LumenTestCase.php +++ /dev/null @@ -1,13 +0,0 @@ -get($this->route('hey', ['name' => 'joe'])); - $this->assertEquals(200, $this->response->getStatusCode()); - } - - /** @test */ - public function optionalParameter() - { - $this->get($this->route('oi', ['name' => 'joe'])); - $this->assertEquals(200, $this->response->getStatusCode()); - $this->assertEquals('Oi: joe', $this->response->getContent()); - - $this->get($this->route('oi')); - $this->assertEquals(200, $this->response->getStatusCode()); - $this->assertEquals('Oi: you', $this->response->getContent()); - } - - /** @test */ - public function typedParameterMatch() - { - $this->get($this->route('id', ['id' => '123'])); - $this->assertEquals(200, $this->response->getStatusCode()); - $this->assertEquals('ID: 123', $this->response->getContent()); - } - - /** @test */ - public function typedParameterFail() - { - $this->get($this->route('id', ['id' => 'x123'])); - $this->assertEquals(404, $this->response->getStatusCode()); - } - - /** @test */ - public function regexParameterMatch() - { - $this->get($this->route('hid', ['hid' => 'a1b2c3'])); - $this->assertEquals(200, $this->response->getStatusCode()); - $this->assertEquals('HID: a1b2c3', $this->response->getContent()); - } - - /** @test */ - public function regexParameterFail() - { - $this->get($this->route('hid', ['hid' => 'za1b2c3'])); - $this->assertEquals(404, $this->response->getStatusCode()); - } -}