diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 170b9894..fa1d96c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,6 +73,7 @@ jobs: export PHPLIST_DATABASE_PASSWORD=${{ env.DB_PASSWORD }} export PHPLIST_DATABASE_PORT=${{ job.services.mysql.ports['3306'] }} export PHPLIST_DATABASE_HOST=127.0.0.1 + export PHPLIST_DATABASE_PATH= vendor/bin/phpunit tests/Integration/ continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8] - name: Running static analysis diff --git a/.gitignore b/.gitignore index 2c98e37b..a2318880 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ /var/ /vendor/ .phpunit.result.cache +.env +.env.dist diff --git a/composer.json b/composer.json index 17764d64..29c904a8 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ }, "require": { "php": "^8.1", - "phplist/core": "dev-main", + "phplist/core": "dev-dev", "friendsofsymfony/rest-bundle": "*", "symfony/test-pack": "^1.0", "symfony/process": "^6.4", @@ -85,6 +85,7 @@ "PhpList\\Core\\Composer\\ScriptHandler::createGeneralConfiguration", "PhpList\\Core\\Composer\\ScriptHandler::createBundleConfiguration", "PhpList\\Core\\Composer\\ScriptHandler::createRoutesConfiguration", + "PhpList\\Core\\Composer\\ScriptHandler::createDotenvConfiguration", "PhpList\\Core\\Composer\\ScriptHandler::createParametersConfiguration", "PhpList\\Core\\Composer\\ScriptHandler::clearAllCaches" ], diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 78ea4f9a..692cf4d0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,10 +5,11 @@ xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd" backupGlobals="false" colors="true" - bootstrap="vendor/autoload.php" + bootstrap="tests/bootstrap.php" > + diff --git a/src/Messaging/Controller/TemplateController.php b/src/Messaging/Controller/TemplateController.php index 9c272566..88955ba2 100644 --- a/src/Messaging/Controller/TemplateController.php +++ b/src/Messaging/Controller/TemplateController.php @@ -116,6 +116,66 @@ className: Template::class, ); } + #[Route('', name: 'create', methods: ['POST'])] + #[OA\Post( + path: '/api/v2/templates', + description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' . + 'Returns a JSON response of created template.', + summary: 'Create a new template.', + requestBody: new OA\RequestBody( + description: 'Pass session credentials', + required: true, + content: new OA\MediaType( + mediaType: 'multipart/form-data', + schema: new OA\Schema(ref: '#/components/schemas/UpdateTemplateRequest') + ) + ), + tags: ['templates'], + parameters: [ + new OA\Parameter( + name: 'php-auth-pw', + description: 'Session key obtained from login', + in: 'header', + required: true, + schema: new OA\Schema(type: 'string') + ), + ], + responses: [ + new OA\Response( + response: 201, + description: 'Success', + content: new OA\JsonContent( + type: 'array', + items: new OA\Items(ref: '#/components/schemas/Template') + ) + ), + new OA\Response( + response: 403, + description: 'Failure', + content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') + ), + new OA\Response( + response: 422, + description: 'Failure', + content: new OA\JsonContent(ref: '#/components/schemas/ValidationErrorResponse') + ), + ] + )] + public function createTemplates(Request $request): JsonResponse + { + $this->requireAuthentication($request); + + /** @var CreateTemplateRequest $createTemplateRequest */ + $createTemplateRequest = $this->validator->validate($request, CreateTemplateRequest::class); + $template = $this->templateManager->create($createTemplateRequest->getDto()); + $this->entityManager->flush(); + + return $this->json( + $this->normalizer->normalize($template), + Response::HTTP_CREATED + ); + } + #[Route('/defaults', name: 'get_defaults', methods: ['GET'])] #[OA\Get( path: '/api/v2/templates/defaults', @@ -263,66 +323,6 @@ public function getTemplate( return $this->json($this->normalizer->normalize($template), Response::HTTP_OK); } - #[Route('', name: 'create', methods: ['POST'])] - #[OA\Post( - path: '/api/v2/templates', - description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' . - 'Returns a JSON response of created template.', - summary: 'Create a new template.', - requestBody: new OA\RequestBody( - description: 'Pass session credentials', - required: true, - content: new OA\MediaType( - mediaType: 'multipart/form-data', - schema: new OA\Schema(ref: '#/components/schemas/UpdateTemplateRequest') - ) - ), - tags: ['templates'], - parameters: [ - new OA\Parameter( - name: 'php-auth-pw', - description: 'Session key obtained from login', - in: 'header', - required: true, - schema: new OA\Schema(type: 'string') - ), - ], - responses: [ - new OA\Response( - response: 201, - description: 'Success', - content: new OA\JsonContent( - type: 'array', - items: new OA\Items(ref: '#/components/schemas/Template') - ) - ), - new OA\Response( - response: 403, - description: 'Failure', - content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse') - ), - new OA\Response( - response: 422, - description: 'Failure', - content: new OA\JsonContent(ref: '#/components/schemas/ValidationErrorResponse') - ), - ] - )] - public function createTemplates(Request $request): JsonResponse - { - $this->requireAuthentication($request); - - /** @var CreateTemplateRequest $createTemplateRequest */ - $createTemplateRequest = $this->validator->validate($request, CreateTemplateRequest::class); - $template = $this->templateManager->create($createTemplateRequest->getDto()); - $this->entityManager->flush(); - - return $this->json( - $this->normalizer->normalize($template), - Response::HTTP_CREATED - ); - } - #[Route('/{templateId}', name: 'update', methods: ['PUT'])] #[OA\Put( path: '/api/v2/templates/{templateId}', diff --git a/tests/Integration/Common/Routing/RoutingTest.php b/tests/Integration/Common/Routing/RoutingTest.php index cfbe3cc3..bbab5c77 100644 --- a/tests/Integration/Common/Routing/RoutingTest.php +++ b/tests/Integration/Common/Routing/RoutingTest.php @@ -16,7 +16,7 @@ class RoutingTest extends WebTestCase public function testRootUrlHasHtmlContentType() { $client = self::createClient(); - $client->request('get', '/api/v2'); + $client->request('GET', '/api/v2', server: ['HTTP_ACCEPT' => 'text/html']); $response = $client->getResponse(); diff --git a/tests/Integration/Composer/ScriptsTest.php b/tests/Integration/Composer/ScriptsTest.php index 5b0df800..2cd0691b 100644 --- a/tests/Integration/Composer/ScriptsTest.php +++ b/tests/Integration/Composer/ScriptsTest.php @@ -29,9 +29,7 @@ private function getAbsolutePublicDirectoryPath(): string public static function publicDirectoryFilesDataProvider(): array { return [ - 'production entry point' => ['app.php'], - 'development entry point' => ['app_dev.php'], - 'testing entry point' => ['app_test.php'], + 'entry point' => ['index.php'], '.htaccess' => ['.htaccess'], ]; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..8a148f7f --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,11 @@ +bootEnv(dirname(__DIR__) . '/.env'); +}