|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2019 LINE Corporation |
| 5 | + * |
| 6 | + * LINE Corporation licenses this file to you under the Apache License, |
| 7 | + * version 2.0 (the "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at: |
| 9 | + * |
| 10 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | + * License for the specific language governing permissions and limitations |
| 16 | + * under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +namespace LINE\Tests\LINEBot; |
| 20 | + |
| 21 | +use LINE\LINEBot; |
| 22 | +use LINE\Tests\LINEBot\Util\DummyHttpClient; |
| 23 | +use PHPUnit\Framework\TestCase; |
| 24 | +use DateTime; |
| 25 | +use DateTimeZone; |
| 26 | + |
| 27 | +class GetNumberOfMessagesSentTest extends TestCase |
| 28 | +{ |
| 29 | + public function testGetNumberOfSentReplyMessages() |
| 30 | + { |
| 31 | + $date = new DateTime(); |
| 32 | + $mock = function ($testRunner, $httpMethod, $url, $data) use ($date) { |
| 33 | + /** @var \PHPUnit\Framework\TestCase $testRunner */ |
| 34 | + $testRunner->assertEquals('GET', $httpMethod); |
| 35 | + $testRunner->assertEquals('https://api.line.me/v2/bot/message/delivery/reply', $url); |
| 36 | + $date->setTimezone(new DateTimeZone('Asia/Tokyo')); |
| 37 | + $testRunner->assertEquals([ |
| 38 | + 'date' => $date->format('Ymd') |
| 39 | + ], $data); |
| 40 | + return [ |
| 41 | + 'status' => 'ready', |
| 42 | + 'success' => 10000 |
| 43 | + ]; |
| 44 | + }; |
| 45 | + $bot = new LINEBot(new DummyHttpClient($this, $mock), ['channelSecret' => 'CHANNEL-SECRET']); |
| 46 | + $res = $bot->getNumberOfSentReplyMessages($date); |
| 47 | + |
| 48 | + $this->assertEquals(200, $res->getHTTPStatus()); |
| 49 | + $this->assertTrue($res->isSucceeded()); |
| 50 | + |
| 51 | + $data = $res->getJSONDecodedBody(); |
| 52 | + $this->assertEquals('ready', $data['status']); |
| 53 | + $this->assertEquals(10000, $data['success']); |
| 54 | + } |
| 55 | + |
| 56 | + public function testGetNumberOfSentPushMessages() |
| 57 | + { |
| 58 | + $date = new DateTime(); |
| 59 | + $mock = function ($testRunner, $httpMethod, $url, $data) use ($date) { |
| 60 | + /** @var \PHPUnit\Framework\TestCase $testRunner */ |
| 61 | + $testRunner->assertEquals('GET', $httpMethod); |
| 62 | + $testRunner->assertEquals('https://api.line.me/v2/bot/message/delivery/push', $url); |
| 63 | + $date->setTimezone(new DateTimeZone('Asia/Tokyo')); |
| 64 | + $testRunner->assertEquals([ |
| 65 | + 'date' => $date->format('Ymd') |
| 66 | + ], $data); |
| 67 | + return [ |
| 68 | + 'status' => 'ready', |
| 69 | + 'success' => 10000 |
| 70 | + ]; |
| 71 | + }; |
| 72 | + $bot = new LINEBot(new DummyHttpClient($this, $mock), ['channelSecret' => 'CHANNEL-SECRET']); |
| 73 | + $res = $bot->getNumberOfSentPushMessages($date); |
| 74 | + |
| 75 | + $this->assertEquals(200, $res->getHTTPStatus()); |
| 76 | + $this->assertTrue($res->isSucceeded()); |
| 77 | + |
| 78 | + $data = $res->getJSONDecodedBody(); |
| 79 | + $this->assertEquals('ready', $data['status']); |
| 80 | + $this->assertEquals(10000, $data['success']); |
| 81 | + } |
| 82 | + |
| 83 | + public function testGetNumberOfSentMulticastMessages() |
| 84 | + { |
| 85 | + $date = new DateTime(); |
| 86 | + $mock = function ($testRunner, $httpMethod, $url, $data) use ($date) { |
| 87 | + /** @var \PHPUnit\Framework\TestCase $testRunner */ |
| 88 | + $testRunner->assertEquals('GET', $httpMethod); |
| 89 | + $testRunner->assertEquals('https://api.line.me/v2/bot/message/delivery/multicast', $url); |
| 90 | + $date->setTimezone(new DateTimeZone('Asia/Tokyo')); |
| 91 | + $testRunner->assertEquals([ |
| 92 | + 'date' => $date->format('Ymd') |
| 93 | + ], $data); |
| 94 | + return [ |
| 95 | + 'status' => 'ready', |
| 96 | + 'success' => 10000 |
| 97 | + ]; |
| 98 | + }; |
| 99 | + $bot = new LINEBot(new DummyHttpClient($this, $mock), ['channelSecret' => 'CHANNEL-SECRET']); |
| 100 | + $res = $bot->getNumberOfSentMulticastMessages($date); |
| 101 | + |
| 102 | + $this->assertEquals(200, $res->getHTTPStatus()); |
| 103 | + $this->assertTrue($res->isSucceeded()); |
| 104 | + |
| 105 | + $data = $res->getJSONDecodedBody(); |
| 106 | + $this->assertEquals('ready', $data['status']); |
| 107 | + $this->assertEquals(10000, $data['success']); |
| 108 | + } |
| 109 | +} |
0 commit comments