DeliveriesTest.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WonderPush\Api; |
| 4 | |
| 5 | class DeliveriesTest extends \WonderPush\TestCase { |
| 6 | |
| 7 | /** @var \WonderPush\WonderPush */ |
| 8 | protected $wp; |
| 9 | /** @var Deliveries */ |
| 10 | protected $api; |
| 11 | |
| 12 | protected function setUp() { |
| 13 | $this->wp = \WonderPush\WonderPushTest::getWonderPush(); |
| 14 | $this->api = $this->wp->deliveries(); |
| 15 | } |
| 16 | |
| 17 | public function testSendNotification() { |
| 18 | /** @noinspection PhpUnhandledExceptionInspection */ |
| 19 | $response = $this->api->create( |
| 20 | \WonderPush\Params\DeliveriesCreateParams::_new() |
| 21 | ->setTargetSegmentIds('@NOBODY') |
| 22 | ->setNotification(\WonderPush\Obj\Notification::_new() |
| 23 | ->setAlert(\WonderPush\Obj\NotificationAlert::_new() |
| 24 | ->setText('Test PHP lib') |
| 25 | )) |
| 26 | ); |
| 27 | $this->assertTrue($response->isSuccess()); |
| 28 | $this->assertSame(\WonderPush\Obj\NullObject::getInstance(), $response->getCampaignId()); |
| 29 | $this->assertNotNull($response->getNotificationId()); |
| 30 | } |
| 31 | |
| 32 | public function testSendNotificationArrayParameters() { |
| 33 | /** @noinspection PhpUnhandledExceptionInspection */ |
| 34 | $response = $this->api->create( |
| 35 | \WonderPush\Params\DeliveriesCreateParams::_new() |
| 36 | ->setTargetSegmentIds('@NOBODY') |
| 37 | ->setNotification(array( |
| 38 | 'alert' => array( |
| 39 | 'text' => 'Test PHP lib', |
| 40 | ))) |
| 41 | ); |
| 42 | $this->assertTrue($response->isSuccess()); |
| 43 | $this->assertSame(\WonderPush\Obj\NullObject::getInstance(), $response->getCampaignId()); |
| 44 | $this->assertNotNull($response->getNotificationId()); |
| 45 | } |
| 46 | |
| 47 | public function testSendNotificationNoParameter() { |
| 48 | $exception = null; |
| 49 | try { |
| 50 | $this->api->create(array()); |
| 51 | } catch (\Exception $ex) { |
| 52 | $exception = $ex; |
| 53 | } |
| 54 | $this->assertInstanceOf('\WonderPush\Errors\Server', $exception); |
| 55 | /* @var $exception \WonderPush\Errors\Server */ |
| 56 | $this->assertInstanceOf('\WonderPush\Net\Request', $exception->getRequest()); |
| 57 | $this->assertInstanceOf('\WonderPush\Net\Response', $exception->getResponse()); |
| 58 | $this->assertEquals('10002', $exception->getCodeStr()); |
| 59 | $this->assertEquals(10002, $exception->getCode()); |
| 60 | $this->assertInternalType('string', $exception->getMessage()); |
| 61 | $this->assertNotEmpty($exception->getMessage()); |
| 62 | } |
| 63 | |
| 64 | } |
| 65 |