1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apns; |
4
|
|
|
|
5
|
|
|
class ClientTest extends \PHPUnit_Framework_TestCase |
6
|
|
|
{ |
7
|
|
|
public function testCreateSandbox() |
8
|
|
|
{ |
9
|
|
|
$client = new Client('', true); |
10
|
|
|
$this->assertContains('development', $client->getServer()); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @dataProvider dataValidSslCert |
15
|
|
|
*/ |
16
|
|
|
public function testSslCert($sslCert) |
17
|
|
|
{ |
18
|
|
|
$client = new Client($sslCert, true); |
19
|
|
|
$this->assertSame($sslCert, $client->getSslCert()); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function dataValidSslCert() |
23
|
|
|
{ |
24
|
|
|
return [ |
25
|
|
|
['foo.pem'], |
26
|
|
|
[['foo.pem', 'bar']], |
27
|
|
|
]; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testCreateProd() |
31
|
|
|
{ |
32
|
|
|
$client = new Client('', false); |
33
|
|
|
$this->assertNotContains('develop', $client->getServer()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testCreatePushURI() |
37
|
|
|
{ |
38
|
|
|
$client = new Client('', true); |
39
|
|
|
$pushUri = $client->getPushURI((new Message())->setDeviceIdentifier('foobar')); |
40
|
|
|
|
41
|
|
|
$this->assertContains('develop', $pushUri); |
42
|
|
|
$this->assertContains('foobar', $pushUri); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testSend() |
46
|
|
|
{ |
47
|
|
|
$mock = $this->getMockCallable(); |
48
|
|
|
$client = new Client('', true, $mock); |
49
|
|
|
$message = new Message(); |
50
|
|
|
|
51
|
|
|
$mock->expects($this->once())->method('__invoke')->with($client, $message); |
52
|
|
|
|
53
|
|
|
$client->send($message); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
58
|
|
|
*/ |
59
|
|
|
private function getMockCallable() |
60
|
|
|
{ |
61
|
|
|
return $this->getMockBuilder('object')->setMethods(['__invoke'])->getMock(); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|