/** * Set up test suite */ public static function setUpBeforeClass() { $base_dir = dirname(dirname(dirname(dirname(dirname(__FILE__))))); // Create log dir define('HAMPAY_LOG_DIR', $base_dir . DIRECTORY_SEPARATOR . 'log'); if (!is_dir(HAMPAY_LOG_DIR)) { if (!mkdir(HAMPAY_LOG_DIR, 0755)) { throw new \Exception(sprintf('Log directory %s doesn\'t exist.', HAMPAY_LOG_DIR)); } } // Set credentials $cred = $base_dir . DIRECTORY_SEPARATOR . 'credential.json'; $cred = json_decode(file_get_contents($cred), true); $gmo = $cred['gmo']; $gmo['sandbox'] = true; Credential::set($gmo); }
/** * Convert specified key * * @param array|string $params * @param array $keys * @return array|false * @throws \Exception */ public static function getSpecifiedParams(array $params = [], $keys = []) { $keys = (array) $keys; if ($lacks = Validator::lack($params, $keys)) { $message = i18n::sp('Required keys[%s] don\'t exist.', implode(', ', $lacks)); throw new \Exception($message); } $param = []; foreach ($keys as $key => $required) { switch ($key) { case 'SiteID': case 'SitePass': case 'ShopID': case 'ShopPass': $prop = strtolower(preg_replace_callback('#(?<!^)(?<![A-Z])([A-Z])#', function ($match) { return '_' . $match[1]; }, $key)); $param[$key] = Credential::get()->{$prop}; break; default: if (isset($params[$key])) { $param[$key] = $params[$key]; } break; } } return $param; }