RestTest.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WonderPush\Api; |
| 4 | |
| 5 | class RestTest extends \WonderPush\TestCase { |
| 6 | |
| 7 | /** @var \WonderPush\WonderPush */ |
| 8 | protected $wp; |
| 9 | |
| 10 | protected function setUp() { |
| 11 | $this->wp = \WonderPush\WonderPushTest::getWonderPush(); |
| 12 | } |
| 13 | |
| 14 | public function testGetFakeEndpoint() { |
| 15 | $response = $this->wp->rest()->get('/fake-endpoint'); |
| 16 | $this->assertInstanceOf('\WonderPush\Net\Response', $response); |
| 17 | $resp = $response->parsedBody(); |
| 18 | $this->assertInternalType('object', $resp); |
| 19 | $this->assertObjectHasAttribute('error', $resp); |
| 20 | $this->assertInternalType('object', $resp->error); |
| 21 | $this->assertObjectHasAttribute('status', $resp->error); |
| 22 | $this->assertInternalType('integer', $resp->error->status); |
| 23 | $this->assertEquals(404, $resp->error->status); |
| 24 | $this->assertObjectHasAttribute('code', $resp->error); |
| 25 | $this->assertInternalType('string', $resp->error->code); |
| 26 | $this->assertEquals('10000', $resp->error->code); |
| 27 | $this->assertObjectHasAttribute('message', $resp->error); |
| 28 | $this->assertInternalType('string', $resp->error->message); |
| 29 | } |
| 30 | |
| 31 | public function testGet() { |
| 32 | $response = $this->wp->rest()->get('/installations', array('limit' => 0)); |
| 33 | $this->assertInstanceOf('\WonderPush\Net\Response', $response); |
| 34 | $resp = $response->parsedBody(); |
| 35 | $this->assertInternalType('object', $resp); |
| 36 | $this->assertObjectHasAttribute('count', $resp); |
| 37 | $this->assertInternalType('integer', $resp->count); |
| 38 | } |
| 39 | |
| 40 | public function testSendNotification() { |
| 41 | $response = $this->wp->rest()->post('/deliveries', array( |
| 42 | 'targetSegmentIds' => array('@NOBODY'), |
| 43 | 'notification' => \WonderPush\Obj\Notification::_new() |
| 44 | ->setAlert(\WonderPush\Obj\NotificationAlert::_new() |
| 45 | ->setText('Test PHP lib') |
| 46 | ) |
| 47 | , |
| 48 | )); |
| 49 | $this->assertGreaterThanOrEqual(200, $response->getStatusCode()); |
| 50 | $this->assertLessThan(300, $response->getStatusCode()); |
| 51 | $this->assertAttributeEquals(true, 'success', $response->parsedBody()); |
| 52 | } |
| 53 | |
| 54 | } |
| 55 |