From a1288f7b818ab62422e2a0316de516b1fcf263b2 Mon Sep 17 00:00:00 2001 From: cyattilakiss <42297201+cyattilakiss@users.noreply.github.com> Date: Mon, 22 Oct 2018 13:57:53 +0200 Subject: [PATCH] fix local unit test running caused by the missing date_default_timezone_set (#78) Set date_default_timezone if missing from the defaults --- tests/TestCase.php | 46 ++++++++++++++++++++++++++++++++----------- tests/config/test.ini | 2 +- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 680fd16c8..5d40080bb 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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 @@ -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 @@ -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 @@ -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 @@ -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"); @@ -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"); @@ -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; @@ -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; @@ -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; @@ -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; @@ -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); @@ -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 diff --git a/tests/config/test.ini b/tests/config/test.ini index 2c550e032..b79a75dbe 100644 --- a/tests/config/test.ini +++ b/tests/config/test.ini @@ -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" \ No newline at end of file