diff options
author | beardyman <nornholdj@gmail.com> | 2015-09-30 21:44:52 -0400 |
---|---|---|
committer | beardyman <nornholdj@gmail.com> | 2015-09-30 21:44:52 -0400 |
commit | 97e0d2643db1969e299349968eea1d9c7a951d7f (patch) | |
tree | 609c4ee26facf953a8d56e855303519c3678c66b /test/unit/SparkPostTest.php | |
parent | c753d55e2025c3948fe8a59a660a881a429b8df2 (diff) | |
download | php-sparkpost-97e0d2643db1969e299349968eea1d9c7a951d7f.zip php-sparkpost-97e0d2643db1969e299349968eea1d9c7a951d7f.tar.gz php-sparkpost-97e0d2643db1969e299349968eea1d9c7a951d7f.tar.bz2 |
Updated tests for new structure
Diffstat (limited to 'test/unit/SparkPostTest.php')
-rw-r--r-- | test/unit/SparkPostTest.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/test/unit/SparkPostTest.php b/test/unit/SparkPostTest.php index 9808c38..aeda7d7 100644 --- a/test/unit/SparkPostTest.php +++ b/test/unit/SparkPostTest.php @@ -3,15 +3,81 @@ namespace SparkPost\Test; use SparkPost\SparkPost; use Ivory\HttpAdapter\CurlHttpAdapter; +use SparkPost\Test\TestUtils\ClassUtils; +use \Mockery; class SparkPostTest extends \PHPUnit_Framework_TestCase { + private static $utils; + private $adapterMock; + private $resource; + + /** + * (non-PHPdoc) + * @before + * @see PHPUnit_Framework_TestCase::setUp() + */ + public function setUp() { + //setup mock for the adapter + $this->adapterMock = Mockery::mock('Ivory\HttpAdapter\HttpAdapterInterface', function($mock) { + $mock->shouldReceive('setConfiguration'); + $mock->shouldReceive('getConfiguration->getUserAgent')->andReturn('php-sparkpost/0.2.0'); + }); + + $this->resource = new SparkPost($this->adapterMock, ['key'=>'a key']); + self::$utils = new ClassUtils($this->resource); + self::$utils->setProperty($this->resource, 'httpAdapter', $this->adapterMock); + } + + public function tearDown() + { + Mockery::close(); + } + /** * @desc Ensures that the configuration class is not instantiable. */ public function testConstructorSetsUpTransmissions() { $sparky = new SparkPost(new CurlHttpAdapter(), ['key'=>'a key']); $this->assertEquals('SparkPost\Transmission', get_class($sparky->transmission)); + $adapter = self::$utils->getProperty($this->resource, 'httpAdapter'); + $this->assertRegExp('/php-sparkpost.*/', $adapter->getConfiguration()->getUserAgent()); } + + /** + * @expectedException Exception + * @expectedExceptionMessageRegExp /valid Ivory\\HttpAdapter/ + */ + public function testSetBadHTTPAdapter() { + $this->resource->setHttpAdapter(new \stdClass()); + } + + /** + * @expectedException Exception + * @expectedExceptionMessageRegExp /API key/ + */ + public function testSetBadConfig() { + $this->resource->setConfig(['not'=>'a key']); + } + + + public function testGetHeaders() { + $results = $this->resource->getHttpHeaders(); + $this->assertEquals('a key', $results['Authorization']); + $this->assertEquals('application/json', $results['Content-Type']); + } + + public function testGetHeadersOverride() { + $results = $this->resource->getHttpHeaders(['Content-Type'=>'application/xml']); + $this->assertEquals('application/xml', $results['Content-Type']); + } + + public function testSetUnwrapped() { + $results = $this->resource->setupUnwrapped('ASweetEndpoint'); + $this->assertEquals($this->resource->ASweetEndpoint, $results); + $this->assertInstanceOf('SparkPost\APIResource', $results); + $this->assertEquals('ASweetEndpoint', $results->endpoint); + } + } ?> |