Exemple #1
0
 public function testInitialization()
 {
     $Class = new ReflectionClass(Client::class);
     $FromProperty = $Class->getProperty('from');
     $FromProperty->setAccessible(true);
     $UserProperty = $Class->getProperty('user');
     $UserProperty->setAccessible(true);
     $SecretProperty = $Class->getProperty('secret');
     $SecretProperty->setAccessible(true);
     $Client1 = new Client('FROM', 'login', '5eCrET');
     $this->assertEquals('FROM', $FromProperty->getValue($Client1));
     $this->assertEquals('login', $UserProperty->getValue($Client1));
     $this->assertEquals('5eCrET', $SecretProperty->getValue($Client1));
     $this->assertSame(0, $Client1->getConnectTimeout());
     $this->assertSame(0, $Client1->getRequestTimeout());
     $Client2 = new Client('FROM', 'login', '5eCrET');
     $Client2->setRequestTimeout(5)->setConnectTimeout(1);
     $this->assertSame(1, $Client2->getConnectTimeout());
     $this->assertSame(5, $Client2->getRequestTimeout());
 }
Exemple #2
0
$phones = [];
$secret = '';
$text = '';
$user = '';
$Command = new CommandPosix();
$Command->appendHelpParameter('show help');
$Command->appendParameter(new Option('from', 'f', 'sender alpha-name', Option::TYPE_STRING, true), function ($name, $value) use(&$from) {
    $from = (string) $value;
});
$Command->appendParameter(new Option('phone', 'p', 'receiver phone or phones (comma-separated)', Option::TYPE_STRING, true), function ($name, $value) use(&$phones) {
    $phones = explode(',', $value);
});
$Command->appendParameter(new Option('secret', 's', 'secret key', Option::TYPE_STRING, true), function ($name, $value) use(&$secret) {
    $secret = (string) $value;
});
$Command->appendParameter(new Option('text', 't', 'message text', Option::TYPE_STRING, true), function ($name, $value) use(&$text) {
    $text = (string) $value;
});
$Command->appendParameter(new Option('user', 'u', 'sender login', Option::TYPE_STRING, true), function ($name, $value) use(&$user) {
    $user = (string) $value;
});
try {
    $Command->parse(true);
    $Message = new Message($text, true);
    $Message->setPhones($phones);
    $Client = new Client($from, $user, $secret);
    $Result = $Client->send($Message);
    printf("%s\n", (string) $Result);
} catch (RequiredOptionException $Ex) {
    $Command->displayHelp();
}