|
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; |
|
11
|
|
|
|
|
12
|
|
|
use Jgut\Tify\Adapter\AbstractAdapter; |
|
13
|
|
|
use Jgut\Tify\Adapter\Apns\ApnsAdapter; |
|
14
|
|
|
use Jgut\Tify\Adapter\Gcm\GcmAdapter; |
|
15
|
|
|
use Jgut\Tify\Message; |
|
16
|
|
|
use Jgut\Tify\Notification; |
|
17
|
|
|
use Jgut\Tify\Result; |
|
18
|
|
|
use Jgut\Tify\Service; |
|
19
|
|
|
|
|
20
|
|
|
class ServiceTest extends \PHPUnit_Framework_TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var \Jgut\Tify\Service |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $service; |
|
26
|
|
|
|
|
27
|
|
|
public function setUp() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->service = new Service( |
|
30
|
|
|
$this->getMockForAbstractClass(AbstractAdapter::class, [], '', false), |
|
31
|
|
|
$this->getMockBuilder(Notification::class)->disableOriginalConstructor()->getMock() |
|
32
|
|
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testAccesorsMutators() |
|
36
|
|
|
{ |
|
37
|
|
|
$service = new Service; |
|
38
|
|
|
|
|
39
|
|
|
self::assertEmpty($service->getNotifications()); |
|
40
|
|
|
$service->addNotification( |
|
41
|
|
|
$this->getMockBuilder(Notification::class)->disableOriginalConstructor()->getMock() |
|
42
|
|
|
); |
|
43
|
|
|
self::assertCount(1, $service->getNotifications()); |
|
44
|
|
|
|
|
45
|
|
|
$service->clearNotifications(); |
|
46
|
|
|
self::assertCount(0, $service->getNotifications()); |
|
47
|
|
|
|
|
48
|
|
|
self::assertEmpty($service->getAdapters()); |
|
49
|
|
|
$service->addAdapter( |
|
50
|
|
|
$this->getMockBuilder(GcmAdapter::class)->disableOriginalConstructor()->getMock() |
|
51
|
|
|
); |
|
52
|
|
|
self::assertCount(1, $service->getAdapters()); |
|
53
|
|
|
|
|
54
|
|
|
$service->clearAdapters(); |
|
55
|
|
|
self::assertCount(0, $service->getAdapters()); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testSend() |
|
59
|
|
|
{ |
|
60
|
|
|
$result = new Result('aaa', new \DateTime('now', new \DateTimeZone('UTC'))); |
|
61
|
|
|
|
|
62
|
|
|
$adapter = $this->getMockBuilder(GcmAdapter::class)->disableOriginalConstructor()->getMock(); |
|
63
|
|
|
$adapter->expects(self::once())->method('push')->will(self::returnValue([$result])); |
|
64
|
|
|
$this->service->addAdapter($adapter); |
|
65
|
|
|
|
|
66
|
|
|
$message = $this->getMockBuilder(Message::class)->disableOriginalConstructor()->getMock(); |
|
|
|
|
|
|
67
|
|
|
$notification = $this->getMockBuilder(Notification::class)->disableOriginalConstructor()->getMock(); |
|
68
|
|
|
$this->service->clearNotifications(); |
|
69
|
|
|
$this->service->addNotification($notification); |
|
70
|
|
|
|
|
71
|
|
|
$results = $this->service->push(); |
|
72
|
|
|
self::assertCount(1, $results); |
|
73
|
|
|
self::assertEquals($result, $results[0]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function testFeedback() |
|
77
|
|
|
{ |
|
78
|
|
|
$result = new Result('aaa', new \DateTime('now', new \DateTimeZone('UTC'))); |
|
79
|
|
|
|
|
80
|
|
|
$adapter = $this->getMockBuilder(ApnsAdapter::class)->disableOriginalConstructor()->getMock(); |
|
81
|
|
|
$adapter->expects(self::once())->method('feedback')->will(self::returnValue([$result])); |
|
82
|
|
|
$this->service->addAdapter($adapter); |
|
83
|
|
|
|
|
84
|
|
|
$results = $this->service->feedback(); |
|
85
|
|
|
self::assertCount(1, $results); |
|
86
|
|
|
self::assertEquals($result, $results[0]); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.