Skip to content

Commit 4e1970f

Browse files
committed
Fix tests;
1 parent cc6d056 commit 4e1970f

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

tests/AutoDocControllerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ class AutoDocControllerTest extends TestCase
1212
use PHPMock;
1313

1414
protected static array $documentation;
15+
protected static string $documentationDirectory;
1516
protected static string $localDriverFilePath;
1617

1718
public function setUp(): void
1819
{
1920
parent::setUp();
2021

21-
self::$localDriverFilePath ??= __DIR__ . '/../storage/documentation.json';
22+
self::$documentationDirectory ??= config('auto-doc.documentation_directory').DIRECTORY_SEPARATOR;
23+
self::$localDriverFilePath ??= 'documentation.json';
2224
self::$documentation ??= $this->getJsonFixture('tmp_data');
2325

24-
file_put_contents(self::$localDriverFilePath, json_encode(self::$documentation));
26+
file_put_contents(self::$documentationDirectory.self::$localDriverFilePath, json_encode(self::$documentation));
2527

2628
config(['auto-doc.drivers.local.production_path' => self::$localDriverFilePath]);
2729
}

tests/LocalDriverTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class LocalDriverTest extends TestCase
1010
{
1111
protected static LocalDriver $localDriverClass;
12+
protected static string $documentationDirectory;
1213
protected static string $productionFilePath;
1314
protected static string $tmpDocumentationFilePath;
1415
protected static array $tmpData;
@@ -17,8 +18,9 @@ public function setUp(): void
1718
{
1819
parent::setUp();
1920

20-
self::$productionFilePath ??= __DIR__ . '/../storage/documentation.json';
21-
self::$tmpDocumentationFilePath ??= __DIR__ . '/../storage/temp_documentation.json';
21+
self::$documentationDirectory ??= config('auto-doc.documentation_directory').DIRECTORY_SEPARATOR;
22+
self::$productionFilePath ??= 'documentation.json';
23+
self::$tmpDocumentationFilePath ??= 'temp_documentation.json';
2224

2325
self::$tmpData ??= $this->getJsonFixture('tmp_data');
2426

@@ -31,13 +33,13 @@ public function testSaveTmpData()
3133
{
3234
self::$localDriverClass->saveTmpData(self::$tmpData);
3335

34-
$this->assertFileExists(self::$tmpDocumentationFilePath);
35-
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$tmpDocumentationFilePath);
36+
$this->assertFileExists(self::$documentationDirectory.self::$tmpDocumentationFilePath);
37+
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$documentationDirectory.self::$tmpDocumentationFilePath);
3638
}
3739

