ResponseTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 HeadlessChromium\Communication\Response;
  13. use PHPUnit\Framework\TestCase;
  14. /**
  15. * @covers \HeadlessChromium\Communication\Response
  16. */
  17. class ResponseTest extends TestCase
  18. {
  19. public function testMessage(): void
  20. {
  21. $message = new Message('foo', ['bar' => 'baz']);
  22. $response = new Response(['id' => $message->getId(), 'bar' => 'foo'], $message);
  23. $this->assertSame($message, $response->getMessage());
  24. $this->assertTrue($response->isSuccessful());
  25. $this->assertTrue(isset($response['bar']));
  26. $this->assertEquals('foo', $response['bar']);
  27. $this->assertEquals(['id' => $message->getId(), 'bar' => 'foo'], $response->getData());
  28. }
  29. public function testIsNotSuccessful(): void
  30. {
  31. $message = new Message('foo', ['bar' => 'baz']);
  32. $response = new Response(['id' => $message->getId(), 'error' => 'foo'], $message);
  33. $this->assertFalse($response->isSuccessful());
  34. }
  35. }