Skip to content

Commit a669fe6

Browse files
committed
Fix bug and failing test
1 parent 04f8855 commit a669fe6

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/SpecBaseObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function getErrors(): array
280280
if (($pos = $this->getDocumentPosition()) !== null) {
281281
$errors = [
282282
array_map(function ($e) use ($pos) {
283-
return "[{$pos->getPointer()}] $e";
283+
return $pos->getPointer() ? "[{$pos->getPointer()}] $e" : $e;
284284
}, $this->_errors)
285285
];
286286
} else {

tests/spec/PathTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,11 @@ public function testPathItemReference()
141141
$openapi = Reader::readFromYamlFile($file, \cebe\openapi\spec\OpenApi::class, false);
142142

143143
$result = $openapi->validate();
144-
$this->assertEquals([], $openapi->getErrors(), print_r($openapi->getErrors(), true));
145-
$this->assertTrue($result);
144+
$this->assertEquals([
145+
'Invalid field: "X-EXTENSION"',
146+
'Invalid field: "xyz-extension"'
147+
], $openapi->getErrors(), print_r($openapi->getErrors(), true));
148+
$this->assertFalse($result);
146149

147150
$this->assertInstanceOf(Paths::class, $openapi->paths);
148151
$this->assertInstanceOf(PathItem::class, $fooPath = $openapi->paths['/foo']);
@@ -173,12 +176,16 @@ public function testPathItemReference()
173176
$this->assertInstanceOf(Response::class, $path200);
174177
$this->assertEquals('A bar', $path200->description);
175178

179+
unset($openapi);
176180
/** @var $openapi OpenApi */
177181
$openapi = Reader::readFromYamlFile($file, \cebe\openapi\spec\OpenApi::class, true);
178182

179183
$result = $openapi->validate();
180-
$this->assertEquals([], $openapi->getErrors(), print_r($openapi->getErrors(), true));
181-
$this->assertTrue($result);
184+
$this->assertEquals([
185+
'Invalid field: "X-EXTENSION"',
186+
'Invalid field: "xyz-extension"'
187+
], $openapi->getErrors());
188+
$this->assertFalse($result);
182189

183190
$this->assertInstanceOf(Paths::class, $openapi->paths);
184191
$this->assertInstanceOf(PathItem::class, $fooPath = $openapi->paths['/foo']);

0 commit comments

Comments
 (0)