1+ <?php
2+
3+ namespace Uecode \Bundle \QPushBundle \Tests \Provider ;
4+
5+
6+ use Uecode \Bundle \QPushBundle \Event \Events ;
7+ use Uecode \Bundle \QPushBundle \Provider \SyncProvider ;
8+
9+ class SyncProviderTest extends \PHPUnit_Framework_TestCase
10+ {
11+ /**
12+ * @var \Uecode\Bundle\QPushBundle\Provider\SyncProvider
13+ */
14+ protected $ provider ;
15+
16+ /**
17+ * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
18+ */
19+ protected $ dispatcher ;
20+
21+ /**
22+ * @var \Symfony\Bridge\Monolog\Logger
23+ */
24+ protected $ logger ;
25+
26+ public function setUp ()
27+ {
28+ $ this ->dispatcher = $ this ->getMock (
29+ 'Symfony\Component\EventDispatcher\EventDispatcherInterface '
30+ );
31+
32+ $ this ->provider = $ this ->getSyncProvider ();
33+ }
34+
35+ public function testGetProvider ()
36+ {
37+ $ provider = $ this ->provider ->getProvider ();
38+
39+ $ this ->assertEquals ('Sync ' , $ provider );
40+ }
41+
42+ public function testPublish ()
43+ {
44+ $ this ->dispatcher
45+ ->expects ($ this ->once ())
46+ ->method ('dispatch ' )
47+ ->with (
48+ Events::Message ($ this ->provider ->getName ()),
49+ new \PHPUnit_Framework_Constraint_IsInstanceOf ('Uecode\Bundle\QPushBundle\Event\MessageEvent ' )
50+ );
51+
52+ $ this ->provider ->publish (['foo ' => 'bar ' ]);
53+ }
54+
55+ public function testCreate ()
56+ {
57+ $ this ->setNoOpExpectation ();
58+
59+ $ this ->provider ->create ();
60+ }
61+
62+ public function testDestroy ()
63+ {
64+ $ this ->setNoOpExpectation ();
65+
66+ $ this ->provider ->destroy ();
67+ }
68+
69+ public function testDelete ()
70+ {
71+ $ this ->setNoOpExpectation ();
72+
73+ $ this ->provider ->delete ('foo ' );
74+ }
75+
76+ public function testReceive ()
77+ {
78+ $ this ->setNoOpExpectation ();
79+
80+ $ this ->provider ->receive ();
81+ }
82+
83+
84+ protected function getSyncProvider ()
85+ {
86+ $ options = [
87+ 'logging_enabled ' => false ,
88+ 'push_notifications ' => true ,
89+ 'notification_retries ' => 3 ,
90+ 'message_delay ' => 0 ,
91+ 'message_timeout ' => 30 ,
92+ 'message_expiration ' => 604800 ,
93+ 'messages_to_receive ' => 1 ,
94+ 'receive_wait_time ' => 3 ,
95+ 'subscribers ' => [
96+ [ 'protocol ' => 'http ' , 'endpoint ' => 'http://fake.com ' ]
97+ ]
98+ ];
99+
100+ $ cache = $ this ->getMock (
101+ 'Doctrine\Common\Cache\PhpFileCache ' ,
102+ [],
103+ ['/tmp ' , 'qpush.aws.test.php ' ]
104+ );
105+
106+ $ this ->logger = $ this ->getMock (
107+ 'Symfony\Bridge\Monolog\Logger ' , [], ['qpush.test ' ]
108+ );
109+
110+ return new SyncProvider ('test ' , $ options , $ this ->dispatcher , $ cache , $ this ->logger );
111+ }
112+
113+ protected function setNoOpExpectation ()
114+ {
115+ $ this ->dispatcher
116+ ->expects ($ this ->never ())
117+ ->method (new \PHPUnit_Framework_Constraint_IsAnything ());
118+
119+ $ this ->logger
120+ ->expects ($ this ->never ())
121+ ->method (new \PHPUnit_Framework_Constraint_IsAnything ());
122+ }
123+ }
0 commit comments