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

30 lines
737 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 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;
2023-07-19 10:51:22 +02:00
use Revolt\EventLoop;
2022-02-18 18:29:09 +01:00
/**
* A fake duplex protocol stream
*/
class MockProtocolStream implements ProtocolReader, ProtocolWriter, EmitterInterface
{
use EmitterTrait;
/**
* Sends a Message to the client
*/
2023-07-19 10:51:22 +02:00
public function write(Message $msg): void
2022-02-18 18:29:09 +01:00
{
2023-07-19 10:51:22 +02:00
EventLoop::queue(function () use ($msg): void {
2022-02-18 18:29:09 +01:00
$this->emit('message', [Message::parse((string)$msg)]);
});
}
2022-04-28 20:12:50 +02:00
}