ReportPayloadTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace JPush\Tests;
  3. use PHPUnit\Framework\TestCase;
  4. class ReportPayloadTest extends TestCase {
  5. protected function setUp() {
  6. global $client;
  7. $this->payload = $client->push()
  8. ->setPlatform('all')
  9. ->addAllAudience()
  10. ->setNotificationAlert('Hello JPush');
  11. $this->reporter = $client->report();
  12. }
  13. public function testPusher0() {
  14. $payload = $this->payload;
  15. $response = $payload->send();
  16. $this->assertEquals('200', $response['http_code']);
  17. $body = $response['body'];
  18. $this->assertTrue(is_array($body));
  19. $this->assertEquals(2, count($body));
  20. $this->assertArrayHasKey('sendno', $body);
  21. $this->assertArrayHasKey('msg_id', $body);
  22. sleep(10);
  23. return $body['msg_id'];
  24. }
  25. public function testPusher1() {
  26. $payload = $this->payload;
  27. $response = $payload->send();
  28. $this->assertEquals('200', $response['http_code']);
  29. sleep(10);
  30. return $response['body']['msg_id'];
  31. }
  32. /**
  33. * @depends testPusher0
  34. * @depends testPusher1
  35. */
  36. public function testGetReceived($msg_id_0, $msg_id_1) {
  37. $response = $this->reporter->getReceived($msg_id_0);
  38. $this->assertEquals('200', $response['http_code']);
  39. $body = $response['body'];
  40. $this->assertTrue(is_array($body));
  41. $this->assertEquals(1, count($body));
  42. $this->assertTrue(is_array($body[0]));
  43. $this->assertArrayHasKey('msg_id', $body[0]);
  44. $response = $this->reporter->getReceived(array($msg_id_0, $msg_id_1));
  45. $this->assertEquals('200', $response['http_code']);
  46. $body = $response['body'];
  47. $this->assertTrue(is_array($body));
  48. $this->assertEquals(2, count($body));
  49. }
  50. /**
  51. * @depends testPusher0
  52. * @depends testPusher1
  53. */
  54. public function testGetMessages($msg_id_0, $msg_id_1) {
  55. $response = $this->reporter->getMessages($msg_id_0);
  56. $this->assertEquals('200', $response['http_code']);
  57. $body = $response['body'];
  58. $this->assertTrue(is_array($body));
  59. $this->assertEquals(1, count($body));
  60. $this->assertTrue(is_array($body[0]));
  61. $this->assertEquals(4, count($body[0]));
  62. $this->assertArrayHasKey('msg_id', $body[0]);
  63. $response = $this->reporter->getMessages(array($msg_id_0, $msg_id_1));
  64. $this->assertEquals('200', $response['http_code']);
  65. $body = $response['body'];
  66. $this->assertTrue(is_array($body));
  67. $this->assertEquals(2, count($body));
  68. }
  69. }