Minor changes to support unit testing via dummy

This commit is contained in:
Kijin Sung 2016-11-06 20:54:46 +09:00
parent a92c77655f
commit aab6bd6d48
2 changed files with 38 additions and 3 deletions

View file

@ -32,6 +32,11 @@ class Dummy extends Base implements \Rhymix\Framework\Drivers\SMSInterface
'delay_supported' => true, 'delay_supported' => true,
); );
/**
* Sent messages are stored here for debugging and testing.
*/
protected $_sent_messages = array();
/** /**
* Send a message. * 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) public function send(array $messages, \Rhymix\Framework\SMS $original)
{ {
foreach ($messages as $message)
{
$this->_sent_messages[] = $message;
}
return true; 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();
}
} }

View file

@ -12,7 +12,7 @@ class SMS
*/ */
public $driver = null; public $driver = null;
protected $caller = ''; protected $caller = '';
protected $from = ''; protected $from = null;
protected $to = array(); protected $to = array();
protected $subject = ''; protected $subject = '';
protected $content = ''; protected $content = '';
@ -91,6 +91,7 @@ class SMS
'name' => $class_name::getName(), 'name' => $class_name::getName(),
'required' => $class_name::getRequiredConfig(), 'required' => $class_name::getRequiredConfig(),
'api_types' => $class_name::getAPITypes(), 'api_types' => $class_name::getAPITypes(),
'api_spec' => $class_name::getAPISpec(),
); );
} }
} }
@ -102,6 +103,7 @@ class SMS
'name' => $driver->getName(), 'name' => $driver->getName(),
'required' => $driver->getRequiredConfig(), 'required' => $driver->getRequiredConfig(),
'api_types' => $driver->getAPITypes(), 'api_types' => $driver->getAPITypes(),
'api_spec' => $class_name::getAPISpec(),
); );
} }
} }
@ -115,7 +117,7 @@ class SMS
public function __construct() public function __construct()
{ {
$this->driver = self::getDefaultDriver(); $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_sms = (config('sms.allow_split.sms') !== false);
$this->allow_split_lms = (config('sms.allow_split.lms') !== false); $this->allow_split_lms = (config('sms.allow_split.lms') !== false);
} }
@ -135,7 +137,7 @@ class SMS
/** /**
* Get the sender's phone number. * Get the sender's phone number.
* *
* @return string * @return string|null
*/ */
public function getFrom() public function getFrom()
{ {
@ -336,6 +338,10 @@ class SMS
{ {
$when = time() + $when; $when = time() + $when;
} }
if ($when <= time())
{
$when = 0;
}
$this->delay_timestamp = intval($when); $this->delay_timestamp = intval($when);
return true; return true;