Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gh 2320: Add passing test #2324

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public function testDiagnostics(DiagnosticProvider $provider, DiagnosticExample
}

if ($example->valid) {
if (count($diagnostics) > 1) {
self::fail(sprintf("Expected code to be valid but recieved diagnostics: \n%s", $diagnostics->__toString()));
}
self::assertCount(0, $diagnostics);
return;
}
Expand Down
9 changes: 8 additions & 1 deletion lib/TextDocument/ByteOffsetRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Phpactor\TextDocument;

class ByteOffsetRange
use Stringable;

class ByteOffsetRange implements Stringable
{
public function __construct(private ByteOffset $start, private ByteOffset $end)
{
Expand Down Expand Up @@ -30,4 +32,9 @@ public function end(): ByteOffset
{
return $this->end;
}

public function __toString(): string
{
return sprintf('%s-%s', $this->start->toInt(), $this->end->toInt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,20 @@ function foo(): void
Assert::assertCount(0, $diagnostics);
}
);
yield new DiagnosticExample(
title: 'variable captured by closure',
source: <<<'PHP'
<?php
$classFqns = ['string'];
function (string $classFqn) use (&$classFqns): string {
$classFqns[] = 'boo';
}
PHP,
valid: true,
assertion: function (Diagnostics $diagnostics): void {
Assert::assertCount(0, $diagnostics);
}
);
}

public function enter(NodeContextResolver $resolver, Frame $frame, Node $node): iterable
Expand Down
2 changes: 1 addition & 1 deletion lib/WorseReflection/Core/Diagnostics.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(private array $diagnostics)
public function __toString(): string
{
return implode("\n", array_map(function (Diagnostic $diagnostic) {
return sprintf('[%s] %s', $diagnostic->severity()->toString(), $diagnostic->message());
return sprintf('[%s] %s (%s))', $diagnostic->severity()->toString(), $diagnostic->message(), $diagnostic->range()->__toString());
}, $this->diagnostics));
}

Expand Down
Loading