Skip to content

Commit 322c173

Browse files
committed
fix: assertExceptionMessage check
1 parent f35b440 commit 322c173

File tree

6 files changed

+13
-18
lines changed

6 files changed

+13
-18
lines changed

src/Drivers/RemoteDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getDocumentation(): array
3636
list($content, $statusCode) = $this->makeHttpRequest('get', $this->getUrl());
3737

3838
if (empty($content) || $statusCode !== 200) {
39-
throw new FileNotFoundException('Documentation file not found.');
39+
throw new FileNotFoundException();
4040
}
4141

4242
return json_decode($content, true);

src/Exceptions/FileNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class FileNotFoundException extends BaseException
88
{
99
public function __construct(string $filePath = null)
1010
{
11-
parent::__construct("Documentation file not found: {$filePath}");
11+
parent::__construct("Documentation file not found {$filePath}");
1212
}
1313
}

src/Services/SwaggerService.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ public function __construct(Container $container)
8080
$this->data = $this->driver->getProcessTmpData();
8181

8282
if (empty($this->data)) {
83-
$this->data = empty($this->config['info'])
84-
? $this->generateEmptyData()
85-
: $this->generateEmptyData($this->config['info']['description']);
83+
$this->data = $this->generateEmptyData();
8684

8785
$this->driver->saveProcessTmpData($this->data);
8886
}
@@ -142,6 +140,10 @@ protected function generateEmptyData(?string $view = null, array $viewData = [],
142140
throw new EmptyContactEmailException();
143141
}
144142

143+
if(empty($view) && !empty($this->config['info'])){
144+
$view = $this->config['info']['description'];
145+
}
146+
145147
$data = [
146148
'openapi' => self::OPEN_API_VERSION,
147149
'servers' => [
@@ -811,7 +813,7 @@ public function saveProductionData()
811813
if (ParallelTesting::token()) {
812814
$this->driver->appendProcessDataToTmpFile(function (array $sharedTmpData) {
813815
$resultDocContent = (empty($sharedTmpData))
814-
? $this->data = $this->generateEmptyData($this->config['info']['description'])
816+
? $this->generateEmptyData($this->config['info']['description'])
815817
: $sharedTmpData;
816818

817819
$this->mergeOpenAPIDocs($resultDocContent, $this->data);
@@ -830,9 +832,6 @@ public function getDocFileContent()
830832

831833
$this->openAPIValidator->validate($documentation);
832834
} catch (Exception $exception) {
833-
$infoConfig = $this->config['info'];
834-
$infoConfig['description'] = Arr::get($this->config, 'defaults.error');
835-
836835
return $this->generateEmptyData($this->config['defaults']['error'], ['message' => $exception->getMessage()]);
837836
}
838837

@@ -965,11 +964,7 @@ protected function prepareInfo(?string $view = null, array $viewData = [], array
965964
{
966965
$info = [];
967966

968-
foreach ($license as $key => $value) {
969-
if (empty($value)) {
970-
unset($license[$key]);
971-
}
972-
}
967+
$license = array_filter($license, fn($value) => !empty($value));
973968

974969
if (!empty($license)) {
975970
$info['license'] = $license;
@@ -981,7 +976,7 @@ protected function prepareInfo(?string $view = null, array $viewData = [], array
981976

982977
$infoConfig = Arr::except($this->config['info'], ['description', 'license']);
983978

984-
return array_merge($info, $infoConfig);
979+
return array_merge($infoConfig, $info);
985980
}
986981

987982
protected function getOpenAPIFileContent(string $filePath): array

tests/LocalDriverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function testGetDocumentationFileNotExists()
128128
{
129129
$this->expectException(FileNotFoundException::class);
130130

131-
$this->expectExceptionMessage('Documentation file not found: '.config(['auto-doc.drivers.local.production_path']));
131+
$this->expectExceptionMessageMatches('/^Documentation file not found not_exists_file$/');
132132

133133
config(['auto-doc.drivers.local.production_path' => 'not_exists_file']);
134134

tests/RemoteDriverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function testGetDocumentationNoFile()
153153
{
154154
$this->expectException(FileNotFoundException::class);
155155

156-
$this->expectExceptionMessage('Documentation file not found:');
156+
$this->expectExceptionMessageMatches('/^Documentation file not found $/');
157157

158158
config(['auto-doc.drivers.remote.key' => 'mocked_key']);
159159
config(['auto-doc.drivers.remote.url' => 'mocked_url']);

tests/StorageDriverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function testGetDocumentationFileNotExists()
122122
{
123123
$this->expectException(FileNotFoundException::class);
124124

125-
$this->expectExceptionMessage('Documentation file not found:');
125+
$this->expectExceptionMessageMatches('/^Documentation file not found documentation.json$/');
126126

127127
self::$storageDriverClass->getDocumentation();
128128
}

0 commit comments

Comments
 (0)