1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 16:59:45 +01:00
psalm/tests/LanguageServer/MockProtocolStream.php

41 lines
959 B
PHP
Raw Normal View History

2022-02-18 18:29:09 +01:00
<?php
2022-04-28 20:12:50 +02:00
declare(strict_types=1);
2022-02-18 18:29:09 +01:00
namespace Psalm\Tests\LanguageServer;
use Amp\Deferred;
use Amp\Loop;
use Amp\Promise;
use Psalm\Internal\LanguageServer\EmitterInterface;
2022-04-28 20:12:50 +02:00
use Psalm\Internal\LanguageServer\EmitterTrait;
use Psalm\Internal\LanguageServer\Message;
2022-02-18 18:29:09 +01:00
use Psalm\Internal\LanguageServer\ProtocolReader;
use Psalm\Internal\LanguageServer\ProtocolWriter;
/**
* A fake duplex protocol stream
*/
class MockProtocolStream implements ProtocolReader, ProtocolWriter, EmitterInterface
{
use EmitterTrait;
/**
* Sends a Message to the client
*
2022-04-28 20:28:59 +02:00
* @psalm-suppress PossiblyUnusedReturnValue
2022-02-18 18:29:09 +01:00
*/
public function write(Message $msg): Promise
{
2022-04-28 20:12:50 +02:00
Loop::defer(function () use ($msg): void {
2022-02-18 18:29:09 +01:00
$this->emit('message', [Message::parse((string)$msg)]);
});
// Create a new promisor
$deferred = new Deferred;
$deferred->resolve(null);
return $deferred->promise();
}
2022-04-28 20:12:50 +02:00
}