From 26a83d97c2fb49ec89a3867045032cef18c7f320 Mon Sep 17 00:00:00 2001 From: Derek Caswell Date: Mon, 13 Mar 2017 13:47:41 -0600 Subject: [PATCH] Added a new test so we can get 100% test coverage --- tests/Message/AbstractRequestTest.php | 15 +++++++++++++++ tests/Message/AuthorizeTest.php | 21 +++++++++++++++++---- tests/Message/PurchaseTest.php | 5 +---- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/tests/Message/AbstractRequestTest.php b/tests/Message/AbstractRequestTest.php index a7db973..ab2bfeb 100644 --- a/tests/Message/AbstractRequestTest.php +++ b/tests/Message/AbstractRequestTest.php @@ -45,6 +45,21 @@ public function setUp() } } + /** + * Get a valid card with the specific data needed to test on Plug 'N Pay + * + * @return array + */ + protected function getTestableCard() + { + $card = $this->getValidCard(); + $card['expiryMonth'] = '01'; + $card['expiryYear'] = '19'; + $card['cvv'] = '810'; + + return $card; + } + /** * Test the endpoint */ diff --git a/tests/Message/AuthorizeTest.php b/tests/Message/AuthorizeTest.php index 5008bfd..24dfe3b 100644 --- a/tests/Message/AuthorizeTest.php +++ b/tests/Message/AuthorizeTest.php @@ -3,6 +3,7 @@ namespace tests\Message; +use Omnipay\Common\CreditCard; use Omnipay\PlugNPay\Message\AuthorizeRequest; use Omnipay\PlugNPay\Message\AuthorizeResponse; @@ -24,10 +25,7 @@ public function setUp() { parent::setUp(); $this->request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); - $card = $this->getValidCard(); - $card['expiryMonth'] = '01'; - $card['expiryYear'] = '19'; - $card['cvv'] = '810'; + $card = $this->getTestableCard(); $this->request->initialize([ 'username'=>$this->username, 'password'=>$this->password, @@ -70,6 +68,21 @@ public function testGetData() $this->assertSame($expectedData, $this->request->getData()); } + /** + * @expectedException \Exception + * @expectedExceptionMessage Name missing from credit card. + */ + public function testEmptyName() + { + $card = $this->getTestableCard(); + $card['firstName'] = ''; + $card['lastName'] = ''; + + $this->request->setCard(new CreditCard($card)); + + $this->request->getData(); + } + /** * Test a successful Authorize */ diff --git a/tests/Message/PurchaseTest.php b/tests/Message/PurchaseTest.php index 13eacc7..5f49ac6 100644 --- a/tests/Message/PurchaseTest.php +++ b/tests/Message/PurchaseTest.php @@ -23,10 +23,7 @@ public function setUp() { parent::setUp(); $this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); - $card = $this->getValidCard(); - $card['expiryMonth'] = '01'; - $card['expiryYear'] = '19'; - $card['cvv'] = '810'; + $card = $this->getTestableCard(); $this->request->initialize([ 'username'=>$this->username, 'password'=>$this->password,