diff options
Diffstat (limited to 'test/unit/TransmissionTest.php')
-rw-r--r-- | test/unit/TransmissionTest.php | 57 |
1 files changed, 24 insertions, 33 deletions
diff --git a/test/unit/TransmissionTest.php b/test/unit/TransmissionTest.php index 95fabe4..f09db7d 100644 --- a/test/unit/TransmissionTest.php +++ b/test/unit/TransmissionTest.php @@ -1,6 +1,5 @@ <?php namespace SparkPost\Test; - use SparkPost\Transmission; use SparkPost\Test\TestUtils\ClassUtils; use \Mockery; @@ -8,7 +7,7 @@ use \Mockery; class TransmissionTest extends \PHPUnit_Framework_TestCase { private static $utils; - private $adapterMock; + private $sparkPostMock; private $resource; /** @@ -17,35 +16,27 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase { * @see PHPUnit_Framework_TestCase::setUp() */ public function setUp() { - $this->adapterMock = Mockery::mock('Ivory\HttpAdapter\HttpAdapterInterface', function($mock) { - $mock->shouldReceive('setConfiguration'); - $mock->shouldReceive('getConfiguration->getUserAgent')->andReturn('php-sparkpost/0.2.0'); + $this->sparkPostMock = Mockery::mock('SparkPost\SparkPost', function($mock) { + $mock->shouldReceive('getHttpHeaders')->andReturn([]); }); - $this->resource = new Transmission($this->adapterMock, ['key'=>'a key']); + $this->sparkPostMock->httpAdapter = Mockery::mock(); + $this->resource = new Transmission($this->sparkPostMock); self::$utils = new ClassUtils($this->resource); - - self::$utils->setProperty($this->resource, 'httpAdapter', $this->adapterMock); } - public function tearDown() - { - Mockery::close(); - } - - public function testConstructorSetsUpAdapterAndConfig() { - $adapter = self::$utils->getProperty($this->resource, 'httpAdapter'); - $this->assertRegExp('/php-sparkpost.*/', $adapter->getConfiguration()->getUserAgent()); + public function tearDown(){ + Mockery::close(); } - public function testSend() { $responseMock = Mockery::mock(); $body = ['text'=>'awesomesauce', 'content'=>['subject'=>'awesomeness']]; $responseBody = ["results"=>"yay"]; - $this->adapterMock->shouldReceive('send')-> - once()-> - with('/.*\/transmissions/', 'POST', Mockery::type('array'), Mockery::type('string'))-> - andReturn($responseMock); + + $this->sparkPostMock->httpAdapter->shouldReceive('send')-> + once()-> + with('/.*\/transmissions/', 'POST', Mockery::type('array'), Mockery::type('string'))-> + andReturn($responseMock); $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($responseBody)); @@ -55,10 +46,10 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase { public function testAllWithFilter() { $responseMock = Mockery::mock(); $responseBody = ["results"=>"yay"]; - $this->adapterMock->shouldReceive('send')-> - once()-> - with('/.*transmissions.*?campaign_id=campaign&template_id=template/', 'GET', Mockery::type('array'), null)-> - andReturn($responseMock); + $this->sparkPostMock->httpAdapter->shouldReceive('send')-> + once()-> + with('/.*transmissions.*?campaign_id=campaign&template_id=template/', 'GET', Mockery::type('array'), null)-> + andReturn($responseMock); $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($responseBody)); @@ -68,10 +59,10 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase { public function testAllWithOutFilter() { $responseMock = Mockery::mock(); $responseBody = ["results"=>"yay"]; - $this->adapterMock->shouldReceive('send')-> - once()-> - with('/.*\/transmissions/', 'GET', Mockery::type('array'), null)-> - andReturn($responseMock); + $this->sparkPostMock->httpAdapter->shouldReceive('send')-> + once()-> + with('/.*\/transmissions/', 'GET', Mockery::type('array'), null)-> + andReturn($responseMock); $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($responseBody)); @@ -81,10 +72,10 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase { public function testFind() { $responseMock = Mockery::mock(); $responseBody = ["results"=>"yay"]; - $this->adapterMock->shouldReceive('send')-> - once()-> - with('/.*\/transmissions.*\/test/', 'GET', Mockery::type('array'), null)-> - andReturn($responseMock); + $this->sparkPostMock->httpAdapter->shouldReceive('send')-> + once()-> + with('/.*\/transmissions.*\/test/', 'GET', Mockery::type('array'), null)-> + andReturn($responseMock); $responseMock->shouldReceive('getBody->getContents')->andReturn(json_encode($responseBody)); |