Skip to content

Commit e6942e6

Browse files
authored
Merge pull request #177 from RonasIT/fix-paralle-test-documntation
fix: save production data with empty temp_documentation.json
2 parents 2a8f884 + 6d21d2f commit e6942e6

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

src/Services/SwaggerService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ protected function saveTempData()
811811
public function saveProductionData()
812812
{
813813
if (ParallelTesting::token()) {
814-
$this->driver->appendProcessDataToTmpFile(function (array $sharedTmpData) {
814+
$this->driver->appendProcessDataToTmpFile(function (?array $sharedTmpData) {
815815
$resultDocContent = (empty($sharedTmpData))
816816
? $this->generateEmptyData($this->config['info']['description'])
817817
: $sharedTmpData;

tests/SwaggerServiceTest.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
use RonasIT\AutoDoc\Tests\Support\Mock\TestNotificationSetting;
1616
use RonasIT\AutoDoc\Tests\Support\Mock\TestRequest;
1717
use RonasIT\AutoDoc\Tests\Support\Traits\SwaggerServiceMockTrait;
18+
use RonasIT\AutoDoc\Tests\Support\Traits\SwaggerServiceTestingTrait;
1819
use stdClass;
1920

2021
class SwaggerServiceTest extends TestCase
2122
{
22-
use SwaggerServiceMockTrait;
23+
use SwaggerServiceMockTrait, SwaggerServiceTestingTrait;
2324

2425
public function testConstructorInvalidConfigVersion()
2526
{
@@ -857,18 +858,28 @@ public function testMergeTempDocumentation()
857858
{
858859
$this->mockParallelTestingToken();
859860

860-
$tempFilePath = __DIR__ . '/../storage/temp_documentation.json';
861-
862-
file_put_contents($tempFilePath, json_encode($this->getJsonFixture('tmp_data_post_user_request')));
861+
$this->fillTempFile($this->getFixture('tmp_data_post_user_request.json'));
863862

864863
$this->mockDriverGetTmpData($this->getJsonFixture('tmp_data_search_users_empty_request'));
865864

866865
$service = app(SwaggerService::class);
867866

868867
$service->saveProductionData();
869868

870-
$this->assertFileExists($tempFilePath);
871-
$this->assertFileEquals($this->generateFixturePath('tmp_data_merged.json'), $tempFilePath);
869+
$this->assertTempFileEqualsFixture('tmp_data_merged');
870+
}
871+
872+
public function testMergeToEmptyTempDocumentation()
873+
{
874+
$this->mockParallelTestingToken();
875+
876+
$this->fillTempFile('');
877+
878+
$this->mockDriverGetTmpData($this->getJsonFixture('tmp_data_search_users_empty_request'));
879+
880+
app(SwaggerService::class)->saveProductionData();
881+
882+
$this->assertTempFileEqualsFixture('tmp_data_merged_to_empty_temp_documentation');
872883
}
873884

874885
public function testAddDataWhenInvokableClass()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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":""}}}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace RonasIT\AutoDoc\Tests\Support\Traits;
4+
5+
use RonasIT\Support\Traits\MockTrait;
6+
7+
trait SwaggerServiceTestingTrait
8+
{
9+
use MockTrait;
10+
11+
protected function fillTempFile(string $content): void
12+
{
13+
file_put_contents(getcwd() . '/storage/temp_documentation.json', $content);
14+
}
15+
16+
protected function assertTempFileEqualsFixture(string $fixture): void
17+
{
18+
$fixture = $this->prepareFixtureName($fixture);
19+
20+
$path = $this->generateFixturePath($fixture);
21+
22+
$this->assertFileEquals($path, getcwd() . '/storage/temp_documentation.json');
23+
}
24+
}

0 commit comments

Comments
 (0)