diff --git a/src/Exceptions/UnsupportedDocumentationViewerException.php b/src/Exceptions/UnsupportedDocumentationViewerException.php new file mode 100644 index 0000000..cf25616 --- /dev/null +++ b/src/Exceptions/UnsupportedDocumentationViewerException.php @@ -0,0 +1,16 @@ +')) { throw new LegacyConfigException(); } + + $documentationViewer = (string) Arr::get($this->config, 'documentation_viewer'); + + if (!view()->exists("auto-doc::documentation-{$documentationViewer}")) { + throw new UnsupportedDocumentationViewerException($documentationViewer); + } } protected function setDriver() diff --git a/tests/SwaggerServiceTest.php b/tests/SwaggerServiceTest.php index 0f8cddf..8d9aa5c 100755 --- a/tests/SwaggerServiceTest.php +++ b/tests/SwaggerServiceTest.php @@ -21,6 +21,7 @@ use RonasIT\Support\AutoDoc\Exceptions\SpecValidation\MissingPathPlaceholderException; use RonasIT\Support\AutoDoc\Exceptions\SpecValidation\MissingRefFileException; use RonasIT\Support\AutoDoc\Exceptions\SwaggerDriverClassNotFoundException; +use RonasIT\Support\AutoDoc\Exceptions\UnsupportedDocumentationViewerException; use RonasIT\Support\AutoDoc\Exceptions\WrongSecurityConfigException; use RonasIT\Support\AutoDoc\Services\SwaggerService; use RonasIT\Support\Tests\Support\Mock\TestNotificationSetting; @@ -649,4 +650,30 @@ public function testAddDataWithoutBoundContract() $service->addData($request, $response); } + + public function testSetInvalidDocumentationViewer() + { + config(['auto-doc.documentation_viewer' => 'invalid']); + + $this->expectException(UnsupportedDocumentationViewerException::class); + $this->expectExceptionMessage( + "The documentation viewer 'invalid' does not exists." + . " Please check that the 'documentation_viewer' key of your auto-doc.php config has one of valid values." + ); + + app(SwaggerService::class); + } + + public function testSetNullableDocumentationViewer() + { + config(['auto-doc.documentation_viewer' => null]); + + $this->expectException(UnsupportedDocumentationViewerException::class); + $this->expectExceptionMessage( + "The documentation viewer '' does not exists." + . " Please check that the 'documentation_viewer' key of your auto-doc.php config has one of valid values." + ); + + app(SwaggerService::class); + } }