|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Phpactor\Extension\LanguageServer\Tests\Unit\CodeAction; |
| 4 | + |
| 5 | +use Amp\CancellationTokenSource; |
| 6 | +use Amp\Success; |
| 7 | +use Phpactor\Extension\LanguageServer\CodeAction\ClosureCodeActionProvider; |
| 8 | +use Phpactor\Extension\LanguageServer\CodeAction\OutsourcedCodeActionProvider; |
| 9 | +use Phpactor\Extension\LanguageServer\Tests\Unit\LanguageServerTestCase; |
| 10 | +use Phpactor\LanguageServerProtocol\CodeAction; |
| 11 | +use Phpactor\LanguageServer\Core\CodeAction\AggregateCodeActionProvider; |
| 12 | +use Phpactor\LanguageServer\Test\ProtocolFactory; |
| 13 | +use Psr\Log\Test\TestLogger; |
| 14 | +use function Amp\Promise\wait; |
| 15 | + |
| 16 | +class OutsourcedCodeActionProviderTest extends LanguageServerTestCase |
| 17 | +{ |
| 18 | + protected function setUp(): void |
| 19 | + { |
| 20 | + $this->workspace()->reset(); |
| 21 | + } |
| 22 | + |
| 23 | + public function testLogMessageWhenTokenIsAlreadyCancelled(): void |
| 24 | + { |
| 25 | + $logger = new TestLogger(); |
| 26 | + $provider = new OutsourcedCodeActionProvider( |
| 27 | + [ |
| 28 | + realpath(__DIR__ . '/../../../../../../bin/phpactor'), |
| 29 | + 'language-server:code-action', |
| 30 | + ], |
| 31 | + $this->workspace()->path(), |
| 32 | + $logger, |
| 33 | + new AggregateCodeActionProvider( |
| 34 | + new ClosureCodeActionProvider(function () { |
| 35 | + return new Success([new CodeAction(title: 'hello')]); |
| 36 | + }) |
| 37 | + ), |
| 38 | + ); |
| 39 | + $cancelSource = (new CancellationTokenSource()); |
| 40 | + $cancelSource->cancel(); |
| 41 | + $codeActions = wait($provider->provideActionsFor( |
| 42 | + ProtocolFactory::textDocumentItem('file:///foo', '<?php Foobar::class;'), |
| 43 | + ProtocolFactory::range(1, 2, 3, 4), |
| 44 | + $cancelSource->getToken() |
| 45 | + )); |
| 46 | + |
| 47 | + self::assertCount(0, $codeActions); |
| 48 | + /** @phpstan-ignore-next-line */ |
| 49 | + self::assertStringContainsString('Could not write to stdin', $logger->recordsByLevel['debug'][0]['message']); |
| 50 | + } |
| 51 | +} |
0 commit comments