Skip to content

Commit

Permalink
Tests nearly done. Test namespace autoload reverted to allow test cla…
Browse files Browse the repository at this point in the history
…sses inheritance.
  • Loading branch information
jan-j committed Sep 19, 2015
1 parent 597c00f commit b717eef
Show file tree
Hide file tree
Showing 18 changed files with 370 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
.idea
composer.lock
vendor
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"Omnipay\\Creditcall\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Omnipay\\Creditcall\\Test\\": "tests"
}
},
"scripts": {
"test": "phpunit"
},
Expand Down
161 changes: 146 additions & 15 deletions tests/GatewayTest.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,170 @@
<?php

namespace Omnipay\Creditcall;
namespace Omnipay\Creditcall\Test;

use Omnipay\Creditcall\Gateway;
use Omnipay\Tests\GatewayTestCase;
use Omnipay\Common\CreditCard;

class GatewayTest extends GatewayTestCase
{

/**
* @var Gateway
*/
protected $gateway;

/**
* @var array
*/
protected $purchaseOptions;

/**
* @var array
*/
protected $captureOptions;

public function setUp()
{
parent::setUp();

$this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest());

$this->options = array(
'amount' => '10.00',
'card' => new CreditCard(array(
'firstName' => 'Example',
'lastName' => 'User',
'number' => '4111111111111111',
'expiryMonth' => '12',
'expiryYear' => '2016',
'cvv' => '123',
)),
$this->gateway->setTerminalId('923632313');
$this->gateway->setTransactionKey('23ASDas3d323ASs6');

$this->purchaseOptions = array(
'amount' => '10.00',
'transactionId' => '123',
'card' => $this->getValidCard(),
);
$this->captureOptions = array(
'amount' => '10.00',
'transactionReference' => '6f3b812a-dafa-e311-983c-00505692354f',
);
}

public function testAuthorize()
public function testGatewaySettersGetters()
{
$this->assertSame('923632313', $this->gateway->getTerminalId());
$this->assertSame('23ASDas3d323ASs6', $this->gateway->getTransactionKey());
$this->gateway->setVerifyCvv(false);
$this->gateway->setVerifyAddress(true);
$this->gateway->setVerifyZip(true);
$this->assertFalse($this->gateway->getVerifyCvv());
$this->assertTrue($this->gateway->getVerifyAddress());
$this->assertTrue($this->gateway->getVerifyZip());
}

public function testAuthorizeSuccess()
{
$this->setMockHttpResponse('AuthorizeSuccess.txt');
$response = $this->gateway->authorize($this->purchaseOptions)->send();

$response = $this->gateway->authorize($this->options)->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getMessage());
$this->assertSame('6f3b812a-dafa-e311-983c-00505692354f', $response->getTransactionReference());
$this->assertSame('a4f483ca-55fc-e311-8ca6-001422187e37', $response->getCardReference());
$this->assertSame('qo3tCvArxWUxsCONcIWGyHUhXKs=', $response->getCardHash());
}

public function testAuthorizeFailure()
{
$this->setMockHttpResponse('AuthorizeFailure.txt');
$response = $this->gateway->authorize($this->purchaseOptions)->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('CvvNotMatched', $response->getMessage());
}

public function testPurchaseSuccess()
{
$this->setMockHttpResponse('AuthorizeSuccess.txt');
$response = $this->gateway->purchase($this->purchaseOptions)->send();

$requestData = $response->getRequest()->getData();
$this->assertSame('true', (string)$requestData->TransactionDetails->MessageType->attributes()->autoconfirm);
$this->assertTrue($response->isSuccessful());
$this->assertEquals('1234', $response->getTransactionReference());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getMessage());
$this->assertSame('6f3b812a-dafa-e311-983c-00505692354f', $response->getTransactionReference());
$this->assertSame('a4f483ca-55fc-e311-8ca6-001422187e37', $response->getCardReference());
$this->assertSame('qo3tCvArxWUxsCONcIWGyHUhXKs=', $response->getCardHash());
}

public function testPurchaseFailure()
{
$this->setMockHttpResponse('AuthorizeFailure.txt');
$response = $this->gateway->purchase($this->purchaseOptions)->send();

$requestData = $response->getRequest()->getData();
$this->assertSame('true', (string)$requestData->TransactionDetails->MessageType->attributes()->autoconfirm);
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('CvvNotMatched', $response->getMessage());
}

public function testCaptureSuccess()
{
$this->setMockHttpResponse('CaptureSuccess.txt');
$response = $this->gateway->capture($this->captureOptions)->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getMessage());
$this->assertNotNull($response->getTransactionReference());
}

public function testCaptureFailure()
{
$this->setMockHttpResponse('CaptureFailure.txt');
$response = $this->gateway->capture($this->captureOptions)->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('CardEaseReferenceInvalid', $response->getMessage());
}

public function testRefundSuccess()
{
$this->setMockHttpResponse('RefundSuccess.txt');
$response = $this->gateway->refund($this->captureOptions)->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getMessage());
$this->assertNotNull($response->getTransactionReference());
}

