Skip to content

Commit 0a3035c

Browse files
committed
Add unit tests for Message Events::documentation and ::samples
1 parent 03c0f36 commit 0a3035c

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib/SparkPost/MessageEvent.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public function documentation() {
4444
}
4545

4646
/**
47-
* List an example of the event data that will be included in a response from the MessageEvent::search() method.
47+
* List examples of the event data that will be included in a response from the MessageEvent::search() method.
4848
*/
49-
public function samples() {
50-
return $this->get("events/samples", ["events" => "bounce"]);
49+
public function samples(Array $events) {
50+
return $this->get("events/samples", ["events"=>$events]);
5151
}
5252
}

test/unit/MessageEventTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,30 @@ public function testDateTimeConversion()
4242

4343
$this->assertEquals($testBody, $this->sut->search(["from" => $testFrom, "to" => $testTo]));
4444
}
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+
}
4571
}

0 commit comments

Comments
 (0)