-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AliasInsertRequestTest, AliasInsertAssertRequestTest added
- Loading branch information
1 parent
5095573
commit 07c3517
Showing
2 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
tests/SaferpayJson/Tests/SecureAliasStore/AliasInsertAssertRequestTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
namespace Ticketpark\SaferpayJson\Tests\SecureAliasStore; | ||
|
||
use Doctrine\Common\Annotations\AnnotationRegistry; | ||
use JMS\Serializer\SerializerBuilder; | ||
use Ticketpark\SaferpayJson\SecureAliasStore\AliasInsertAssertRequest; | ||
|
||
/** | ||
* Created by PhpStorm. | ||
* User: thomasm | ||
* Date: 25.07.2016 | ||
* Time: 11:13 | ||
*/ | ||
class AliasInsertAssertRequestTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testErrorResponse() | ||
{ | ||
$initializer = new AliasInsertAssertRequest(); | ||
$initializer->setBrowser($this->getBrowserMock(false)); | ||
$response = $initializer->execute(); | ||
|
||
$this->assertInstanceOf('Ticketpark\SaferpayJson\Message\ErrorResponse', $response); | ||
} | ||
|
||
public function testSuccessfulResponse() | ||
{ | ||
$initializer = new AliasInsertAssertRequest(); | ||
$initializer->setBrowser($this->getBrowserMock(true)); | ||
$response = $initializer->execute(); | ||
|
||
$this->assertInstanceOf('Ticketpark\SaferpayJson\SecureAliasStore\AliasInsertAssertResponse', $response); | ||
} | ||
|
||
public function getBrowserMock($successful) | ||
{ | ||
$browser = $this->getMockBuilder('Buzz\Browser') | ||
->disableOriginalConstructor() | ||
->setMethods(array('post')) | ||
->getMock(); | ||
|
||
$browser->expects($this->once()) | ||
->method('post') | ||
->will($this->returnValue($this->getResponseMock($successful))); | ||
|
||
return $browser; | ||
} | ||
|
||
public function getResponseMock($successful) | ||
{ | ||
$response = $this->getMockBuilder('Buzz\Message\Response') | ||
->disableOriginalConstructor() | ||
->setMethods(array('getStatusCode', 'isClientError', 'getContent')) | ||
->getMock(); | ||
|
||
$response->expects($this->any()) | ||
->method('isClientError') | ||
->will($this->returnValue(!$successful)); | ||
|
||
$response->expects($this->any()) | ||
->method('getStatusCode') | ||
->will($this->returnValue(200)); | ||
|
||
if ($successful) { | ||
$content = $this->getFakedApiResponse('Ticketpark\SaferpayJson\SecureAliasStore\AliasInsertAssertResponse'); | ||
} else { | ||
$content = $this->getFakedApiResponse('Ticketpark\SaferpayJson\Message\ErrorResponse'); | ||
} | ||
|
||
$response->expects($this->any()) | ||
->method('getContent') | ||
->will($this->returnValue($content)); | ||
|
||
return $response; | ||
} | ||
|
||
public function getFakedApiResponse($class) | ||
{ | ||
AnnotationRegistry::registerLoader('class_exists'); | ||
$serializer = SerializerBuilder::create()->build(); | ||
|
||
$response = new $class(); | ||
|
||
return $serializer->serialize($response, 'json'); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
tests/SaferpayJson/Tests/SecureAliasStore/AliasInsertRequestTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
namespace Ticketpark\SaferpayJson\Tests\SecureAliasStore; | ||
|
||
use Doctrine\Common\Annotations\AnnotationRegistry; | ||
use JMS\Serializer\SerializerBuilder; | ||
use Ticketpark\SaferpayJson\SecureAliasStore\AliasInsertRequest; | ||
|
||
/** | ||
* Created by PhpStorm. | ||
* User: thomasm | ||
* Date: 25.07.2016 | ||
* Time: 11:14 | ||
*/ | ||
class AliasInsertRequestTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testErrorResponse() | ||
{ | ||
$initializer = new AliasInsertRequest(); | ||
$initializer->setBrowser($this->getBrowserMock(false)); | ||
$response = $initializer->execute(); | ||
|
||
$this->assertInstanceOf('Ticketpark\SaferpayJson\Message\ErrorResponse', $response); | ||
} | ||
|
||
public function testSuccessfulResponse() | ||
{ | ||
$initializer = new AliasInsertRequest(); | ||
$initializer->setBrowser($this->getBrowserMock(true)); | ||
$response = $initializer->execute(); | ||
|
||
$this->assertInstanceOf('Ticketpark\SaferpayJson\SecureAliasStore\AliasInsertResponse', $response); | ||
} | ||
|
||
public function getBrowserMock($successful) | ||
{ | ||
$browser = $this->getMockBuilder('Buzz\Browser') | ||
->disableOriginalConstructor() | ||
->setMethods(array('post')) | ||
->getMock(); | ||
|
||
$browser->expects($this->once()) | ||
->method('post') | ||
->will($this->returnValue($this->getResponseMock($successful))); | ||
|
||
return $browser; | ||
} | ||
|
||
public function getResponseMock($successful) | ||
{ | ||
$response = $this->getMockBuilder('Buzz\Message\Response') | ||
->disableOriginalConstructor() | ||
->setMethods(array('getStatusCode', 'isClientError', 'getContent')) | ||
->getMock(); | ||
|
||
$response->expects($this->any()) | ||
->method('isClientError') | ||
->will($this->returnValue(!$successful)); | ||
|
||
$response->expects($this->any()) | ||
->method('getStatusCode') | ||
->will($this->returnValue(200)); | ||
|
||
if ($successful) { | ||
$content = $this->getFakedApiResponse('Ticketpark\SaferpayJson\SecureAliasStore\AliasInsertResponse'); | ||
} else { | ||
$content = $this->getFakedApiResponse('Ticketpark\SaferpayJson\Message\ErrorResponse'); | ||
} | ||
|
||
$response->expects($this->any()) | ||
->method('getContent') | ||
->will($this->returnValue($content)); | ||
|
||
return $response; | ||
} | ||
|
||
public function getFakedApiResponse($class) | ||
{ | ||
AnnotationRegistry::registerLoader('class_exists'); | ||
$serializer = SerializerBuilder::create()->build(); | ||
|
||
$response = new $class(); | ||
|
||
return $serializer->serialize($response, 'json'); | ||
} | ||
} |