public function testRefundFailure()
{
$this->setMockHttpResponse('RefundFailure.txt');
$response = $this->gateway->refund($this->captureOptions)->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('TransactionAlreadyVoided', $response->getMessage());
}

public function testVoidSuccess()
{
$this->setMockHttpResponse('VoidSuccess.txt');
$response = $this->gateway->void($this->captureOptions)->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertNull($response->getMessage());
$this->assertNotNull($response->getTransactionReference());
}

public function testVoidFailure()
{
$this->setMockHttpResponse('VoidFailure.txt');
$response = $this->gateway->void($this->captureOptions)->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('TransactionAlreadyVoided', $response->getMessage());
}
}
43 changes: 43 additions & 0 deletions tests/Message/AuthorizeCardReferenceRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Omnipay\Creditcall\Test\Message;

use Omnipay\Creditcall\Message\AuthorizeRequest;

class AuthorizeCardReferenceRequestTest extends AuthorizeRequestTest
{
public function setUp()
{
parent::setUp();

$this->request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(array_merge($this->getOptions(), array(
'card' => null,
'cardReference' => 'a4f483ca-55fc-e311-8ca6-001422187e37',
'cardHash' => 'qo3tCvArxWUxsCONcIWGyHUhXKs=',
)));
}

public function testTransactionData()
{
$data = $this->request->getData();

$this->assertSame('123', (string)$data->TransactionDetails->Reference);
$this->assertSame('12.00', (string)$data->TransactionDetails->Amount);
$this->assertSame('major', (string)$data->TransactionDetails->Amount->attributes()->unit);
$this->assertSame('826', (string)$data->TransactionDetails->CurrencyCode);

$this->assertNull($this->request->getCard());

$manual = $data->CardDetails->Manual;
$this->assertSame('cnp', (string)$manual->attributes()->type);
$this->assertSame('a4f483ca-55fc-e311-8ca6-001422187e37', (string)$manual->CardReference);
$this->assertSame('qo3tCvArxWUxsCONcIWGyHUhXKs=', (string)$manual->CardHash);
$this->assertSame('826', (string)$data->TransactionDetails->CurrencyCode);
}

public function testGetDataCustomerDetails()
{
//
}
}
36 changes: 21 additions & 15 deletions tests/Message/AuthorizeRequestTest.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
<?php

namespace Omnipay\Creditcall\Message;
namespace Omnipay\Creditcall\Test\Message;

use Omnipay\Common\CreditCard;
use Omnipay\Creditcall\Message\AuthorizeRequest;
use Omnipay\Tests\TestCase;

class AuthorizeRequestTest extends TestCase
{
/**
* @var AuthorizeRequest
*/
public $request;
protected $request;

/**
* @return array
*/
protected function getOptions()
{
return array(
'terminalId' => '923632313',
'transactionKey' => '23ASDas3d323ASs6',
'testMode' => true,
'amount' => '12.00',
'currency' => 'GBP',
'transactionId' => '123',
'card' => $this->getValidCard(),
'verifyCvv' => true,
);
}

public function setUp()
{
parent::setUp();

$this->request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'terminalId' => '923632313',
'transactionKey' => '23ASDas3d323ASs6',
'testMode' => true,
'amount' => '12.00',
'currency' => 'GBP',
'transactionId' => '123',
'card' => $this->getValidCard(),
'verifyCvv' => true,
)
);
$this->request->initialize($this->getOptions());
}

public function testBaseData()
{
$data = $this->request->getData();

$this->assertSame('Auth', (string)$data->TransactionDetails->MessageType);

$this->assertSame('923632313', (string)$data->TerminalDetails->TerminalID);
$this->assertSame('23ASDas3d323ASs6', (string)$data->TerminalDetails->TransactionKey);
}
Expand Down
31 changes: 31 additions & 0 deletions tests/Message/CaptureRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Omnipay\Creditcall\Test\Message;

use Omnipay\Creditcall\Message\CaptureRequest;
use Omnipay\Tests\TestCase;

class CaptureRequestTest extends TestCase
{
/**
* @var CaptureRequest
*/
protected $request;

public function setUp()
{
parent::setUp();

$this->request = new CaptureRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(array(
'transactionReference' => '6f3b812a-dafa-e311-983c-00505692354f',
));
}

public function testGetData()
{
$data = $this->request->getData();

$this->assertSame('6f3b812a-dafa-e311-983c-00505692354f', (string)$data->TransactionDetails->CardEaseReference);
}
}
28 changes: 28 additions & 0 deletions tests/Message/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Omnipay\Creditcall\Test\Message;

use Omnipay\Creditcall\Message\PurchaseRequest;

class PurchaseRequestTest extends AuthorizeRequestTest
{
/**
* @var PurchaseRequest
*/
protected $request;

public function setUp()
{
parent::setUp();

$this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize($this->getOptions());
}

public function testAutoconfirmProperty()
{
$data = $this->request->getData();

$this->assertSame('true', (string)$data->TransactionDetails->MessageType->attributes()->autoconfirm);
}
}
Loading

0 comments on commit b717eef

Please sign in to comment.