-
Notifications
You must be signed in to change notification settings - Fork 48
feat: Store documentation file on a configurable directory #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
748d424
cc6d056
4e1970f
7d08de0
a97158e
10705ea
8d25c0f
db649e9
9dd4951
0fa0b4b
4a387c2
b665010
ebef239
cef046b
83b43b3
999f2c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,34 +10,39 @@ | |||||||||||
| class StorageDriver extends BaseDriver | ||||||||||||
| { | ||||||||||||
| protected Filesystem $disk; | ||||||||||||
| protected ?string $prodFilePath; | ||||||||||||
| protected ?string $mainFilePath; | ||||||||||||
| protected array $config; | ||||||||||||
|
|
||||||||||||
| public function __construct() | ||||||||||||
| { | ||||||||||||
| parent::__construct(); | ||||||||||||
|
|
||||||||||||
| $this->disk = Storage::disk(config('auto-doc.drivers.storage.disk')); | ||||||||||||
| $this->prodFilePath = config('auto-doc.drivers.storage.production_path'); | ||||||||||||
| $this->config = config('auto-doc.drivers.storage'); | ||||||||||||
| $this->disk = Storage::disk($this->config['disk']); | ||||||||||||
|
|
||||||||||||
| if (empty($this->prodFilePath)) { | ||||||||||||
| $directory = $this->config['directory'] . DIRECTORY_SEPARATOR; | ||||||||||||
|
||||||||||||
| $directory = $this->config['directory'] . DIRECTORY_SEPARATOR; | |
| $directory = $this->config['directory']; | |
| if (!str_ends_with($directory, DIRECTORY_SEPARATOR)) { | |
| $directory .= DIRECTORY_SEPARATOR; | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,24 +9,37 @@ | |||||||||
| class LocalDriverTest extends TestCase | ||||||||||
| { | ||||||||||
| protected static LocalDriver $localDriverClass; | ||||||||||
| protected static string $productionFilePath; | ||||||||||
| protected static string $baseFile; | ||||||||||
| protected static string $tmpDocumentationFilePath; | ||||||||||
| protected static array $tmpData; | ||||||||||
|
|
||||||||||
| public function setUp(): void | ||||||||||
| { | ||||||||||
| parent::setUp(); | ||||||||||
|
|
||||||||||
| self::$productionFilePath ??= __DIR__ . '/../storage/documentation.json'; | ||||||||||
| self::$tmpDocumentationFilePath ??= __DIR__ . '/../storage/temp_documentation.json'; | ||||||||||
| $documentationDirectory = config('auto-doc.drivers.local.directory'); | ||||||||||
|
|
||||||||||
| self::$baseFile ??= storage_path("{$documentationDirectory}/documentation.json"); | ||||||||||
| self::$tmpDocumentationFilePath ??= storage_path('temp_documentation.json'); | ||||||||||
|
|
||||||||||
| self::$tmpData ??= $this->getJsonFixture('tmp_data'); | ||||||||||
|
|
||||||||||
| config(['auto-doc.drivers.local.production_path' => self::$productionFilePath]); | ||||||||||
| config(['auto-doc.drivers.local.base_file_name' => 'documentation']); | ||||||||||
|
|
||||||||||
| self::$localDriverClass ??= new LocalDriver(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public function testDirectoryEndsWithDirectorySeparator() | ||||||||||
| { | ||||||||||
| config(['auto-doc.drivers.local.directory' => 'documentations'.DIRECTORY_SEPARATOR]); | ||||||||||
|
|
||||||||||
| $driver = new LocalDriver(); | ||||||||||
| $driver->saveTmpData(self::$tmpData); | ||||||||||
|
|
||||||||||
| $this->assertFileExists(self::$tmpDocumentationFilePath); | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These static properties are used several times in this class and I believe they are beneficial to keep tests simpler and improve the readability. |
||||||||||
| $this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$tmpDocumentationFilePath); | ||||||||||
hans-thomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| public function testSaveTmpData() | ||||||||||
| { | ||||||||||
| self::$localDriverClass->saveTmpData(self::$tmpData); | ||||||||||
|
|
@@ -55,7 +68,7 @@ public function testCreateClassConfigEmpty() | |||||||||
| { | ||||||||||
| $this->expectException(MissedProductionFilePathException::class); | ||||||||||
|
|
||||||||||
| config(['auto-doc.drivers.local.production_path' => null]); | ||||||||||
| config(['auto-doc.drivers.local.base_file_name' => null]); | ||||||||||
|
|
||||||||||
| new LocalDriver(); | ||||||||||
| } | ||||||||||
|
|
@@ -73,15 +86,32 @@ public function testSaveData() | |||||||||
|
|
||||||||||
| self::$localDriverClass->saveData(); | ||||||||||
|
|
||||||||||
| $this->assertFileExists(self::$productionFilePath); | ||||||||||
| $this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$productionFilePath); | ||||||||||
| $this->assertFileExists(self::$baseFile); | ||||||||||
| $this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$baseFile); | ||||||||||
|
|
||||||||||
| $this->assertFileDoesNotExist(self::$tmpDocumentationFilePath); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public function testSaveDataWhenDirectoryNotExists() | ||||||||||
| { | ||||||||||
| $documentationDirectory = 'test_directory'; | ||||||||||
| if (is_dir($documentationDirectory)) { | ||||||||||
|
Comment on lines
+97
to
+98
|
||||||||||
| $documentationDirectory = 'test_directory'; | |
| if (is_dir($documentationDirectory)) { | |
| $documentationDirectory = config('auto-doc.drivers.local.directory'); | |
| if (is_dir(storage_path($documentationDirectory))) { |
Copilot
AI
Aug 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using rmdir() without checking if the directory is empty will fail if the directory contains files. Should use a recursive directory removal or ensure the directory is empty before attempting to remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The directory path construction is inconsistent with the mainFilePath construction. When config['directory'] already ends with DIRECTORY_SEPARATOR, this will create the wrong directory path. Should use the same normalized $directory variable from lines 19-21.