1
+ <?php
2
+
3
+ namespace SparkPost ;
4
+
5
+ use \Mockery ;
6
+
7
+
8
+ class MessageEventTest extends \PHPUnit_Framework_TestCase
9
+ {
10
+ private $ sparkPostMock ;
11
+ private $ sut ;
12
+
13
+ /**
14
+ * (non-PHPdoc)
15
+ * @before
16
+ * @see PHPUnit_Framework_TestCase::setUp()
17
+ */
18
+ public function setUp ()
19
+ {
20
+ $ this ->sparkPostMock = Mockery::mock ('SparkPost\SparkPost ' , function ($ mock ) {
21
+ $ mock ->shouldReceive ('getHttpHeaders ' )->andReturn ([]);
22
+ });
23
+ $ this ->sparkPostMock ->httpAdapter = Mockery::mock ();
24
+ $ this ->sut = new MessageEvents ($ this ->sparkPostMock );
25
+ }
26
+
27
+ public function testDateTimeConversion ()
28
+ {
29
+ $ testBody = ['results ' => ['my ' => 'test ' ]];
30
+ $ testFrom = new \DateTime ("1978-08-27 04:05:02 " );
31
+ $ testFromStr = urlencode ("1978-08-27T04:05 " );
32
+ $ testTo = new \DateTime ("2016-04-04 19:00 " );
33
+ $ testToStr = urlencode ("2016-04-04T19:00 " );
34
+
35
+ $ responseMock = Mockery::mock ();
36
+ $ this ->sparkPostMock ->httpAdapter ->shouldReceive ('send ' )->
37
+ once ()->
38
+ with ("/message-events/?from= {$ testFromStr }&to= {$ testToStr }" , 'GET ' , Mockery::type ('array ' ), null )->
39
+ andReturn ($ responseMock );
40
+ $ responseMock ->shouldReceive ('getStatusCode ' )->andReturn (200 );
41
+ $ responseMock ->shouldReceive ('getBody->getContents ' )->andReturn (json_encode ($ testBody ));
42
+
43
+ $ this ->assertEquals ($ testBody , $ this ->sut ->search (["from " => $ testFrom , "to " => $ testTo ]));
44
+ }
45
+
46
+ public function testDocumentation () {
47
+ $ testBody = ['results ' => ['my ' => 'test ' ]];
48
+ $ responseMock = Mockery::mock ();
49
+ $ this ->sparkPostMock ->httpAdapter ->shouldReceive ('send ' )->
50
+ once ()->
51
+ with ("/message-events/events/documentation " , 'GET ' , Mockery::type ('array ' ), null )->
52
+ andReturn ($ responseMock );
53
+ $ responseMock ->shouldReceive ('getStatusCode ' )->andReturn (200 );
54
+ $ responseMock ->shouldReceive ('getBody->getContents ' )->andReturn (json_encode ($ testBody ));
55
+
56
+ $ this ->assertEquals ($ testBody , $ this ->sut ->documentation ());
57
+ }
58
+
59
+ public function testSamples () {
60
+ $ testBody = ['results ' => ['my ' => 'test ' ]];
61
+ $ responseMock = Mockery::mock ();
62
+ $ this ->sparkPostMock ->httpAdapter ->shouldReceive ('send ' )->
63
+ once ()->
64
+ with ("/message-events/events/samples?events= " .urlencode ("delivery,bounce " ), 'GET ' , Mockery::type ('array ' ), null )->
65
+ andReturn ($ responseMock );
66
+ $ responseMock ->shouldReceive ('getStatusCode ' )->andReturn (200 );
67
+ $ responseMock ->shouldReceive ('getBody->getContents ' )->andReturn (json_encode ($ testBody ));
68
+
69
+ $ this ->assertEquals ($ testBody , $ this ->sut ->samples (["delivery " , "bounce " ]));
70
+ }
71
+ }
0 commit comments