From 5420edd1b8d9fae75e714f4b408b511111925844 Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikob Date: Wed, 30 Jul 2025 13:28:48 +0500 Subject: [PATCH 1/8] fix: save production data with empty temp_documentation.json --- src/Services/SwaggerService.php | 2 +- tests/SwaggerServiceTest.php | 17 ++ ...ta_merged_to_empty_temp_documentation.json | 149 ++++++++++++++++++ 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/SwaggerServiceTest/tmp_data_merged_to_empty_temp_documentation.json diff --git a/src/Services/SwaggerService.php b/src/Services/SwaggerService.php index fe0ec1b..068997a 100644 --- a/src/Services/SwaggerService.php +++ b/src/Services/SwaggerService.php @@ -811,7 +811,7 @@ protected function saveTempData() public function saveProductionData() { if (ParallelTesting::token()) { - $this->driver->appendProcessDataToTmpFile(function (array $sharedTmpData) { + $this->driver->appendProcessDataToTmpFile(function (?array $sharedTmpData) { $resultDocContent = (empty($sharedTmpData)) ? $this->generateEmptyData($this->config['info']['description']) : $sharedTmpData; diff --git a/tests/SwaggerServiceTest.php b/tests/SwaggerServiceTest.php index bef5d33..ca670c3 100644 --- a/tests/SwaggerServiceTest.php +++ b/tests/SwaggerServiceTest.php @@ -857,6 +857,23 @@ public function testMergeTempDocumentation() $this->assertFileEquals($this->generateFixturePath('tmp_data_merged.json'), $tempFilePath); } + public function testMergeTempDocumentationTempDocumentationIsEmpty() + { + $this->mockParallelTestingToken(); + + $tempFilePath = __DIR__ . '/../storage/temp_documentation.json'; + + file_put_contents($tempFilePath, ''); + + $this->mockDriverGetTmpData($this->getJsonFixture('tmp_data_search_users_empty_request')); + + app(SwaggerService::class)->saveProductionData(); + + $this->assertFileExists($tempFilePath); + $this->assertFileEquals($this->generateFixturePath('tmp_data_merged_to_empty_temp_documentation.json'), $tempFilePath); + } + + public function testAddDataWhenInvokableClass() { $this->mockDriverGetEmptyAndSaveProcessTmpData($this->getJsonFixture('tmp_data_get_user_request_invoke')); diff --git a/tests/fixtures/SwaggerServiceTest/tmp_data_merged_to_empty_temp_documentation.json b/tests/fixtures/SwaggerServiceTest/tmp_data_merged_to_empty_temp_documentation.json new file mode 100644 index 0000000..b86e97a --- /dev/null +++ b/tests/fixtures/SwaggerServiceTest/tmp_data_merged_to_empty_temp_documentation.json @@ -0,0 +1,149 @@ +{ + "openapi": "3.1.0", + "servers": [ + { + "url": "http:\/\/localhost" + } + ], + "paths": { + "\/api\/users": { + "get": { + "tags": [ + "api" + ], + "produces": [ + "application\/json" + ], + "parameters": [], + "responses": { + "200": { + "description": "OK", + "content": { + "application\/json": { + "schema": { + "$ref": "#\/components\/schemas\/getApiusers200ResponseObject", + "type": "object" + }, + "example": { + "current_page": 1, + "data": [ + { + "id": 1, + "first_name": "Billy", + "last_name": "Coleman", + "email": "billy.coleman@example.com", + "created_at": null, + "updated_at": null, + "role_id": 1, + "date_of_birth": "1986-05-20", + "phone": "+79535482530", + "position": "admin", + "starts_on": "2022-04-16 00:00:00", + "hr_id": null, + "manager_id": null, + "lead_id": null, + "avatar_id": null, + "deleted_at": null, + "company_id": 1 + } + ], + "first_page_url": "http:\/\/localhost\/api\/users?page=1", + "from": 1, + "last_page": 1, + "last_page_url": "http:\/\/localhost\/api\/users?page=1", + "links": [ + { + "url": null, + "label": "« Previous", + "active": false + }, + { + "url": "http:\/\/localhost\/api\/users?page=1", + "label": "1", + "active": true + }, + { + "url": null, + "label": "Next »", + "active": false + } + ], + "next_page_url": null, + "path": "http:\/\/localhost\/api\/users", + "per_page": 20, + "prev_page_url": null, + "to": 1, + "total": 1 + } + } + } + } + }, + "security": [], + "description": "", + "consumes": [] + } + } + }, + "components": { + "schemas": { + "getApiusers200ResponseObject": { + "type": "object", + "properties": { + "current_page": { + "type": "integer" + }, + "data": { + "type": "array" + }, + "first_page_url": { + "type": "string" + }, + "from": { + "type": "integer" + }, + "last_page": { + "type": "integer" + }, + "last_page_url": { + "type": "string" + }, + "links": { + "type": "array" + }, + "next_page_url": { + "nullable": true + }, + "path": { + "type": "string" + }, + "per_page": { + "type": "integer" + }, + "prev_page_url": { + "nullable": true + }, + "to": { + "type": "integer" + }, + "total": { + "type": "integer" + } + } + } + } + }, + "info": { + "description": "This is automatically collected documentation", + "version": "0.0.0", + "title": "Name of Your Application", + "termsOfService": "", + "contact": { + "email": "your@mail.com" + }, + "license": { + "name": "", + "url": "" + } + } +} \ No newline at end of file From 0f8206e11f3a576e5e8055e85077f64be8470c28 Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikob Date: Wed, 30 Jul 2025 13:40:57 +0500 Subject: [PATCH 2/8] fix: save production data with empty temp_documentation.json --- tests/SwaggerServiceTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/SwaggerServiceTest.php b/tests/SwaggerServiceTest.php index ca670c3..4471700 100644 --- a/tests/SwaggerServiceTest.php +++ b/tests/SwaggerServiceTest.php @@ -873,7 +873,6 @@ public function testMergeTempDocumentationTempDocumentationIsEmpty() $this->assertFileEquals($this->generateFixturePath('tmp_data_merged_to_empty_temp_documentation.json'), $tempFilePath); } - public function testAddDataWhenInvokableClass() { $this->mockDriverGetEmptyAndSaveProcessTmpData($this->getJsonFixture('tmp_data_get_user_request_invoke')); From 03ff8759a1ab3816d64f8c6ed2f9bc81895ebc7f Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikob Date: Wed, 30 Jul 2025 13:48:45 +0500 Subject: [PATCH 3/8] fix: save production data with empty temp_documentation.json --- tests/SwaggerServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/SwaggerServiceTest.php b/tests/SwaggerServiceTest.php index 4471700..d67b808 100644 --- a/tests/SwaggerServiceTest.php +++ b/tests/SwaggerServiceTest.php @@ -857,7 +857,7 @@ public function testMergeTempDocumentation() $this->assertFileEquals($this->generateFixturePath('tmp_data_merged.json'), $tempFilePath); } - public function testMergeTempDocumentationTempDocumentationIsEmpty() + public function testMergeToEmptyTempDocumentation() { $this->mockParallelTestingToken(); From 3831798da6dac0bba10461c6bf7822c027b39f1d Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikob Date: Wed, 30 Jul 2025 13:53:16 +0500 Subject: [PATCH 4/8] fix: save production data with empty temp_documentation.json --- ...ta_merged_to_empty_temp_documentation.json | 150 +----------------- 1 file changed, 1 insertion(+), 149 deletions(-) diff --git a/tests/fixtures/SwaggerServiceTest/tmp_data_merged_to_empty_temp_documentation.json b/tests/fixtures/SwaggerServiceTest/tmp_data_merged_to_empty_temp_documentation.json index b86e97a..5297bc0 100644 --- a/tests/fixtures/SwaggerServiceTest/tmp_data_merged_to_empty_temp_documentation.json +++ b/tests/fixtures/SwaggerServiceTest/tmp_data_merged_to_empty_temp_documentation.json @@ -1,149 +1 @@ -{ - "openapi": "3.1.0", - "servers": [ - { - "url": "http:\/\/localhost" - } - ], - "paths": { - "\/api\/users": { - "get": { - "tags": [ - "api" - ], - "produces": [ - "application\/json" - ], - "parameters": [], - "responses": { - "200": { - "description": "OK", - "content": { - "application\/json": { - "schema": { - "$ref": "#\/components\/schemas\/getApiusers200ResponseObject", - "type": "object" - }, - "example": { - "current_page": 1, - "data": [ - { - "id": 1, - "first_name": "Billy", - "last_name": "Coleman", - "email": "billy.coleman@example.com", - "created_at": null, - "updated_at": null, - "role_id": 1, - "date_of_birth": "1986-05-20", - "phone": "+79535482530", - "position": "admin", - "starts_on": "2022-04-16 00:00:00", - "hr_id": null, - "manager_id": null, - "lead_id": null, - "avatar_id": null, - "deleted_at": null, - "company_id": 1 - } - ], - "first_page_url": "http:\/\/localhost\/api\/users?page=1", - "from": 1, - "last_page": 1, - "last_page_url": "http:\/\/localhost\/api\/users?page=1", - "links": [ - { - "url": null, - "label": "« Previous", - "active": false - }, - { - "url": "http:\/\/localhost\/api\/users?page=1", - "label": "1", - "active": true - }, - { - "url": null, - "label": "Next »", - "active": false - } - ], - "next_page_url": null, - "path": "http:\/\/localhost\/api\/users", - "per_page": 20, - "prev_page_url": null, - "to": 1, - "total": 1 - } - } - } - } - }, - "security": [], - "description": "", - "consumes": [] - } - } - }, - "components": { - "schemas": { - "getApiusers200ResponseObject": { - "type": "object", - "properties": { - "current_page": { - "type": "integer" - }, - "data": { - "type": "array" - }, - "first_page_url": { - "type": "string" - }, - "from": { - "type": "integer" - }, - "last_page": { - "type": "integer" - }, - "last_page_url": { - "type": "string" - }, - "links": { - "type": "array" - }, - "next_page_url": { - "nullable": true - }, - "path": { - "type": "string" - }, - "per_page": { - "type": "integer" - }, - "prev_page_url": { - "nullable": true - }, - "to": { - "type": "integer" - }, - "total": { - "type": "integer" - } - } - } - } - }, - "info": { - "description": "This is automatically collected documentation", - "version": "0.0.0", - "title": "Name of Your Application", - "termsOfService": "", - "contact": { - "email": "your@mail.com" - }, - "license": { - "name": "", - "url": "" - } - } -} \ No newline at end of file +{"openapi":"3.1.0","servers":[{"url":"http:\/\/localhost"}],"paths":{"\/api\/users":{"get":{"tags":["api"],"produces":["application\/json"],"parameters":[],"responses":{"200":{"description":"OK","content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/getApiusers200ResponseObject","type":"object"},"example":{"current_page":1,"data":[{"id":1,"first_name":"Billy","last_name":"Coleman","email":"billy.coleman@example.com","created_at":null,"updated_at":null,"role_id":1,"date_of_birth":"1986-05-20","phone":"+79535482530","position":"admin","starts_on":"2022-04-16 00:00:00","hr_id":null,"manager_id":null,"lead_id":null,"avatar_id":null,"deleted_at":null,"company_id":1}],"first_page_url":"http:\/\/localhost\/api\/users?page=1","from":1,"last_page":1,"last_page_url":"http:\/\/localhost\/api\/users?page=1","links":[{"url":null,"label":"« Previous","active":false},{"url":"http:\/\/localhost\/api\/users?page=1","label":"1","active":true},{"url":null,"label":"Next »","active":false}],"next_page_url":null,"path":"http:\/\/localhost\/api\/users","per_page":20,"prev_page_url":null,"to":1,"total":1}}}}},"security":[],"description":"","consumes":[]}}},"components":{"schemas":{"getApiusers200ResponseObject":{"type":"object","properties":{"current_page":{"type":"integer"},"data":{"type":"array"},"first_page_url":{"type":"string"},"from":{"type":"integer"},"last_page":{"type":"integer"},"last_page_url":{"type":"string"},"links":{"type":"array"},"next_page_url":{"nullable":true},"path":{"type":"string"},"per_page":{"type":"integer"},"prev_page_url":{"nullable":true},"to":{"type":"integer"},"total":{"type":"integer"}}}}},"info":{"description":"This is automatically collected documentation","version":"0.0.0","title":"Name of Your Application","termsOfService":"","contact":{"email":"your@mail.com"},"license":{"name":"","url":""}}} \ No newline at end of file From 9ec8d0952ad9ad1442765983fcdc2c7c1cf7ca88 Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikob Date: Fri, 22 Aug 2025 15:41:06 +0500 Subject: [PATCH 5/8] refact: fill temp file --- tests/SwaggerServiceTest.php | 14 ++++---------- tests/TestCase.php | 1 + tests/support/Traits/SwaggerServiceMockTrait.php | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/SwaggerServiceTest.php b/tests/SwaggerServiceTest.php index d67b808..a53bc86 100644 --- a/tests/SwaggerServiceTest.php +++ b/tests/SwaggerServiceTest.php @@ -843,9 +843,7 @@ public function testMergeTempDocumentation() { $this->mockParallelTestingToken(); - $tempFilePath = __DIR__ . '/../storage/temp_documentation.json'; - - file_put_contents($tempFilePath, json_encode($this->getJsonFixture('tmp_data_post_user_request'))); + $this->fillTempFile($this->getFixture('tmp_data_post_user_request.json')); $this->mockDriverGetTmpData($this->getJsonFixture('tmp_data_search_users_empty_request')); @@ -853,24 +851,20 @@ public function testMergeTempDocumentation() $service->saveProductionData(); - $this->assertFileExists($tempFilePath); - $this->assertFileEquals($this->generateFixturePath('tmp_data_merged.json'), $tempFilePath); + $this->assertTempFileEqualsFixture('tmp_data_merged'); } public function testMergeToEmptyTempDocumentation() { $this->mockParallelTestingToken(); - $tempFilePath = __DIR__ . '/../storage/temp_documentation.json'; - - file_put_contents($tempFilePath, ''); + $this->fillTempFile(''); $this->mockDriverGetTmpData($this->getJsonFixture('tmp_data_search_users_empty_request')); app(SwaggerService::class)->saveProductionData(); - $this->assertFileExists($tempFilePath); - $this->assertFileEquals($this->generateFixturePath('tmp_data_merged_to_empty_temp_documentation.json'), $tempFilePath); + $this->assertTempFileEqualsFixture('tmp_data_merged_to_empty_temp_documentation'); } public function testAddDataWhenInvokableClass() diff --git a/tests/TestCase.php b/tests/TestCase.php index fde97e9..da3146c 100755 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -214,4 +214,5 @@ protected function mockParallelTestingToken(string $token = 'workerID'): void { ParallelTesting::resolveTokenUsing(fn () => $token); } + } diff --git a/tests/support/Traits/SwaggerServiceMockTrait.php b/tests/support/Traits/SwaggerServiceMockTrait.php index 8c47d2b..5e532e7 100644 --- a/tests/support/Traits/SwaggerServiceMockTrait.php +++ b/tests/support/Traits/SwaggerServiceMockTrait.php @@ -68,4 +68,18 @@ protected function mockDriverSaveData($driverClass = LocalDriver::class): void $this->functionCall('saveData'), ]); } + + protected function fillTempFile(string $content): void + { + file_put_contents(getcwd() . '/storage/temp_documentation.json', $content); + } + + protected function assertTempFileEqualsFixture(string $fixture): void + { + $fixture = $this->prepareFixtureName($fixture); + + $path = $this->generateFixturePath($fixture); + + $this->assertFileEquals($path, getcwd() . '/storage/temp_documentation.json'); + } } From d4e25191306ffae7cbfe93e32af395953144396d Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikob Date: Fri, 22 Aug 2025 15:43:36 +0500 Subject: [PATCH 6/8] refact: fill temp file --- tests/TestCase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index da3146c..fde97e9 100755 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -214,5 +214,4 @@ protected function mockParallelTestingToken(string $token = 'workerID'): void { ParallelTesting::resolveTokenUsing(fn () => $token); } - } From c66e17fa50f729f0d107aa1d420b1db3ddb6a61d Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikob Date: Mon, 25 Aug 2025 14:46:14 +0500 Subject: [PATCH 7/8] refact: fill temp file --- tests/SwaggerServiceTest.php | 3 ++- .../Traits/SwaggerServiceMockTrait.php | 14 ----------- .../Traits/SwaggerServiceTestingTrait.php | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 tests/support/Traits/SwaggerServiceTestingTrait.php diff --git a/tests/SwaggerServiceTest.php b/tests/SwaggerServiceTest.php index a53bc86..6225a3f 100644 --- a/tests/SwaggerServiceTest.php +++ b/tests/SwaggerServiceTest.php @@ -15,11 +15,12 @@ use RonasIT\AutoDoc\Tests\Support\Mock\TestNotificationSetting; use RonasIT\AutoDoc\Tests\Support\Mock\TestRequest; use RonasIT\AutoDoc\Tests\Support\Traits\SwaggerServiceMockTrait; +use RonasIT\AutoDoc\Tests\Support\Traits\SwaggerServiceTestingTrait; use stdClass; class SwaggerServiceTest extends TestCase { - use SwaggerServiceMockTrait; + use SwaggerServiceMockTrait, SwaggerServiceTestingTrait; public function testConstructorInvalidConfigVersion() { diff --git a/tests/support/Traits/SwaggerServiceMockTrait.php b/tests/support/Traits/SwaggerServiceMockTrait.php index 5e532e7..8c47d2b 100644 --- a/tests/support/Traits/SwaggerServiceMockTrait.php +++ b/tests/support/Traits/SwaggerServiceMockTrait.php @@ -68,18 +68,4 @@ protected function mockDriverSaveData($driverClass = LocalDriver::class): void $this->functionCall('saveData'), ]); } - - protected function fillTempFile(string $content): void - { - file_put_contents(getcwd() . '/storage/temp_documentation.json', $content); - } - - protected function assertTempFileEqualsFixture(string $fixture): void - { - $fixture = $this->prepareFixtureName($fixture); - - $path = $this->generateFixturePath($fixture); - - $this->assertFileEquals($path, getcwd() . '/storage/temp_documentation.json'); - } } diff --git a/tests/support/Traits/SwaggerServiceTestingTrait.php b/tests/support/Traits/SwaggerServiceTestingTrait.php new file mode 100644 index 0000000..5c417be --- /dev/null +++ b/tests/support/Traits/SwaggerServiceTestingTrait.php @@ -0,0 +1,24 @@ +prepareFixtureName($fixture); + + $path = $this->generateFixturePath($fixture); + + $this->assertFileEquals($path, getcwd() . '/storage/temp_documentation.json'); + } +} \ No newline at end of file From 6d21d2f12c9a2e90765938071737cbe32fcd02f0 Mon Sep 17 00:00:00 2001 From: Anton Zabolotnikob Date: Mon, 25 Aug 2025 14:46:33 +0500 Subject: [PATCH 8/8] refact: fill temp file --- tests/support/Traits/SwaggerServiceTestingTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/support/Traits/SwaggerServiceTestingTrait.php b/tests/support/Traits/SwaggerServiceTestingTrait.php index 5c417be..9db8f8e 100644 --- a/tests/support/Traits/SwaggerServiceTestingTrait.php +++ b/tests/support/Traits/SwaggerServiceTestingTrait.php @@ -21,4 +21,4 @@ protected function assertTempFileEqualsFixture(string $fixture): void $this->assertFileEquals($path, getcwd() . '/storage/temp_documentation.json'); } -} \ No newline at end of file +}