3840
public function testGetTmpData()
3941
{
40-
file_put_contents(self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
42+
file_put_contents(self::$documentationDirectory.self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
4143

4244
$result = self::$localDriverClass->getTmpData();
4345

@@ -69,19 +71,19 @@ public function testGetAndSaveTmpData()
6971

7072
public function testSaveData()
7173
{
72-
file_put_contents(self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
74+
file_put_contents(self::$documentationDirectory.self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
7375

7476
self::$localDriverClass->saveData();
7577

76-
$this->assertFileExists(self::$productionFilePath);
77-
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$productionFilePath);
78+
$this->assertFileExists(self::$documentationDirectory.self::$productionFilePath);
79+
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$documentationDirectory.self::$productionFilePath);
7880

79-
$this->assertFileDoesNotExist(self::$tmpDocumentationFilePath);
81+
$this->assertFileDoesNotExist(self::$documentationDirectory.self::$tmpDocumentationFilePath);
8082
}
8183

8284
public function testGetDocumentation()
8385
{
84-
file_put_contents(self::$productionFilePath, json_encode(self::$tmpData));
86+
file_put_contents(self::$documentationDirectory.self::$productionFilePath, json_encode(self::$tmpData));
8587

8688
$documentation = self::$localDriverClass->getDocumentation();
8789

@@ -92,7 +94,7 @@ public function testGetDocumentationFileNotExists()
9294
{
9395
$this->expectException(FileNotFoundException::class);
9496

95-
config(['auto-doc.drivers.local.production_path' => 'not_exists_file']);
97+
config(['auto-doc.drivers.local.production_path' => 'not_exists_file.json']);
9698

9799
(new LocalDriver())->getDocumentation();
98100
}

tests/RemoteDriverTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ class RemoteDriverTest extends TestCase
1313

1414
protected static array $tmpData;
1515
protected static RemoteDriver $remoteDriverClass;
16+
protected static string $documentationDirectory;
1617
protected static string $tmpDocumentationFilePath;
1718

1819
public function setUp(): void
1920
{
2021
parent::setUp();
2122

2223
self::$tmpData ??= $this->getJsonFixture('tmp_data');
23-
self::$tmpDocumentationFilePath ??= __DIR__ . '/../storage/temp_documentation.json';
24+
self::$documentationDirectory ??= config('auto-doc.documentation_directory').DIRECTORY_SEPARATOR;
25+
self::$tmpDocumentationFilePath ??= 'temp_documentation.json';
2426

2527
self::$remoteDriverClass ??= new RemoteDriver();
2628
}
@@ -29,13 +31,13 @@ public function testSaveTmpData()
2931
{
3032
self::$remoteDriverClass->saveTmpData(self::$tmpData);
3133

32-
$this->assertFileExists(self::$tmpDocumentationFilePath);
33-
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$tmpDocumentationFilePath);
34+
$this->assertFileExists(self::$documentationDirectory.self::$tmpDocumentationFilePath);
35+
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$documentationDirectory.self::$tmpDocumentationFilePath);
3436
}
3537

3638
public function testGetTmpData()
3739
{
38-
file_put_contents(self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
40+
file_put_contents(self::$documentationDirectory.self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
3941

4042
$result = self::$remoteDriverClass->getTmpData();
4143

@@ -73,11 +75,11 @@ public function testSaveData()
7375
])
7476
->willReturn(['', 204]);
7577

76-
file_put_contents(self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
78+
file_put_contents(self::$documentationDirectory.self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
7779

7880
$mock->saveData();
7981

80-
$this->assertFileDoesNotExist(self::$tmpDocumentationFilePath);
82+
$this->assertFileDoesNotExist(self::$documentationDirectory.self::$tmpDocumentationFilePath);
8183
}
8284

8385
public function testSaveDataWithoutTmpFile()

tests/StorageDriverTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class StorageDriverTest extends TestCase
1212
{
1313
protected static StorageDriver $storageDriverClass;
1414
protected Filesystem $disk;
15+
protected static string $documentationDirectory;
1516
protected static string $productionFilePath;
1617
protected static string $tmpDocumentationFilePath;
1718
protected static array $tmpData;
@@ -22,8 +23,9 @@ public function setUp(): void
2223

2324
$this->disk = Storage::fake('testing');
2425

26+
self::$documentationDirectory ??= config('auto-doc.documentation_directory').DIRECTORY_SEPARATOR;
2527
self::$productionFilePath ??= 'documentation.json';
26-
self::$tmpDocumentationFilePath ??= __DIR__ . '/../storage/temp_documentation.json';
28+
self::$tmpDocumentationFilePath ??= 'temp_documentation.json';
2729

2830
self::$tmpData ??= $this->getJsonFixture('tmp_data');
2931

@@ -37,13 +39,13 @@ public function testSaveTmpData()
3739
{
3840
self::$storageDriverClass->saveTmpData(self::$tmpData);
3941

40-
$this->assertFileExists(self::$tmpDocumentationFilePath);
41-
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$tmpDocumentationFilePath);
42+
$this->assertFileExists(self::$documentationDirectory.self::$tmpDocumentationFilePath);
43+
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$documentationDirectory.self::$tmpDocumentationFilePath);
4244
}
4345

4446
public function testGetTmpData()
4547
{
46-
file_put_contents(self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
48+
file_put_contents(self::$documentationDirectory.self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
4749

4850
$result = self::$storageDriverClass->getTmpData();
4951

@@ -75,14 +77,14 @@ public function testGetAndSaveTmpData()
7577

7678
public function testSaveData()
7779
{
78-
file_put_contents(self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
80+
file_put_contents(self::$documentationDirectory.self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
7981

8082
self::$storageDriverClass->saveData();
8183

8284
$this->disk->assertExists(self::$productionFilePath);
8385
$this->assertEqualsFixture('tmp_data_non_formatted.json', $this->disk->get(self::$productionFilePath));
8486

85-
$this->assertFileDoesNotExist(self::$tmpDocumentationFilePath);
87+
$this->assertFileDoesNotExist(self::$documentationDirectory.self::$tmpDocumentationFilePath);
8688
}
8789

8890
public function testGetDocumentation()

0 commit comments

Comments
 (0)