Exemple #1
0
use Xi\Sms\Event\SmsMessageEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
if (!@(include __DIR__ . '/../vendor/autoload.php')) {
    die("You must set up the project dependencies, run the following commands:\nwget http://getcomposer.org/composer.phar\nphp composer.phar install --dev\n");
}
gc_enable();
if (count($argv) != 3 || in_array('-h', $argv) || in_array('--argv', $argv)) {
    echo "Usage: {$argv[0]} from to\n";
    echo "Then input the text to send and press Ctrl+D\n";
    exit;
}
$from = $argv[1];
$to = $argv[2];
$ed = new EventDispatcher();
$gw = null;
$gw = new MessageBirdGateway('');
if (!$gw) {
    throw new LogicException('Configure gateway');
}
$service = new SmsService($gw, $ed);
$ed->addListener(Events::SEND, function (SmsMessageEvent $event) {
    $msg = $event->getMessage();
    echo "Message sent.\n";
    echo "From: " . $msg->getFrom() . "\n";
    echo "To: " . print_r($msg->getTo(), true) . "\n";
    echo "Body:\n" . $msg->getBody() . "\n\n";
});
$body = stream_get_contents(STDIN);
$msg = new SmsMessage($body, $from, $to);
echo "Sending...\n";
$service->send($msg);
 /**
  * @test
  */
 public function urlNormalDispatch()
 {
     $ResponseMock = $this->getMock('Buzz\\Message\\Response', array('getContent', 'isOk'));
     $ResponseMock->expects($this->once())->method('getContent')->will($this->returnValue('100'));
     $ResponseMock->expects($this->once())->method('isOk')->will($this->returnValue(true));
     $ClientMock = $this->getMock('Browser', array('get'));
     $ClientMock->expects($this->once())->method('get')->with($this->callback(function ($actual) {
         $url = parse_url($actual);
         parse_str($url['query'], $query);
         return $url['scheme'] === 'http' && $url['host'] === 'www.smskaufen.com' && $url['path'] === '/sms/gateway/sms.php' && $query['id'] === 'XXX' && $query['pw'] === 'YYY' && $query['type'] == 4 && $query['text'] === 'Hi' && $query['empfaenger'] === '00491111' && $query['absender'] === '00491234';
     }), $this->isType('array'))->will($this->returnValue($ResponseMock));
     $this->SmskaufenGateway = $this->getMock('Xi\\Sms\\Gateway\\SmskaufenGateway', array('getClient'), array(array('username' => 'XXX', 'password' => 'YYY', 'https' => false, 'gateway' => 4)));
     $this->SmskaufenGateway->expects($this->once())->method('getClient')->will($this->returnValue($ClientMock));
     $service = new SmsService($this->SmskaufenGateway);
     $msg = new SmsMessage('Hi', '00491234', '00491111');
     $service->send($msg);
 }