Completed
Push — master ( 020c5c...9dbce5 )
by Julián
08:49
created

ApnsAdapterTest::setUp()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 1
eloc 19
nc 1
nop 0
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);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
36
        $message->expects(self::any())->method('getToken')->will(self::returnValue(['aaa']));
37
38
        $pushResponse = $this->getMock(PushResponse::class, [], [], '', false);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
39
        $pushResponse->expects(self::any())->method('getCode')->will(self::returnValue(8));
40
41
        $pushClient = $this->getMock(MessageClient::class, [], [], '', false);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
42
        $pushClient->expects(self::any())->method('send')->will(self::returnValue($pushResponse));
43
44
        $feedbackResponse = $this->getMock(FeedbackResponse::class, [], [], '', false);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
45
        $feedbackResponse->expects(self::any())->method('getToken')->will(self::returnValue('aaa'));
46
47
        $feedbackClient = $this->getMock(FeedbackClient::class, [], [], '', false);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
48
        $feedbackClient->expects(self::any())->method('feedback')->will(self::returnValue([$feedbackResponse]));
49
50
        $builder = $this->getMock(ApnsBuilder::class, [], [], '', false);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
73
74
        $receiver = $this->getMock(ApnsReceiver::class, [], [], '', false);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
75
76
        $notification = new Notification($message, [$receiver]);
77
        $results = $this->adapter->push($notification);
78
79
        self::assertCount(1, $results);
80
    }
81
82
    public function testFeedback()
83
    {
84
        self::assertCount(1, $this->adapter->feedback());
85
    }
86
}
87