Skip to content

Commit 9dd4951

Browse files
committed
Update tests;
1 parent db649e9 commit 9dd4951

File tree

4 files changed

+60
-47
lines changed

4 files changed

+60
-47
lines changed

tests/AutoDocControllerTest.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,28 @@ class AutoDocControllerTest extends TestCase
1212
use PHPMock;
1313

1414
protected static array $documentation;
15-
protected static string $documentationDirectory;
16-
protected static string $localDriverFilePath;
15+
protected static string $baseFileName;
16+
protected static string $baseFile;
1717

1818
public function setUp(): void
1919
{
2020
parent::setUp();
2121

22-
self::$documentationDirectory ??= config('auto-doc.documentation_directory').DIRECTORY_SEPARATOR;
23-
self::$localDriverFilePath ??= 'documentation.json';
22+
$documentationDirectory = config('auto-doc.drivers.local.directory');
23+
if (!str_ends_with($documentationDirectory, DIRECTORY_SEPARATOR)) {
24+
$documentationDirectory .= DIRECTORY_SEPARATOR;
25+
}
26+
27+
self::$baseFileName ??= 'documentation';
28+
self::$baseFile ??= $documentationDirectory.self::$baseFileName.'.json';
2429
self::$documentation ??= $this->getJsonFixture('tmp_data');
2530

26-
if (!is_dir(self::$documentationDirectory)) {
27-
mkdir(self::$documentationDirectory);
31+
if (!is_dir(storage_path($documentationDirectory))) {
32+
mkdir(storage_path($documentationDirectory));
2833
}
29-
file_put_contents(self::$documentationDirectory.self::$localDriverFilePath, json_encode(self::$documentation));
34+
file_put_contents(storage_path(self::$baseFile), json_encode(self::$documentation));
3035

31-
config(['auto-doc.drivers.local.production_path' => self::$localDriverFilePath]);
36+
config(['auto-doc.drivers.local.base_file_name' => self::$baseFileName]);
3237
}
3338

3439
public function tearDown(): void

tests/LocalDriverTest.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,27 @@
99
class LocalDriverTest extends TestCase
1010
{
1111
protected static LocalDriver $localDriverClass;
12-
protected static string $documentationDirectory;
13-
protected static string $productionFilePath;
12+
protected static string $baseFileName;
13+
protected static string $baseFile;
1414
protected static string $tmpDocumentationFilePath;
1515
protected static array $tmpData;
1616

1717
public function setUp(): void
1818
{
1919
parent::setUp();
2020

21-
self::$documentationDirectory ??= config('auto-doc.documentation_directory').DIRECTORY_SEPARATOR;
22-
self::$productionFilePath ??= 'documentation.json';
23-
self::$tmpDocumentationFilePath ??= 'temp_documentation.json';
21+
$documentationDirectory ??= config('auto-doc.drivers.local.directory');
22+
if (!str_ends_with($documentationDirectory, DIRECTORY_SEPARATOR)) {
23+
$documentationDirectory .= DIRECTORY_SEPARATOR;
24+
}
25+
26+
self::$baseFileName ??= 'documentation';
27+
self::$baseFile ??= storage_path($documentationDirectory.self::$baseFileName.'.json');
28+
self::$tmpDocumentationFilePath ??= storage_path('temp_documentation.json');
2429

2530
self::$tmpData ??= $this->getJsonFixture('tmp_data');
2631

27-
config(['auto-doc.drivers.local.production_path' => self::$productionFilePath]);
32+
config(['auto-doc.drivers.local.base_file_name' => self::$baseFileName]);
2833

2934
self::$localDriverClass ??= new LocalDriver();
3035
}
@@ -33,13 +38,13 @@ public function testSaveTmpData()
3338
{
3439
self::$localDriverClass->saveTmpData(self::$tmpData);
3540

36-
$this->assertFileExists(self::$documentationDirectory.self::$tmpDocumentationFilePath);
37-
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$documentationDirectory.self::$tmpDocumentationFilePath);
41+
$this->assertFileExists(self::$tmpDocumentationFilePath);
42+
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$tmpDocumentationFilePath);
3843
}
3944

