From 7a03ee1c04294d5e3f1cda41886c5a7678043d8a Mon Sep 17 00:00:00 2001 From: Benoit Foujols Date: Thu, 8 Aug 2024 14:48:30 +0200 Subject: [PATCH] #112 del not use class --- app/Config/routes.yaml | 24 +++++++ composer.json | 3 +- composer.lock | 68 ++++++++++++++++++- .../Commands/CreateApiCommand.php | 4 ++ tests/Command/CreateApiCommandTest.php | 42 ++++++++++++ 5 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 app/Config/routes.yaml create mode 100644 tests/Command/CreateApiCommandTest.php diff --git a/app/Config/routes.yaml b/app/Config/routes.yaml new file mode 100644 index 0000000..6714cb9 --- /dev/null +++ b/app/Config/routes.yaml @@ -0,0 +1,24 @@ +index: + uri: / + controller: Controller\HomeController + httpMethod: [GET] +home: + uri: /home + controller: Controller\HomeController + httpMethod: [GET] +link: + uri: /link + controller: Controller\LinkController + httpMethod: [GET] +user: + uri: /user/{id} + controller: Controller\UserController + httpMethod: [GET,POST] +userUpdate: + uri: /user/{id}/update + controller: Controller\UserController + httpMethod: [GET,POST] +userName: + uri: /user/{id:\d+}[/{name}] + controller: Controller\UserController + httpMethod: [GET,POST] \ No newline at end of file diff --git a/composer.json b/composer.json index 2d7e433..3d9dd51 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "symfony/yaml": "6.3.*", "symfony/console": "6.3.*", "nette/php-generator": "^4.1@dev", - "zircote/swagger-php": "^4.0@dev" + "zircote/swagger-php": "^4.0@dev", + "symfony/filesystem": "7.2.x-dev" } , "require-dev": { diff --git a/composer.lock b/composer.lock index 4a66c0c..9e78059 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "37290ef989d18fa8d5ea092831fba702", + "content-hash": "7813f19d8e460380ab13e1b4ac9cccc4", "packages": [ { "name": "graham-campbell/result-type", @@ -615,6 +615,72 @@ ], "time": "2024-04-18T09:32:20+00:00" }, + { + "name": "symfony/filesystem", + "version": "7.2.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "c46c178f375c2dfddc7b6a32731077c778e14264" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/c46c178f375c2dfddc7b6a32731077c778e14264", + "reference": "c46c178f375c2dfddc7b6a32731077c778e14264", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.8" + }, + "require-dev": { + "symfony/process": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides basic utilities for the filesystem", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/filesystem/tree/7.2" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-07-23T10:47:31+00:00" + }, { "name": "symfony/finder", "version": "7.2.x-dev", diff --git a/src/EduFramework/Commands/CreateApiCommand.php b/src/EduFramework/Commands/CreateApiCommand.php index 3c5f9e0..0a76213 100644 --- a/src/EduFramework/Commands/CreateApiCommand.php +++ b/src/EduFramework/Commands/CreateApiCommand.php @@ -200,6 +200,10 @@ private function generateRoute(string $name, string $uri, string $className): ar return $router[$indexName . $name]; } + /** + * Génération du fichier de base openapi + * @return void + */ private function generateOpenApi(): void { $filename = self::CONTROLLER_DIR . self::API_DIR . 'openapi.php'; diff --git a/tests/Command/CreateApiCommandTest.php b/tests/Command/CreateApiCommandTest.php new file mode 100644 index 0000000..29fb6d4 --- /dev/null +++ b/tests/Command/CreateApiCommandTest.php @@ -0,0 +1,42 @@ +add(new CreateApiCommand()); + $command = $application->find("make:api"); + $this->commandeTester = new CommandTester($command); + } + + protected function tearDown(): void + { + $this->commandeTester = null; + (new Filesystem())->remove("app/Config/routes.yaml"); + (new Filesystem())->copy("tests/Config/routes.yaml", "app/Config/routes.yaml"); + (new Filesystem())->remove("app/Controller/api/InitController.php"); + (new Filesystem())->remove("app/Controller/api/openapi.php"); + } + + public function testCommandUri(): void + { + $this->commandeTester->execute(["controller-name" => "init"]); + $output = $this->commandeTester->getDisplay(); + + $this->assertStringContainsString('URI : /api/init', $output); + } +}