Skip to content

Commit 6b0d189

Browse files
committed
tests: minor fix;
1 parent db8cdba commit 6b0d189

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

tests/AutoDocControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testGetViewDocumentation()
6969

7070
$response->assertStatus(Response::HTTP_OK);
7171

72-
$this->assertEquals($response->getContent(), $this->getFixture('rendered_documentation.html'));
72+
$this->assertEqualsFixture('rendered_documentation.html', $response->getContent());
7373
}
7474

7575
public function testGetViewDocumentationEnvironmentDisable()
@@ -91,7 +91,7 @@ public function testGetViewDocumentationWithGlobalPrefix()
9191

9292
$response->assertStatus(Response::HTTP_OK);
9393

94-
$this->assertEquals($response->getContent(), $this->getFixture('rendered_documentation_with_global_path.html'));
94+
$this->assertEqualsFixture('rendered_documentation_with_global_path.html', $response->getContent());
9595
}
9696

9797
public function testGetSwaggerAssetFile()

tests/LocalDriverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testGetDocumentation()
5858

5959
$documentation = $this->localDriverClass->getDocumentation();
6060

61-
$this->assertEquals($this->getJsonFixture('tmp_data'), $documentation);
61+
$this->assertEqualsJsonFixture('tmp_data', $documentation);
6262
}
6363

6464
public function testGetDocumentationFileNotExists()

tests/StorageDriverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testSaveData()
4242
$this->storageDriverClass->saveData();
4343

4444
$this->disk->assertExists($this->filePath);
45-
$this->assertEquals($this->getFixture('tmp_data_non_formatted.json'), $this->disk->get($this->filePath));
45+
$this->assertEqualsFixture('tmp_data_non_formatted.json', $this->disk->get($this->filePath));
4646

4747
$this->assertEquals([], $this->storageDriverClass->getTmpData());
4848
}
@@ -53,7 +53,7 @@ public function testGetDocumentation()
5353

5454
$documentation = $this->storageDriverClass->getDocumentation();
5555

56-
$this->assertEquals($this->getJsonFixture('tmp_data'), $documentation);
56+
$this->assertEqualsJsonFixture('tmp_data', $documentation);
5757
}
5858

5959
public function testGetDocumentationFileNotExists()

tests/TestCase.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ protected function defineEnvironment($app)
3535
$app->setBasePath(__DIR__ . '/..');
3636
}
3737

38-
public function exportJson($fixture, $data): void
38+
public function exportJson(string $fixtureName, $data): void
3939
{
4040
if ($data instanceof TestResponse) {
4141
$data = $data->json();
4242
}
4343

44-
$this->exportContent(json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), "{$fixture}.json");
44+
$this->exportContent(json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), "{$fixtureName}.json");
4545
}
4646

47-
protected function exportContent($content, string $fixture): void
47+
protected function exportContent($content, string $fixtureName): void
4848
{
49-
file_put_contents($this->getFixturePath($fixture), $content);
49+
file_put_contents($this->getFixturePath($fixtureName), $content);
5050
}
5151

5252
public function getFixturePath(string $fixtureName): string
@@ -58,18 +58,27 @@ public function getFixturePath(string $fixtureName): string
5858
return base_path("tests/fixtures/{$className}/{$fixtureName}");
5959
}
6060

61-
protected function getJsonFixture($name)
61+
protected function getJsonFixture(string $name)
6262
{
6363
return json_decode($this->getFixture("{$name}.json"), true);
6464
}
6565

66-
public function assertEqualsJsonFixture(string $fixture, $data, bool $exportMode = false): void
66+
public function assertEqualsJsonFixture(string $fixtureName, $data, bool $exportMode = false): void
6767
{
6868
if ($exportMode || $this->globalExportMode) {
69-
$this->exportJson($fixture, $data);
69+
$this->exportJson($fixtureName, $data);
7070
}
7171

72-
$this->assertEquals($this->getJsonFixture($fixture), $data);
72+
$this->assertEquals($this->getJsonFixture($fixtureName), $data);
73+
}
74+
75+
public function assertEqualsFixture(string $fixtureName, $data, bool $exportMode = false): void
76+
{
77+
if ($exportMode || $this->globalExportMode) {
78+
$this->exportContent($fixtureName, $data);
79+
}
80+
81+
$this->assertEquals($this->getFixture($fixtureName), $data);
7382
}
7483

7584
protected function getFixture($name)

0 commit comments

Comments
 (0)