diff --git a/src/Exceptions/DocFileNotExistsException.php b/src/Exceptions/DocFileNotExistsException.php new file mode 100644 index 0000000..b5647b7 --- /dev/null +++ b/src/Exceptions/DocFileNotExistsException.php @@ -0,0 +1,13 @@ +config, 'files.temporary'); @@ -692,13 +698,13 @@ public function getDocFileContent() $fullFilePath = base_path($filePath); if (!file_exists($fullFilePath)) { - continue; + throw new DocFileNotExistsException($fullFilePath); } $fileContent = json_decode(file_get_contents($fullFilePath), true); if (empty($fileContent)) { - continue; + throw new EmptyDocFileException($fullFilePath); } try { diff --git a/tests/AutoDocControllerTest.php b/tests/AutoDocControllerTest.php index eccb1b3..ef2c18f 100644 --- a/tests/AutoDocControllerTest.php +++ b/tests/AutoDocControllerTest.php @@ -3,6 +3,8 @@ namespace RonasIT\Support\Tests; use Illuminate\Http\Response; +use RonasIT\Support\AutoDoc\Exceptions\DocFileNotExistsException; +use RonasIT\Support\AutoDoc\Exceptions\EmptyDocFileException; class AutoDocControllerTest extends TestCase { @@ -50,32 +52,32 @@ public function testGetJSONDocumentationWithAdditionalPaths() $this->assertEqualsJsonFixture('tmp_data_with_additional_paths', $response->json()); } - public function getJSONDocumentationInvalidAdditionalDoc(): array + public function getJSONDocumentationDoesntExist() { - $basePath = 'tests/fixtures/AutoDocControllerTest'; + config([ + 'auto-doc.additional_paths' => ['invalid_path/non_existent_file.json'] + ]); + + $this->expectException(DocFileNotExistsException::class); + + $this->json('get', '/auto-doc/documentation'); + } + + public function getJSONDocumentationIsEmpty() + { + config([ + 'auto-doc.additional_paths' => ['tests/fixtures/AutoDocControllerTest/documentation__non_json.txt'] + ]); + + $this->expectException(EmptyDocFileException::class); - return [ - [ - 'additionalDocPath' => 'invalid_path/non_existent_file.json' - ], - [ - 'additionalDocPath' => $basePath . '/documentation__non_json.txt' - ], - [ - 'additionalDocPath' => $basePath. '/documentation__invalid_format__missing_field__paths.json' - ] - ]; + $this->json('get', '/auto-doc/documentation'); } - /** - * @dataProvider getJSONDocumentationInvalidAdditionalDoc - * - * @param string $additionalDocPath - */ - public function testGetJSONDocumentationInvalidAdditionalDoc(string $additionalDocPath) + public function testGetJSONDocumentationInvalidAdditionalDoc() { config([ - 'auto-doc.additional_paths' => [$additionalDocPath] + 'auto-doc.additional_paths' => ['tests/fixtures/AutoDocControllerTest/documentation__invalid_format__missing_field__paths.json'] ]); $response = $this->json('get', '/auto-doc/documentation');