MessageTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /*
  3. * This file is part of Chrome PHP.
  4. *
  5. * (c) Soufiane Ghzal <sghzal@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace HeadlessChromium\Test\Communication;
  11. use HeadlessChromium\Communication\Message;
  12. use PHPUnit\Framework\TestCase;
  13. /**
  14. * @covers \HeadlessChromium\Communication\Message
  15. */
  16. class MessageTest extends TestCase
  17. {
  18. public function testMessage(): void
  19. {
  20. $message = new Message('foo', ['bar' => 'baz']);
  21. self::assertEquals(Message::getLastMessageId(), $message->getId());
  22. self::assertEquals('foo', $message->getMethod());
  23. self::assertEquals(['bar' => 'baz'], $message->getParams());
  24. self::assertEquals(
  25. \json_encode(['id' => $message->getId(), 'method' => 'foo', 'params' => ['bar' => 'baz']]),
  26. (string) $message
  27. );
  28. $message2 = new Message('qux', ['quux' => 'corge']);
  29. self::assertEquals(Message::getLastMessageId(), $message2->getId());
  30. self::assertNotSame($message->getId(), $message2->getId());
  31. self::assertEquals('qux', $message2->getMethod());
  32. self::assertEquals(['quux' => 'corge'], $message2->getParams());
  33. }
  34. }