-
Notifications
You must be signed in to change notification settings - Fork 47
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
Open
hans-thomas
wants to merge
16
commits into
RonasIT:master
Choose a base branch
from
hans-thomas:doc-file-on-configurable-dir
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
748d424
Add `documentation_directory` key to the config file;
hans-thomas cc6d056
Update drivers;
hans-thomas 4e1970f
Fix tests;
hans-thomas 7d08de0
Increase config version;
hans-thomas a97158e
Fix `No such file or directory` error on running tests;
hans-thomas 10705ea
The `directory` config key added to local and storage drivers;
hans-thomas 8d25c0f
The `production_path` key renamed;
hans-thomas db649e9
Add `.json` extension to `base_file_name` attr and check target dir e…
hans-thomas 9dd4951
Update tests;
hans-thomas 0fa0b4b
Wip;
hans-thomas 4a387c2
Making suggested changes;
hans-thomas b665010
Apply changes;
hans-thomas ebef239
Apply changes;
hans-thomas cef046b
Set empty directory in AutoDocControllerTest;
hans-thomas 83b43b3
Cover new lines;
hans-thomas 999f2c2
Apply new changes;
hans-thomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||||||
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
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)) { | ||||||
rmdir(storage_path($documentationDirectory)); | ||||||
} | ||||||
|
||||||
self::$localDriverClass->saveTmpData(self::$tmpData); | ||||||
|
||||||
self::$localDriverClass->saveData(); | ||||||
|
||||||
$this->assertFileExists(self::$baseFile); | ||||||
$this->assertFileEquals($this->generateFixturePath('tmp_data_non_formatted.json'), self::$baseFile); | ||||||
|
||||||
$this->assertFileDoesNotExist(self::$tmpDocumentationFilePath); | ||||||
} | ||||||
|
||||||
public function testGetDocumentation() | ||||||
{ | ||||||
file_put_contents(self::$productionFilePath, json_encode(self::$tmpData)); | ||||||
file_put_contents(self::$baseFile, json_encode(self::$tmpData)); | ||||||
|
||||||
$documentation = self::$localDriverClass->getDocumentation(); | ||||||
|
||||||
|
@@ -92,7 +122,7 @@ public function testGetDocumentationFileNotExists() | |||||
{ | ||||||
$this->expectException(FileNotFoundException::class); | ||||||
|
||||||
config(['auto-doc.drivers.local.production_path' => 'not_exists_file']); | ||||||
config(['auto-doc.drivers.local.base_file_name' => 'not_exists_file.json']); | ||||||
|
||||||
(new LocalDriver())->getDocumentation(); | ||||||
} | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.