From 3aa2f8146e0a2dbc389f7f3efaaa21b033782fe4 Mon Sep 17 00:00:00 2001 From: Andy Perdomo Date: Thu, 24 Mar 2016 09:14:17 -0700 Subject: [PATCH] Increasing test coverage. --- src/Message/AbstractProfileRequest.php | 8 ++++---- src/Message/DeleteProfileCardRequest.php | 7 +++++++ src/Message/DeleteProfileRequest.php | 3 ++- src/Message/FetchProfileRequest.php | 3 ++- tests/GatewayTest.php | 18 +++++++++--------- tests/Message/CreateProfileCardRequestTest.php | 6 ++++++ tests/Message/DeleteProfileRequestTest.php | 8 ++++++++ tests/Message/FetchProfileRequestTest.php | 8 ++++++++ 8 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/Message/AbstractProfileRequest.php b/src/Message/AbstractProfileRequest.php index 72a3192..deee90b 100644 --- a/src/Message/AbstractProfileRequest.php +++ b/src/Message/AbstractProfileRequest.php @@ -6,22 +6,22 @@ abstract class AbstractProfileRequest extends AbstractRequest public function getProfileId() { - return $this->getParameter('profileId'); + return $this->getParameter('profile_id'); } public function setProfileId($value) { - return $this->setParameter('profileId', $value); + return $this->setParameter('profile_id', $value); } public function getCardId() { - return $this->getParameter('cardId'); + return $this->getParameter('card_id'); } public function setCardId($value) { - return $this->setParameter('cardId', $value); + return $this->setParameter('card_id', $value); } public function getComment() diff --git a/src/Message/DeleteProfileCardRequest.php b/src/Message/DeleteProfileCardRequest.php index 5433ac4..0038d57 100644 --- a/src/Message/DeleteProfileCardRequest.php +++ b/src/Message/DeleteProfileCardRequest.php @@ -2,6 +2,13 @@ class DeleteProfileCardRequest extends DeleteProfileRequest { + public function getData() + { + $this->validate('profile_id'); + $this->validate('card_id'); + return; + } + public function getEndpoint() { return $this->endpoint . '/' . $this->getProfileId() . '/cards/' . $this->getCardId(); diff --git a/src/Message/DeleteProfileRequest.php b/src/Message/DeleteProfileRequest.php index 39024cf..0a30a57 100644 --- a/src/Message/DeleteProfileRequest.php +++ b/src/Message/DeleteProfileRequest.php @@ -4,7 +4,8 @@ class DeleteProfileRequest extends AbstractProfileRequest { public function getData() { - return array(); + $this->validate('profile_id'); + return; } public function getEndpoint() diff --git a/src/Message/FetchProfileRequest.php b/src/Message/FetchProfileRequest.php index 96fb33a..8328459 100644 --- a/src/Message/FetchProfileRequest.php +++ b/src/Message/FetchProfileRequest.php @@ -4,7 +4,8 @@ class FetchProfileRequest extends AbstractProfileRequest { public function getData() { - return array(); + $this->validate('profile_id'); + return; } public function getEndpoint() diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 648967f..d15aec3 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -94,7 +94,7 @@ public function testFetchProfile() { $request = $this->gateway->fetchProfile( array( - 'profileId' => 1 + 'profile_id' => 1 ) ); $this->assertInstanceOf('Omnipay\Beanstream\Message\FetchProfileRequest', $request); @@ -106,7 +106,7 @@ public function testUpdateProfile() { $request = $this->gateway->updateProfile( array( - 'profileId' => 1, + 'profile_id' => 1, 'language' => 'test-language', 'comment' => 'test-comment' ) @@ -122,7 +122,7 @@ public function testDeleteProfile() { $request = $this->gateway->deleteProfile( array( - 'profileId' => 1, + 'profile_id' => 1, ) ); $this->assertInstanceOf('Omnipay\Beanstream\Message\DeleteProfileRequest', $request); @@ -134,7 +134,7 @@ public function testCreateProfileCard() { $request = $this->gateway->createProfileCard( array( - 'profileId' => 1 + 'profile_id' => 1 ) ); $this->assertInstanceOf('Omnipay\Beanstream\Message\CreateProfileCardRequest', $request); @@ -146,7 +146,7 @@ public function testFetchProfileCards() { $request = $this->gateway->fetchProfileCards( array( - 'profileId' => 1 + 'profile_id' => 1 ) ); $this->assertInstanceOf('Omnipay\Beanstream\Message\FetchProfileCardsRequest', $request); @@ -158,8 +158,8 @@ public function testUpdateProfileCard() { $request = $this->gateway->updateProfileCard( array( - 'profileId' => 1, - 'cardId' => 2 + 'profile_id' => 1, + 'card_id' => 2 ) ); $this->assertInstanceOf('Omnipay\Beanstream\Message\UpdateProfileCardRequest', $request); @@ -172,8 +172,8 @@ public function testDeleteProfileCard() { $request = $this->gateway->deleteProfileCard( array( - 'profileId' => 1, - 'cardId' => 2 + 'profile_id' => 1, + 'card_id' => 2 ) ); $this->assertInstanceOf('Omnipay\Beanstream\Message\DeleteProfileCardRequest', $request); diff --git a/tests/Message/CreateProfileCardRequestTest.php b/tests/Message/CreateProfileCardRequestTest.php index f40dddc..af1c64b 100644 --- a/tests/Message/CreateProfileCardRequestTest.php +++ b/tests/Message/CreateProfileCardRequestTest.php @@ -23,6 +23,12 @@ public function testCard() { $card = $this->getValidCard(); $this->assertSame($this->request, $this->request->setCard($card)); + $data = $this->request->getData(); + $this->assertSame($card['number'], $data['number']); + $this->assertSame($card['cvv'], $data['cvd']); + $this->assertSame(sprintf("%02d", $card['expiryMonth']), $data['expiry_month']); + $this->assertSame(substr($card['expiryYear'], -2), $data['expiry_year']); + $this->assertSame($card['firstName'] . ' ' . $card['lastName'], $data['name']); } public function testHttpMethod() diff --git a/tests/Message/DeleteProfileRequestTest.php b/tests/Message/DeleteProfileRequestTest.php index 1ce1b56..127a60e 100644 --- a/tests/Message/DeleteProfileRequestTest.php +++ b/tests/Message/DeleteProfileRequestTest.php @@ -23,4 +23,12 @@ public function testHttpMethod() { $this->assertSame('DELETE', $this->request->getHttpMethod()); } + + public function testGetData() + { + $this->assertSame($this->request, $this->request->setProfileId('1')); + $this->assertSame('1', $this->request->getProfileId()); + $this->assertNull($this->request->getData()); + $this->assertSame('DELETE', $this->request->getHttpMethod()); + } } diff --git a/tests/Message/FetchProfileRequestTest.php b/tests/Message/FetchProfileRequestTest.php index 3057282..d2f5f6a 100644 --- a/tests/Message/FetchProfileRequestTest.php +++ b/tests/Message/FetchProfileRequestTest.php @@ -23,4 +23,12 @@ public function testHttpMethod() { $this->assertSame('GET', $this->request->getHttpMethod()); } + + public function testGetData() + { + $this->assertSame($this->request, $this->request->setProfileId('1')); + $this->assertSame('1', $this->request->getProfileId()); + $this->assertNull($this->request->getData()); + $this->assertSame('GET', $this->request->getHttpMethod()); + } }