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\Apns; |
11
|
|
|
|
12
|
|
|
use Jgut\Tify\Adapter\Apns\ApnsAdapter; |
13
|
|
|
use Jgut\Tify\Adapter\Apns\ApnsBuilder; |
14
|
|
|
use Jgut\Tify\Message; |
15
|
|
|
use Jgut\Tify\Notification; |
16
|
|
|
use Jgut\Tify\Receiver\ApnsReceiver; |
17
|
|
|
use ZendService\Apple\Apns\Client\Feedback as FeedbackClient; |
18
|
|
|
use ZendService\Apple\Apns\Client\Message as MessageClient; |
19
|
|
|
use ZendService\Apple\Apns\Message as ServiceMessage; |
20
|
|
|
use ZendService\Apple\Apns\Response\Feedback as FeedbackResponse; |
21
|
|
|
use ZendService\Apple\Apns\Response\Message as PushResponse; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Apns adapter tests. |
25
|
|
|
*/ |
26
|
|
|
class ApnsAdapterTest extends \PHPUnit_Framework_TestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var \Jgut\Tify\Adapter\Apns\ApnsAdapter |
30
|
|
|
*/ |
31
|
|
|
protected $adapter; |
32
|
|
|
|
33
|
|
|
public function setUp() |
34
|
|
|
{ |
35
|
|
|
$message = $this->getMock(ServiceMessage::class, [], [], '', false); |
36
|
|
|
$message->expects(self::any())->method('getToken')->will(self::returnValue(['aaa'])); |
37
|
|
|
|
38
|
|
|
$pushResponse = $this->getMock(PushResponse::class, [], [], '', false); |
39
|
|
|
$pushResponse->expects(self::any())->method('getCode')->will(self::returnValue(8)); |
40
|
|
|
|
41
|
|
|
$pushClient = $this->getMock(MessageClient::class, [], [], '', false); |
42
|
|
|
$pushClient->expects(self::any())->method('send')->will(self::returnValue($pushResponse)); |
43
|
|
|
|
44
|
|
|
$feedbackResponse = $this->getMock(FeedbackResponse::class, [], [], '', false); |
45
|
|
|
$feedbackResponse->expects(self::any())->method('getToken')->will(self::returnValue('aaa')); |
46
|
|
|
|
47
|
|
|
$feedbackClient = $this->getMock(FeedbackClient::class, [], [], '', false); |
48
|
|
|
$feedbackClient->expects(self::any())->method('feedback')->will(self::returnValue([$feedbackResponse])); |
49
|
|
|
|
50
|
|
|
$builder = $this->getMock(ApnsBuilder::class, [], [], '', false); |
51
|
|
|
$builder->expects(self::any())->method('buildPushClient')->will(self::returnValue($pushClient)); |
52
|
|
|
$builder->expects(self::any())->method('buildFeedbackClient')->will(self::returnValue($feedbackClient)); |
53
|
|
|
$builder->expects(self::any())->method('buildPushMessage')->will(self::returnValue($message)); |
54
|
|
|
|
55
|
|
|
$this->adapter = new ApnsAdapter( |
56
|
|
|
['certificate' => __DIR__ . '/../../../files/apns_certificate.pem'], |
57
|
|
|
false, |
58
|
|
|
$builder |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @expectedException \Jgut\Tify\Exception\AdapterException |
64
|
|
|
*/ |
65
|
|
|
public function testInvalidCertificate() |
66
|
|
|
{ |
67
|
|
|
new ApnsAdapter(['certificate' => 'fake_path']); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testSend() |
71
|
|
|
{ |
72
|
|
|
$message = $this->getMock(Message::class, [], [], '', false); |
73
|
|
|
|
74
|
|
|
$receiver = $this->getMock(ApnsReceiver::class, [], [], '', false); |
75
|
|
|
|
76
|
|
|
$notification = new Notification($message, [$receiver]); |
77
|
|
|
$this->adapter->send($notification); |
78
|
|
|
|
79
|
|
|
self::assertCount(1, $notification->getResults()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testFeedback() |
83
|
|
|
{ |
84
|
|
|
self::assertCount(1, $this->adapter->feedback()); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|