diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/APIResourceTest.php | 19 | ||||
-rw-r--r-- | test/unit/MessageEventTest.php | 71 | ||||
-rw-r--r-- | test/unit/TransmissionTest.php | 16 |
3 files changed, 106 insertions, 0 deletions
diff --git a/test/unit/APIResourceTest.php b/test/unit/APIResourceTest.php index 1d29c55..c2b0c2a 100644 --- a/test/unit/APIResourceTest.php +++ b/test/unit/APIResourceTest.php @@ -84,6 +84,25 @@ class APIResourceTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($testBody, $this->resource->get('test')); } + public function testGetCommaSeparated() { + $testBody = ['results'=>['my'=>'test']]; + $requestArray = [ + "param1" => "param1val", + "param2" => ["param2val1", "param2val2"] + ]; + $expectedGetParams = "param1=param1val¶m2=" . urlencode("param2val1,param2val2"); + + $responseMock = Mockery::mock(); + $this->sparkPostMock->httpAdapter->shouldReceive('send')-> + once()-> + with(matchesPattern("/.*\/test\?{$expectedGetParams}/"), 'GET', Mockery::type('array'), null)-> + andReturn($responseMock); + $responseMock->shouldReceive('getStatusCode')->andReturn(200); + $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($testBody)); + + $this->assertEquals($testBody, $this->resource->get('test', $requestArray)); + } + public function testDelete() { $responseMock = Mockery::mock(); $this->sparkPostMock->httpAdapter->shouldReceive('send')-> diff --git a/test/unit/MessageEventTest.php b/test/unit/MessageEventTest.php new file mode 100644 index 0000000..48657e6 --- /dev/null +++ b/test/unit/MessageEventTest.php @@ -0,0 +1,71 @@ +<?php + +namespace SparkPost; + +use \Mockery; + + +class MessageEventTest extends \PHPUnit_Framework_TestCase +{ + private $sparkPostMock; + private $sut; + + /** + * (non-PHPdoc) + * @before + * @see PHPUnit_Framework_TestCase::setUp() + */ + public function setUp() + { + $this->sparkPostMock = Mockery::mock('SparkPost\SparkPost', function ($mock) { + $mock->shouldReceive('getHttpHeaders')->andReturn([]); + }); + $this->sparkPostMock->httpAdapter = Mockery::mock(); + $this->sut = new MessageEvents($this->sparkPostMock); + } + + public function testDateTimeConversion() + { + $testBody = ['results' => ['my' => 'test']]; + $testFrom = new \DateTime("1978-08-27 04:05:02"); + $testFromStr = urlencode("1978-08-27T04:05"); + $testTo = new \DateTime("2016-04-04 19:00"); + $testToStr = urlencode("2016-04-04T19:00"); + + $responseMock = Mockery::mock(); + $this->sparkPostMock->httpAdapter->shouldReceive('send')-> + once()-> + with("/message-events/?from={$testFromStr}&to={$testToStr}", 'GET', Mockery::type('array'), null)-> + andReturn($responseMock); + $responseMock->shouldReceive('getStatusCode')->andReturn(200); + $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($testBody)); + + $this->assertEquals($testBody, $this->sut->search(["from" => $testFrom, "to" => $testTo])); + } + + public function testDocumentation() { + $testBody = ['results' => ['my' => 'test']]; + $responseMock = Mockery::mock(); + $this->sparkPostMock->httpAdapter->shouldReceive('send')-> + once()-> + with("/message-events/events/documentation", 'GET', Mockery::type('array'), null)-> + andReturn($responseMock); + $responseMock->shouldReceive('getStatusCode')->andReturn(200); + $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($testBody)); + + $this->assertEquals($testBody, $this->sut->documentation()); + } + + public function testSamples() { + $testBody = ['results' => ['my' => 'test']]; + $responseMock = Mockery::mock(); + $this->sparkPostMock->httpAdapter->shouldReceive('send')-> + once()-> + with("/message-events/events/samples?events=".urlencode("delivery,bounce"), 'GET', Mockery::type('array'), null)-> + andReturn($responseMock); + $responseMock->shouldReceive('getStatusCode')->andReturn(200); + $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($testBody)); + + $this->assertEquals($testBody, $this->sut->samples(["delivery", "bounce"])); + } +}
\ No newline at end of file diff --git a/test/unit/TransmissionTest.php b/test/unit/TransmissionTest.php index a985883..ba29b3b 100644 --- a/test/unit/TransmissionTest.php +++ b/test/unit/TransmissionTest.php @@ -44,6 +44,22 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($responseBody, $this->resource->send($body)); } + public function testSendDateTimeConversion() + { + $testStartTime = new \DateTime("2016-08-27 13:01:02", new \DateTimeZone("UTC")); + + $responseMock = Mockery::mock(); + $responseBody = ['results'=>'yay']; + $this->sparkPostMock->httpAdapter->shouldReceive('send')-> + once()-> + with('/.*\/transmissions/', 'POST', Mockery::type('array'), matchesPattern('/"start_time":"2016-08-27T13:01:02\+00:00"/'))-> + andReturn($responseMock); + $responseMock->shouldReceive('getStatusCode')->andReturn(200); + $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($responseBody)); + + $this->assertEquals($responseBody, $this->resource->send(['startTime'=>$testStartTime])); + } + public function testAllWithFilter() { $responseMock = Mockery::mock(); $responseBody = ['results'=>'yay']; |