|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Push notification services abstraction (http://github.com/juliangut/tify) |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/juliangut/tify for the canonical source repository |
|
6
|
|
|
* |
|
7
|
|
|
* @license https://github.com/juliangut/tify/blob/master/LICENSE |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Jgut\Tify\Tests\Adapter\Gcm; |
|
11
|
|
|
|
|
12
|
|
|
use Jgut\Tify\Adapter\Gcm\GcmAdapter; |
|
13
|
|
|
use Jgut\Tify\Adapter\Gcm\GcmBuilder; |
|
14
|
|
|
use Jgut\Tify\Adapter\Gcm\GcmMessage; |
|
15
|
|
|
use Jgut\Tify\Message; |
|
16
|
|
|
use Jgut\Tify\Notification; |
|
17
|
|
|
use Jgut\Tify\Receiver\GcmReceiver; |
|
18
|
|
|
use ZendService\Google\Gcm\Client; |
|
19
|
|
|
use ZendService\Google\Gcm\Response; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Gcm adapter tests. |
|
23
|
|
|
*/ |
|
24
|
|
|
class GcmAdapterTest extends \PHPUnit_Framework_TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var \Jgut\Tify\Adapter\Gcm\GcmAdapter |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $adapter; |
|
30
|
|
|
|
|
31
|
|
|
public function setUp() |
|
32
|
|
|
{ |
|
33
|
|
|
$message = $this->getMock(GcmMessage::class, [], [], '', false); |
|
34
|
|
|
$message->expects(self::any())->method('getRegistrationIds')->will(self::returnValue(['aaa', 'bbb'])); |
|
35
|
|
|
|
|
36
|
|
|
$response = $this->getMock(Response::class, [], [], '', false); |
|
37
|
|
|
$response->expects(self::any())->method('getResults') |
|
38
|
|
|
->will(self::returnValue(['aaa' => [], 'bbb' => ['error' => 'NotRegistered']])); |
|
39
|
|
|
|
|
40
|
|
|
$client = $this->getMock(Client::class, [], [], '', false); |
|
41
|
|
|
$client->expects(self::any())->method('send')->will(self::returnValue($response)); |
|
42
|
|
|
|
|
43
|
|
|
$builder = $this->getMock(GcmBuilder::class, [], [], '', false); |
|
44
|
|
|
$builder->expects(self::any())->method('buildPushClient')->will(self::returnValue($client)); |
|
45
|
|
|
$builder->expects(self::any())->method('buildPushMessage')->will(self::returnValue($message)); |
|
46
|
|
|
|
|
47
|
|
|
$this->adapter = new GcmAdapter(['api_key' => 'aaa'], $builder); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @expectedException \Jgut\Tify\Exception\AdapterException |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testInvalidApiKey() |
|
54
|
|
|
{ |
|
55
|
|
|
new GcmAdapter(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testSend() |
|
59
|
|
|
{ |
|
60
|
|
|
$message = $this->getMock(Message::class, [], [], '', false); |
|
61
|
|
|
|
|
62
|
|
|
$receiver = $this->getMock(GcmReceiver::class, [], [], '', false); |
|
63
|
|
|
$receiver->expects(self::any())->method('getToken')->will(self::returnValue('aaa')); |
|
64
|
|
|
|
|
65
|
|
|
$notification = new Notification($message, [$receiver]); |
|
66
|
|
|
$this->adapter->send($notification); |
|
67
|
|
|
|
|
68
|
|
|
self::assertCount(2, $notification->getResults()); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|