@@ -24,60 +24,44 @@ private function getExceptionMock($statusCode) {
2424 * @see PHPUnit_Framework_TestCase::setUp()
2525 */
2626 public function setUp () {
27- $ this ->adapterMock = Mockery::mock ('Ivory\HttpAdapter\HttpAdapterInterface ' , function ($ mock ) {
28- $ mock ->shouldReceive ('setConfiguration ' );
29- $ mock ->shouldReceive ('getConfiguration->getUserAgent ' )->andReturn ('php-sparkpost/0.2.0 ' );
27+ $ this ->sparkPostMock = Mockery::mock ('SparkPost\SparkPost ' , function ($ mock ) {
28+ $ mock ->shouldReceive ('getHttpHeaders ' )->andReturn ([]);
3029 });
31- $ this ->resource = new APIResource ($ this ->adapterMock , ['key ' =>'a key ' ]);
30+ $ this ->sparkPostMock ->httpAdapter = Mockery::mock ();
31+ $ this ->resource = new APIResource ($ this ->sparkPostMock );
3232 self ::$ utils = new ClassUtils ($ this ->resource );
33-
34- self ::$ utils ->setProperty ($ this ->resource , 'httpAdapter ' , $ this ->adapterMock );
33+ self ::$ utils ->setProperty ($ this ->resource , 'sparkpost ' , $ this ->sparkPostMock );
3534 }
3635
3736 public function tearDown ()
3837 {
3938 Mockery::close ();
4039 }
4140
42- public function testConstructorSetsUpAdapterAndConfig () {
43- $ adapter = self ::$ utils ->getProperty ($ this ->resource , 'httpAdapter ' );
44- $ this ->assertRegExp ('/php-sparkpost.*/ ' , $ adapter ->getConfiguration ()->getUserAgent ());
45- }
46-
47- /**
48- * @expectedException Exception
49- * @expectedExceptionMessageRegExp /valid Ivory\\HttpAdapter/
50- */
51- public function testSetBadHTTPAdapter () {
52- $ this ->resource ->setHttpAdapter (new \stdClass ());
53- }
54-
55- /**
56- * @expectedException Exception
57- * @expectedExceptionMessageRegExp /API key/
58- */
59- public function testSetBadConfig () {
60- $ this ->resource ->setConfig (['not ' =>'a key ' ]);
41+ public function testConstructorSetsUpSparkPostObject () {
42+ $ this ->sparkPostMock ->newProp = 'new value ' ;
43+ $ this ->assertEquals ($ this ->sparkPostMock , self ::$ utils ->getProperty ($ this ->resource , 'sparkpost ' ));
6144 }
6245
6346 public function testCreate () {
6447 $ testInput = ['test ' =>'body ' ];
6548 $ testBody = ["results " =>["my " =>"test " ]];
6649 $ responseMock = Mockery::mock ();
67- $ this ->adapterMock ->shouldReceive ('send ' )->
50+ $ this ->sparkPostMock -> httpAdapter ->shouldReceive ('send ' )->
6851 once ()->
6952 with (Mockery::type ('string ' ), 'POST ' , Mockery::type ('array ' ), json_encode ($ testInput ))->
7053 andReturn ($ responseMock );
7154 $ responseMock ->shouldReceive ('getBody->getContents ' )->andReturn (json_encode ($ testBody ));
7255
56+
7357 $ this ->assertEquals ($ testBody , $ this ->resource ->create ($ testInput ));
7458 }
7559
7660 public function testUpdate () {
7761 $ testInput = ['test ' =>'body ' ];
7862 $ testBody = ["results " =>["my " =>"test " ]];
7963 $ responseMock = Mockery::mock ();
80- $ this ->adapterMock ->shouldReceive ('send ' )->
64+ $ this ->sparkPostMock -> httpAdapter ->shouldReceive ('send ' )->
8165 once ()->
8266 with ('/.*\/test/ ' , 'PUT ' , Mockery::type ('array ' ), json_encode ($ testInput ))->
8367 andReturn ($ responseMock );
@@ -89,7 +73,7 @@ public function testUpdate() {
8973 public function testGet () {
9074 $ testBody = ["results " =>["my " =>"test " ]];
9175 $ responseMock = Mockery::mock ();
92- $ this ->adapterMock ->shouldReceive ('send ' )->
76+ $ this ->sparkPostMock -> httpAdapter ->shouldReceive ('send ' )->
9377 once ()->
9478 with ('/.*\/test/ ' , 'GET ' , Mockery::type ('array ' ), null )->
9579 andReturn ($ responseMock );
@@ -100,7 +84,7 @@ public function testGet() {
10084
10185 public function testDelete () {
10286 $ responseMock = Mockery::mock ();
103- $ this ->adapterMock ->shouldReceive ('send ' )->
87+ $ this ->sparkPostMock -> httpAdapter ->shouldReceive ('send ' )->
10488 once ()->
10589 with ('/.*\/test/ ' , 'DELETE ' , Mockery::type ('array ' ), null )->
10690 andReturn ($ responseMock );
@@ -111,7 +95,7 @@ public function testDelete() {
11195
11296 public function testAdapter404Exception () {
11397 try {
114- $ this ->adapterMock ->shouldReceive ('send ' )->
98+ $ this ->sparkPostMock -> httpAdapter ->shouldReceive ('send ' )->
11599 once ()->
116100 andThrow ($ this ->getExceptionMock (404 ));
117101
@@ -124,7 +108,7 @@ public function testAdapter404Exception() {
124108
125109 public function testAdapter4XXException () {
126110 try {
127- $ this ->adapterMock ->shouldReceive ('send ' )->
111+ $ this ->sparkPostMock -> httpAdapter ->shouldReceive ('send ' )->
128112 once ()->
129113 andThrow ($ this ->getExceptionMock (400 ));
130114
@@ -137,7 +121,7 @@ public function testAdapter4XXException() {
137121
138122 public function testAdapter5XXException () {
139123 try {
140- $ this ->adapterMock ->shouldReceive ('send ' )->
124+ $ this ->sparkPostMock -> httpAdapter ->shouldReceive ('send ' )->
141125 once ()->
142126 andThrow (new \Exception ('Something went wrong. ' ));
143127
0 commit comments