From aab6bd6d484c30aa1a82fa1e2febf351bfb77f67 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 6 Nov 2016 20:54:46 +0900 Subject: [PATCH] Minor changes to support unit testing via dummy --- common/framework/drivers/sms/dummy.php | 29 ++++++++++++++++++++++++++ common/framework/sms.php | 12 ++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/common/framework/drivers/sms/dummy.php b/common/framework/drivers/sms/dummy.php index d777bf892..43f97b299 100644 --- a/common/framework/drivers/sms/dummy.php +++ b/common/framework/drivers/sms/dummy.php @@ -32,6 +32,11 @@ class Dummy extends Base implements \Rhymix\Framework\Drivers\SMSInterface 'delay_supported' => true, ); + /** + * Sent messages are stored here for debugging and testing. + */ + protected $_sent_messages = array(); + /** * Send a message. * @@ -43,6 +48,30 @@ class Dummy extends Base implements \Rhymix\Framework\Drivers\SMSInterface */ public function send(array $messages, \Rhymix\Framework\SMS $original) { + foreach ($messages as $message) + { + $this->_sent_messages[] = $message; + } return true; } + + /** + * Get sent messages. + * + * @return array + */ + public function getSentMessages() + { + return $this->_sent_messages; + } + + /** + * Reset sent messages. + * + * @return void + */ + public function resetSentMessages() + { + $this->_sent_messages = array(); + } } diff --git a/common/framework/sms.php b/common/framework/sms.php index 76ae3fc4c..2b704e932 100644 --- a/common/framework/sms.php +++ b/common/framework/sms.php @@ -12,7 +12,7 @@ class SMS */ public $driver = null; protected $caller = ''; - protected $from = ''; + protected $from = null; protected $to = array(); protected $subject = ''; protected $content = ''; @@ -91,6 +91,7 @@ class SMS 'name' => $class_name::getName(), 'required' => $class_name::getRequiredConfig(), 'api_types' => $class_name::getAPITypes(), + 'api_spec' => $class_name::getAPISpec(), ); } } @@ -102,6 +103,7 @@ class SMS 'name' => $driver->getName(), 'required' => $driver->getRequiredConfig(), 'api_types' => $driver->getAPITypes(), + 'api_spec' => $class_name::getAPISpec(), ); } } @@ -115,7 +117,7 @@ class SMS public function __construct() { $this->driver = self::getDefaultDriver(); - $this->from = trim(config('sms.default_from')); + $this->from = trim(preg_replace('/[^0-9]/', '', config('sms.default_from'))) ?: null; $this->allow_split_sms = (config('sms.allow_split.sms') !== false); $this->allow_split_lms = (config('sms.allow_split.lms') !== false); } @@ -135,7 +137,7 @@ class SMS /** * Get the sender's phone number. * - * @return string + * @return string|null */ public function getFrom() { @@ -336,6 +338,10 @@ class SMS { $when = time() + $when; } + if ($when <= time()) + { + $when = 0; + } $this->delay_timestamp = intval($when); return true;