4045
public function testGetTmpData()
4146
{
42-
file_put_contents(self::$documentationDirectory.self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
47+
file_put_contents(self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
4348

4449
$result = self::$localDriverClass->getTmpData();
4550

@@ -57,7 +62,7 @@ public function testCreateClassConfigEmpty()
5762
{
5863
$this->expectException(MissedProductionFilePathException::class);
5964

60-
config(['auto-doc.drivers.local.production_path' => null]);
65+
config(['auto-doc.drivers.local.base_file_name' => null]);
6166

6267
new LocalDriver();
6368
}
@@ -71,19 +76,19 @@ public function testGetAndSaveTmpData()
7176

7277
public function testSaveData()
7378
{
74-
file_put_contents(self::$documentationDirectory.self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
79+
file_put_contents(self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
7580

7681
self::$localDriverClass->saveData();
7782

78-
$this->assertFileExists(self::$documentationDirectory.self::$productionFilePath);
79-
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$documentationDirectory.self::$productionFilePath);
83+
$this->assertFileExists(self::$baseFile);
84+
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$baseFile);
8085

81-
$this->assertFileDoesNotExist(self::$documentationDirectory.self::$tmpDocumentationFilePath);
86+
$this->assertFileDoesNotExist(self::$tmpDocumentationFilePath);
8287
}
8388

8489
public function testGetDocumentation()
8590
{
86-
file_put_contents(self::$documentationDirectory.self::$productionFilePath, json_encode(self::$tmpData));
91+
file_put_contents(self::$baseFile, json_encode(self::$tmpData));
8792

8893
$documentation = self::$localDriverClass->getDocumentation();
8994

@@ -94,7 +99,7 @@ public function testGetDocumentationFileNotExists()
9499
{
95100
$this->expectException(FileNotFoundException::class);
96101

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

99104
(new LocalDriver())->getDocumentation();
100105
}

tests/RemoteDriverTest.php

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

1414
protected static array $tmpData;
1515
protected static RemoteDriver $remoteDriverClass;
16-
protected static string $documentationDirectory;
1716
protected static string $tmpDocumentationFilePath;
1817

1918
public function setUp(): void
2019
{
2120
parent::setUp();
2221

2322
self::$tmpData ??= $this->getJsonFixture('tmp_data');
24-
self::$documentationDirectory ??= config('auto-doc.documentation_directory').DIRECTORY_SEPARATOR;
25-
self::$tmpDocumentationFilePath ??= 'temp_documentation.json';
23+
self::$tmpDocumentationFilePath ??= storage_path('temp_documentation.json');
2624

2725
self::$remoteDriverClass ??= new RemoteDriver();
2826
}
@@ -31,13 +29,13 @@ public function testSaveTmpData()
3129
{
3230
self::$remoteDriverClass->saveTmpData(self::$tmpData);
3331

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

3836
public function testGetTmpData()
3937
{
40-
file_put_contents(self::$documentationDirectory.self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
38+
file_put_contents(self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
4139

4240
$result = self::$remoteDriverClass->getTmpData();
4341

@@ -75,11 +73,11 @@ public function testSaveData()
7573
])
7674
->willReturn(['', 204]);
7775

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

8078
$mock->saveData();
8179

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

8583
public function testSaveDataWithoutTmpFile()

tests/StorageDriverTest.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class StorageDriverTest extends TestCase
1212
{
1313
protected static StorageDriver $storageDriverClass;
1414
protected Filesystem $disk;
15-
protected static string $documentationDirectory;
16-
protected static string $productionFilePath;
15+
protected static string $baseFileName;
16+
protected static string $baseFile;
1717
protected static string $tmpDocumentationFilePath;
1818
protected static array $tmpData;
1919

@@ -23,14 +23,19 @@ public function setUp(): void
2323

2424
$this->disk = Storage::fake('testing');
2525

26-
self::$documentationDirectory ??= config('auto-doc.documentation_directory').DIRECTORY_SEPARATOR;
27-
self::$productionFilePath ??= 'documentation.json';
28-
self::$tmpDocumentationFilePath ??= 'temp_documentation.json';
26+
$documentationDirectory = config('auto-doc.drivers.storage.directory');
27+
if (!str_ends_with($documentationDirectory, DIRECTORY_SEPARATOR)) {
28+
$documentationDirectory .= DIRECTORY_SEPARATOR;
29+
}
30+
31+
self::$baseFileName ??= 'documentation';
32+
self::$baseFile ??= $documentationDirectory.self::$baseFileName.'.json';
33+
self::$tmpDocumentationFilePath ??= storage_path('temp_documentation.json');
2934

3035
self::$tmpData ??= $this->getJsonFixture('tmp_data');
3136

3237
config(['auto-doc.drivers.storage.disk' => 'testing']);
33-
config(['auto-doc.drivers.storage.production_path' => self::$productionFilePath]);
38+
config(['auto-doc.drivers.storage.base_file_name' => self::$baseFileName]);
3439

3540
self::$storageDriverClass = new StorageDriver();
3641
}
@@ -39,13 +44,13 @@ public function testSaveTmpData()
3944
{
4045
self::$storageDriverClass->saveTmpData(self::$tmpData);
4146

42-
$this->assertFileExists(self::$documentationDirectory.self::$tmpDocumentationFilePath);
43-
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$documentationDirectory.self::$tmpDocumentationFilePath);
47+
$this->assertFileExists(self::$tmpDocumentationFilePath);
48+
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$tmpDocumentationFilePath);
4449
}
4550

4651
public function testGetTmpData()
4752
{
48-
file_put_contents(self::$documentationDirectory.self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
53+
file_put_contents(self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
4954

5055
$result = self::$storageDriverClass->getTmpData();
5156

@@ -63,7 +68,7 @@ public function testCreateClassConfigEmpty()
6368
{
6469
$this->expectException(MissedProductionFilePathException::class);
6570

66-
config(['auto-doc.drivers.storage.production_path' => null]);
71+
config(['auto-doc.drivers.storage.base_file_name' => null]);
6772

6873
new StorageDriver();
6974
}
@@ -77,19 +82,19 @@ public function testGetAndSaveTmpData()
7782

7883
public function testSaveData()
7984
{
80-
file_put_contents(self::$documentationDirectory.self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
85+
file_put_contents(self::$tmpDocumentationFilePath, json_encode(self::$tmpData));
8186

8287
self::$storageDriverClass->saveData();
8388

84-
$this->disk->assertExists(self::$productionFilePath);
85-
$this->assertEqualsFixture('tmp_data_non_formatted.json', $this->disk->get(self::$productionFilePath));
89+
$this->disk->assertExists(self::$baseFile);
90+
$this->assertEqualsFixture('tmp_data_non_formatted.json', $this->disk->get(self::$baseFile));
8691

87-
$this->assertFileDoesNotExist(self::$documentationDirectory.self::$tmpDocumentationFilePath);
92+
$this->assertFileDoesNotExist(self::$tmpDocumentationFilePath);
8893
}
8994

9095
public function testGetDocumentation()
9196
{
92-
$this->disk->put(self::$productionFilePath, $this->getFixture('tmp_data_non_formatted.json'));
97+
$this->disk->put(self::$baseFile, $this->getFixture('tmp_data_non_formatted.json'));
9398

9499
$documentation = self::$storageDriverClass->getDocumentation();
95100

0 commit comments

Comments
 (0)