Skip to content

Commit

Permalink
Improve Context::getDebugLocation()
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann committed Jan 6, 2025
1 parent ee69aa1 commit f6149dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ public function isVersion($versions): bool
public function getDebugLocation(): string
{
$location = '';
if ($this->class && ($this->method || $this->property)) {
$location .= $this->fullyQualifiedName($this->class);
$fqn = $this->fullyQualifiedName($this->class ?? $this->interface ?? $this->trait ?? $this->enum);
if ($fqn && ($this->method || $this->property)) {
$location .= $fqn;
if ($this->method) {
$location .= ($this->static ? '::' : '->') . $this->method . '()';
} elseif ($this->property) {
Expand Down
21 changes: 21 additions & 0 deletions tests/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OpenApi\Analysers\TokenAnalyser;
use OpenApi\Context;
use OpenApi\Generator;
use OpenApi\Tests\Fixtures\Customer;
use Psr\Log\NullLogger;

class ContextTest extends OpenApiTestCase
Expand Down Expand Up @@ -61,4 +62,24 @@ public function testEnsureRoot(): void
$this->assertInstanceOf(NullLogger::class, $context->logger);
$this->assertEquals(OA\OpenApi::VERSION_3_1_0, $context->getVersion());
}

public function testDebugLocation(): void
{
$this->assertOpenApiLogEntryContains('Required @OA\PathItem() not found');
$openapi = (new Generator($this->getTrackingLogger()))
->setAnalyser(new TokenAnalyser())
->generate([$this->fixture('Customer.php')]);

$customerSchema = $openapi->components->schemas[0];
$this->assertStringContainsString(
'Fixtures/Customer.php on line 16',
$customerSchema->_context->getDebugLocation()
);

$customerPropertyFirstName = $customerSchema->properties[0];
$this->assertStringContainsString(
Customer::class . '->firstname in ',
$customerPropertyFirstName->_context->getDebugLocation()
);
}
}

0 comments on commit f6149dc

Please sign in to comment.