Skip to content

Commit 9ec8d09

Browse files
committed
refact: fill temp file
1 parent 3831798 commit 9ec8d09

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

tests/SwaggerServiceTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -843,34 +843,28 @@ public function testMergeTempDocumentation()
843843
{
844844
$this->mockParallelTestingToken();
845845

846-
$tempFilePath = __DIR__ . '/../storage/temp_documentation.json';
847-
848-
file_put_contents($tempFilePath, json_encode($this->getJsonFixture('tmp_data_post_user_request')));
846+
$this->fillTempFile($this->getFixture('tmp_data_post_user_request.json'));
849847

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

852850
$service = app(SwaggerService::class);
853851

854852
$service->saveProductionData();
855853

856-
$this->assertFileExists($tempFilePath);
857-
$this->assertFileEquals($this->generateFixturePath('tmp_data_merged.json'), $tempFilePath);
854+
$this->assertTempFileEqualsFixture('tmp_data_merged');
858855
}
859856

860857
public function testMergeToEmptyTempDocumentation()
861858
{
862859
$this->mockParallelTestingToken();
863860

864-
$tempFilePath = __DIR__ . '/../storage/temp_documentation.json';
865-
866-
file_put_contents($tempFilePath, '');
861+
$this->fillTempFile('');
867862

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

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

872-
$this->assertFileExists($tempFilePath);
873-
$this->assertFileEquals($this->generateFixturePath('tmp_data_merged_to_empty_temp_documentation.json'), $tempFilePath);
867+
$this->assertTempFileEqualsFixture('tmp_data_merged_to_empty_temp_documentation');
874868
}
875869

876870
public function testAddDataWhenInvokableClass()

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,5 @@ protected function mockParallelTestingToken(string $token = 'workerID'): void
214214
{
215215
ParallelTesting::resolveTokenUsing(fn () => $token);
216216
}
217+
217218
}

tests/support/Traits/SwaggerServiceMockTrait.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,18 @@ protected function mockDriverSaveData($driverClass = LocalDriver::class): void
6868
$this->functionCall('saveData'),
6969
]);
7070
}
71+
72+
protected function fillTempFile(string $content): void
73+
{
74+
file_put_contents(getcwd() . '/storage/temp_documentation.json', $content);
75+
}
76+
77+
protected function assertTempFileEqualsFixture(string $fixture): void
78+
{
79+
$fixture = $this->prepareFixtureName($fixture);
80+
81+
$path = $this->generateFixturePath($fixture);
82+
83+
$this->assertFileEquals($path, getcwd() . '/storage/temp_documentation.json');
84+
}
7185
}

0 commit comments

Comments
 (0)