Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Services/SwaggerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 15 additions & 5 deletions tests/SwaggerServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,18 +843,28 @@ 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'));

$service = app(SwaggerService::class);

$service->saveProductionData();

$this->assertFileExists($tempFilePath);
$this->assertFileEquals($this->generateFixturePath('tmp_data_merged.json'), $tempFilePath);
$this->assertTempFileEqualsFixture('tmp_data_merged');
}

public function testMergeToEmptyTempDocumentation()
{
$this->mockParallelTestingToken();

$this->fillTempFile('');

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

app(SwaggerService::class)->saveProductionData();

$this->assertTempFileEqualsFixture('tmp_data_merged_to_empty_temp_documentation');
}

public function testAddDataWhenInvokableClass()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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":""}}}
14 changes: 14 additions & 0 deletions tests/support/Traits/SwaggerServiceMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}