Skip to content

Commit

Permalink
fix local unit test running caused by the missing date_default_timezo…
Browse files Browse the repository at this point in the history
…ne_set (#78)

Set date_default_timezone if missing from the defaults
  • Loading branch information
cyattilakiss authored Oct 22, 2018
1 parent fbae79c commit a1288f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
46 changes: 35 additions & 11 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,34 @@ class TestCase extends \PHPUnit_Framework_TestCase
protected $_skinCode;
protected $_hmacSignature;

/**
* Settings parsed from the config/test.ini file
*
* @var array
*/
protected $settings;

public function __construct()
{

$this->_merchantAccount = $this->getMerchantAccount();
$this->_skinCode = $this->getSkinCode();
$this->_hmacSignature = $this->getHmacSignature();
$this->settings = $this->_loadConfigIni();

$this->setDefaultsDuringDevelopment();
}

/**
* During development of the standalone php api library this function sets the necessary defaults which would
* otherwise set by the merchant
*/
private function setDefaultsDuringDevelopment()
{
// Check default timezone if not set use a default value for that
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'Europe/Amsterdam');
}
}

/**
* Mock client
Expand All @@ -27,7 +46,7 @@ public function __construct()
protected function createClient()
{
// load settings from .ini file
$settings = $this->_loadConfigIni();
$settings = $this->settings;

// validate username, password and MERCHANTAccount

Expand Down Expand Up @@ -82,7 +101,7 @@ protected function createClientWithoutTestIni()
protected function createPayoutClient()
{
// load settings from .ini file
$settings = $this->_loadConfigIni();
$settings = $this->settings;

// validate username, password and MERCHANTAccount

Expand Down Expand Up @@ -119,7 +138,7 @@ protected function createPayoutClient()
protected function createReviewPayoutClient()
{
// load settings from .ini file
$settings = $this->_loadConfigIni();
$settings = $this->settings;

// validate username, password and MERCHANTAccount

Expand Down Expand Up @@ -151,7 +170,7 @@ protected function createReviewPayoutClient()
protected function createTerminalCloudAPIClient()
{
// load settings from .ini file
$settings = $this->_loadConfigIni();
$settings = $this->settings;

if(!isset($settings['x-api-key']) || !isset($settings['POIID']) || $settings['x-api-key'] == 'YOUR X-API KEY' || $settings['POIID'] == 'UNIQUETERMINALID'){
$this->_skipTest("Skipped the test. Configure your x-api-key and POIID in the config");
Expand All @@ -171,7 +190,7 @@ protected function createClientWithMerchantAccount()
$client = $this->createClient();

// load settings from .ini file
$settings = $this->_loadConfigIni();
$settings = $this->settings;

if(!isset($settings['merchantAccount']) || $settings['merchantAccount'] == 'YOUR MERCHANTACCOUNT') {
$this->_skipTest("Skipped the test. Configure your MerchantAccount in the config");
Expand All @@ -184,7 +203,7 @@ protected function createClientWithMerchantAccount()

protected function getMerchantAccount()
{
$settings = $this->_loadConfigIni();
$settings = $this->settings;

if(!isset($settings['merchantAccount']) || $settings['merchantAccount'] == 'YOUR MERCHANTACCOUNT') {
return null;
Expand All @@ -195,7 +214,7 @@ protected function getMerchantAccount()

protected function getSkinCode()
{
$settings = $this->_loadConfigIni();
$settings = $this->settings;

if(!isset($settings['skinCode']) || $settings['skinCode'] == 'YOUR SKIN CODE') {
return null;
Expand All @@ -206,7 +225,7 @@ protected function getSkinCode()

protected function getHmacSignature()
{
$settings = $this->_loadConfigIni();
$settings = $this->settings;

if(!isset($settings['hmacSignature'])|| $settings['hmacSignature'] == 'YOUR HMAC SIGNATURE') {
return null;
Expand All @@ -217,7 +236,7 @@ protected function getHmacSignature()

protected function getPOIID()
{
$settings = $this->_loadConfigIni();
$settings = $this->settings;

if(!isset($settings['POIID']) || $settings['POIID'] == 'MODEL-SERIALNUMBER') {
return null;
Expand All @@ -226,6 +245,11 @@ protected function getPOIID()
return $settings['POIID'];
}

/**
* Loads the settings into and array from the config/test.ini file
*
* @return array|bool
*/
protected function _loadConfigIni()
{
return parse_ini_file(__DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'test.ini', true);
Expand All @@ -242,7 +266,7 @@ protected function _needSkinCode() {
$this->_skipTest("Skipped the test. Configure your SkinCode in the config");
}
}

public function validateApiPermission($e)
{
// it is possible you do not have permission to use full API then switch over to CSE
Expand Down
2 changes: 1 addition & 1 deletion tests/config/test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ POIID = UNIQUETERMINALID
storePayoutUsername = YOUR STORE PAYOUT USERNAME
storePayoutPassword = "YOUR STORE PAYOUT PASSWORD"
reviewPayoutUsername = YOUR REVIEW PAYOUT USERNAME
reviewPayoutPassword = "YOUR REVIEW PAYOUT PASSWORD"
reviewPayoutPassword = "YOUR REVIEW PAYOUT PASSWORD"

0 comments on commit a1288f7

Please sign in to comment.