diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/SparkPostResponseTest.php | 97 | ||||
-rw-r--r-- | test/unit/SparkPostTest.php | 42 | ||||
-rw-r--r-- | test/unit/TransmissionTest.php | 30 |
3 files changed, 75 insertions, 94 deletions
diff --git a/test/unit/SparkPostResponseTest.php b/test/unit/SparkPostResponseTest.php index db8600a..efdec1a 100644 --- a/test/unit/SparkPostResponseTest.php +++ b/test/unit/SparkPostResponseTest.php @@ -1,14 +1,13 @@ <?php + namespace SparkPost\Test; use SparkPost\SparkPostResponse; -use Psr\Http\Message\StreamInterface; -use Psr\Http\Message\ResponseInterface; use Mockery; class SparkPostResponseTest extends \PHPUnit_Framework_TestCase { - /** + /** * (non-PHPdoc). * * @before @@ -17,120 +16,118 @@ class SparkPostResponseTest extends \PHPUnit_Framework_TestCase */ public function setUp() { - $this->returnValue = 'some_value_to_return'; + $this->returnValue = 'some_value_to_return'; $this->responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface'); } public function testGetProtocolVersion() - { - $this->responseMock->shouldReceive('getProtocolVersion')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + { + $this->responseMock->shouldReceive('getProtocolVersion')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->getProtocolVersion(), $sparkpostResponse->getProtocolVersion()); } public function testWithProtocolVersion() - { - $param = 'protocol version'; + { + $param = 'protocol version'; - $this->responseMock->shouldReceive('withProtocolVersion')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + $this->responseMock->shouldReceive('withProtocolVersion')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->withProtocolVersion($param), $sparkpostResponse->withProtocolVersion($param)); } public function testGetHeaders() - { - $this->responseMock->shouldReceive('getHeaders')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + { + $this->responseMock->shouldReceive('getHeaders')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->getHeaders(), $sparkpostResponse->getHeaders()); } public function testHasHeader() - { - $param = 'header'; + { + $param = 'header'; - $this->responseMock->shouldReceive('hasHeader')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + $this->responseMock->shouldReceive('hasHeader')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->hasHeader($param), $sparkpostResponse->hasHeader($param)); } public function testGetHeader() { - $param = 'header'; + $param = 'header'; - $this->responseMock->shouldReceive('getHeader')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + $this->responseMock->shouldReceive('getHeader')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->getHeader($param), $sparkpostResponse->getHeader($param)); } public function testGetHeaderLine() { - $param = 'header'; + $param = 'header'; - $this->responseMock->shouldReceive('getHeaderLine')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + $this->responseMock->shouldReceive('getHeaderLine')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->getHeaderLine($param), $sparkpostResponse->getHeaderLine($param)); } public function testWithHeader() { - $param = 'header'; - $param2 = 'value'; + $param = 'header'; + $param2 = 'value'; - $this->responseMock->shouldReceive('withHeader')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + $this->responseMock->shouldReceive('withHeader')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->withHeader($param, $param2), $sparkpostResponse->withHeader($param, $param2)); } public function testWithAddedHeader() { - $param = 'header'; - $param2 = 'value'; - + $param = 'header'; + $param2 = 'value'; - $this->responseMock->shouldReceive('withAddedHeader')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + $this->responseMock->shouldReceive('withAddedHeader')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->withAddedHeader($param, $param2), $sparkpostResponse->withAddedHeader($param, $param2)); } public function testWithoutHeader() - { - $param = 'header'; + { + $param = 'header'; - $this->responseMock->shouldReceive('withoutHeader')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + $this->responseMock->shouldReceive('withoutHeader')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->withoutHeader($param), $sparkpostResponse->withoutHeader($param)); } public function testWithBody() { - $param = Mockery::mock('Psr\Http\Message\StreamInterface'); + $param = Mockery::mock('Psr\Http\Message\StreamInterface'); - $this->responseMock->shouldReceive('withBody')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + $this->responseMock->shouldReceive('withBody')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->withBody($param), $sparkpostResponse->withBody($param)); } public function testGetStatusCode() - { - $this->responseMock->shouldReceive('getStatusCode')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + { + $this->responseMock->shouldReceive('getStatusCode')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->getStatusCode(), $sparkpostResponse->getStatusCode()); } public function testWithStatus() { - $param = 'status'; + $param = 'status'; - $this->responseMock->shouldReceive('withStatus')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + $this->responseMock->shouldReceive('withStatus')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->withStatus($param), $sparkpostResponse->withStatus($param)); } public function testGetReasonPhrase() - { - $this->responseMock->shouldReceive('getReasonPhrase')->andReturn($this->returnValue); - $sparkpostResponse = new SparkPostResponse($this->responseMock); + { + $this->responseMock->shouldReceive('getReasonPhrase')->andReturn($this->returnValue); + $sparkpostResponse = new SparkPostResponse($this->responseMock); $this->assertEquals($this->responseMock->getReasonPhrase(), $sparkpostResponse->getReasonPhrase()); } } -?>
\ No newline at end of file diff --git a/test/unit/SparkPostTest.php b/test/unit/SparkPostTest.php index c5dca08..f1c8a56 100644 --- a/test/unit/SparkPostTest.php +++ b/test/unit/SparkPostTest.php @@ -3,16 +3,10 @@ namespace SparkPost\Test; use SparkPost\SparkPost; -use SparkPost\SparkPostResponse; use SparkPost\SparkPostPromise; -use Psr\Http\Message\ResponseInterface; -use Http\Promise\Promise; -use GuzzleHttp\Promise\Promise as GuzzlePromise; use GuzzleHttp\Promise\FulfilledPromise as GuzzleFulfilledPromise; use GuzzleHttp\Promise\RejectedPromise as GuzzleRejectedPromise; use Http\Adapter\Guzzle6\Promise as GuzzleAdapterPromise; -use Http\Client\Exception\HttpException; -use Http\Adapter\Guzzle6\Client; use Mockery; use SparkPost\Test\TestUtils\ClassUtils; @@ -25,18 +19,18 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase private $postTransmissionPayload = [ 'content' => [ - 'from' => [ 'name' => 'Sparkpost Team', 'email' => 'postmaster@sendmailfor.me' ], + 'from' => ['name' => 'Sparkpost Team', 'email' => 'postmaster@sendmailfor.me'], 'subject' => 'First Mailing From PHP', 'text' => 'Congratulations, {{name}}!! You just sent your very first mailing!', ], 'substitution_data' => ['name' => 'Avi'], 'recipients' => [ - ['address' => 'avi.goldman@sparkpost.com'] - ] + ['address' => 'avi.goldman@sparkpost.com'], + ], ]; - + private $getTransmissionPayload = [ - 'campaign_id' => 'thanksgiving' + 'campaign_id' => 'thanksgiving', ]; /** @@ -60,12 +54,12 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase Mockery::close(); } - public function testRequest() { + public function testRequest() + { $responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface'); $this->resource->setOptions(['async' => false]); $this->resource->httpClient->shouldReceive('sendRequest')->andReturn($responseMock); $this->assertInstanceOf('SparkPost\SparkPostResponse', $this->resource->request('POST', 'transmissions', $this->postTransmissionPayload)); - $promiseMock = Mockery::mock('Http\Promise\Promise'); $this->resource->setOptions(['async' => true]); @@ -155,7 +149,7 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase once()-> with(Mockery::type('GuzzleHttp\Psr7\Request'))-> andReturn($promiseMock); - + $promiseMock->shouldReceive('wait')->andThrow($exceptionMock); $exceptionMock->shouldReceive('getResponse->getStatusCode')->andReturn(500); @@ -171,7 +165,8 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase } } - public function testSuccessfulAsyncRequestWithThen() { + public function testSuccessfulAsyncRequestWithThen() + { $responseBody = ['results' => 'yay']; $responseMock = Mockery::mock('Psr\Http\Message\ResponseInterface'); $responseBodyMock = Mockery::mock(); @@ -180,26 +175,27 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase $responseBodyMock->shouldReceive('__toString')->andReturn(json_encode($responseBody)); $guzzlePromise = new GuzzleFulfilledPromise($responseMock); - + $promise = new SparkPostPromise(new GuzzleAdapterPromise($guzzlePromise, $this->resource->buildRequest('POST', 'transmissions', $this->postTransmissionPayload, []))); - $promise->then(function ($exception) use ($responseBody) { + $promise->then(function ($exception) use ($responseBody) { $this->assertEquals(200, $exception->getStatusCode()); $this->assertEquals($responseBody, $exception->getBody()); }, null)->wait(); } - public function testUnsuccessfulAsyncRequestWithThen() { + public function testUnsuccessfulAsyncRequestWithThen() + { $responseBody = ['results' => 'failed']; $exceptionMock = Mockery::mock('Http\Client\Exception\HttpException'); $exceptionMock->shouldReceive('getResponse->getStatusCode')->andReturn(500); $exceptionMock->shouldReceive('getResponse->getBody->__toString')->andReturn(json_encode($responseBody)); $guzzlePromise = new GuzzleRejectedPromise($exceptionMock); - + $promise = new SparkPostPromise(new GuzzleAdapterPromise($guzzlePromise, $this->resource->buildRequest('POST', 'transmissions', $this->postTransmissionPayload, []))); - $promise->then(null, function ($exception) use ($responseBody) { + $promise->then(null, function ($exception) use ($responseBody) { $this->assertEquals(500, $exception->getCode()); $this->assertEquals($responseBody, $exception->getBody()); })->wait(); @@ -220,7 +216,7 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase $this->assertEquals($promiseMock->getState(), $promise->getState()); $promiseMock->shouldReceive('getState')->once()->andReturn('rejected'); - $this->assertEquals('rejected', $promise->getState()); + $this->assertEquals('rejected', $promise->getState()); } /** @@ -228,7 +224,6 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase */ public function testUnsupportedAsyncRequest() { - $this->resource->setHttpClient(Mockery::mock('Http\Client\HttpClient')); $this->resource->asyncRequest('POST', 'transmissions', $this->postTransmissionPayload); @@ -237,7 +232,7 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase public function testGetHttpHeaders() { $headers = $this->resource->getHttpHeaders([ - 'Custom-Header' => 'testing' + 'Custom-Header' => 'testing', ]); $version = self::$utils->getProperty($this->resource, 'version'); @@ -276,5 +271,4 @@ class SparkPostTest extends \PHPUnit_Framework_TestCase self::$utils->setProperty($this->resource, 'options', []); $this->resource->setOptions(['not' => 'SPARKPOST_API_KEY']); } - } diff --git a/test/unit/TransmissionTest.php b/test/unit/TransmissionTest.php index f0a8ec9..84f16f0 100644 --- a/test/unit/TransmissionTest.php +++ b/test/unit/TransmissionTest.php @@ -3,16 +3,6 @@ namespace SparkPost\Test; use SparkPost\SparkPost; -use SparkPost\SparkPostResponse; -use SparkPost\SparkPostPromise; -use Psr\Http\Message\ResponseInterface; -use Http\Promise\Promise; -use GuzzleHttp\Promise\Promise as GuzzlePromise; -use GuzzleHttp\Promise\FulfilledPromise as GuzzleFulfilledPromise; -use GuzzleHttp\Promise\RejectedPromise as GuzzleRejectedPromise; -use Http\Adapter\Guzzle6\Promise as GuzzleAdapterPromise; -use Http\Client\Exception\HttpException; -use Http\Adapter\Guzzle6\Client; use Mockery; use SparkPost\Test\TestUtils\ClassUtils; @@ -25,7 +15,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase private $postTransmissionPayload = [ 'content' => [ - 'from' => [ 'name' => 'Sparkpost Team', 'email' => 'postmaster@sendmailfor.me' ], + 'from' => ['name' => 'Sparkpost Team', 'email' => 'postmaster@sendmailfor.me'], 'subject' => 'First Mailing From PHP', 'text' => 'Congratulations, {{name}}!! You just sent your very first mailing!', ], @@ -34,26 +24,26 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase [ 'address' => [ 'name' => 'Vincent', - 'email' => 'vincent.song@sparkpost.com' - ] + 'email' => 'vincent.song@sparkpost.com', + ], ], - [ 'address' => 'test@example.com' ] + ['address' => 'test@example.com'], ], 'cc' => [ [ 'address' => [ - 'email' => 'avi.goldman@sparkpost.com' + 'email' => 'avi.goldman@sparkpost.com', ], - ] + ], ], 'bcc' => [ ['address' => 'Emely Giraldo <emely.giraldo@sparkpost.com>'], - ] + ], ]; - + private $getTransmissionPayload = [ - 'campaign_id' => 'thanksgiving' + 'campaign_id' => 'thanksgiving', ]; /** @@ -83,7 +73,7 @@ class TransmissionTest extends \PHPUnit_Framework_TestCase public function testInvalidEmailFormat() { $this->postTransmissionPayload['recipients'][] = [ - 'address' => 'invalid email format' + 'address' => 'invalid email format', ]; $response = $this->resource->transmissions->post($this->postTransmissionPayload); |