2018-11-25 22:43:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace BeyondCode\LaravelWebSockets\Tests\Mocks;
|
|
|
|
|
|
|
|
|
|
use GuzzleHttp\Psr7\Request;
|
|
|
|
|
use Ratchet\ConnectionInterface;
|
|
|
|
|
use PHPUnit\Framework\Assert as PHPUnit;
|
|
|
|
|
|
|
|
|
|
class Connection implements ConnectionInterface
|
|
|
|
|
{
|
|
|
|
|
/** @var Request */
|
|
|
|
|
public $httpRequest;
|
|
|
|
|
|
2018-11-25 23:20:18 +00:00
|
|
|
public $sentData = [];
|
2018-11-25 22:43:43 +00:00
|
|
|
|
|
|
|
|
function send($data)
|
|
|
|
|
{
|
|
|
|
|
$this->sentData[] = json_decode($data, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function close()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Implement close() method.
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-25 23:20:18 +00:00
|
|
|
public function assertSentEvent(string $name, array $additionalParameters = [])
|
2018-11-25 22:43:43 +00:00
|
|
|
{
|
2018-11-25 23:20:18 +00:00
|
|
|
$event = collect($this->sentData)->firstWhere('event', '=', $name);
|
|
|
|
|
|
2018-11-25 22:43:43 +00:00
|
|
|
PHPUnit::assertTrue(
|
2018-11-25 23:20:18 +00:00
|
|
|
! is_null($event)
|
2018-11-25 22:43:43 +00:00
|
|
|
);
|
2018-11-25 23:20:18 +00:00
|
|
|
|
|
|
|
|
foreach ($additionalParameters as $parameter => $value) {
|
|
|
|
|
PHPUnit::assertSame($event[$parameter], $value);
|
|
|
|
|
}
|
2018-11-25 22:43:43 +00:00
|
|
|
}
|
|
|
|
|
}
|