|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Pavel |
|
5
|
|
|
* Date: 2015-05-09 |
|
6
|
|
|
* Time: 23:01 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace ScayTrase\WebSMS\Tests; |
|
10
|
|
|
|
|
11
|
|
|
use ScayTrase\WebSMS\Connection\Connection; |
|
12
|
|
|
use ScayTrase\WebSMS\Driver\DriverInterface; |
|
13
|
|
|
use ScayTrase\WebSMS\Exception\DeliveryException; |
|
14
|
|
|
use ScayTrase\WebSMS\Exception\DriverException; |
|
15
|
|
|
use ScayTrase\WebSMS\Exception\WebSMSException; |
|
16
|
|
|
|
|
17
|
|
|
class DriverTest extends AbstractWebSMSTest |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @param DriverInterface $driver |
|
21
|
|
|
* |
|
22
|
|
|
* @dataProvider getDrivers |
|
23
|
|
|
*/ |
|
24
|
|
|
public function testConnectionRequest(DriverInterface $driver) |
|
25
|
|
|
{ |
|
26
|
|
|
$connection = new Connection($driver, 'demo', 'demo', Connection::TEST_SPECIAL); |
|
27
|
|
|
$message = $this->getMessageMock(); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertTrue($connection->send($message)); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param DriverInterface $driver |
|
35
|
|
|
* |
|
36
|
|
|
* @dataProvider getDrivers |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testBalanceChecking(DriverInterface $driver) |
|
39
|
|
|
{ |
|
40
|
|
|
$connection = new Connection($driver, 'demo', 'demo', Connection::TEST_SPECIAL); |
|
41
|
|
|
$this->assertTrue($connection->verify()); |
|
42
|
|
|
$this->assertGreaterThan(0, $connection->getBalance()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function invalidCredentialsProvider() |
|
46
|
|
|
{ |
|
47
|
|
|
$driversData = $this->getDrivers(); |
|
48
|
|
|
|
|
49
|
|
|
$credentialsData = array( |
|
50
|
|
|
'no username' => array(null, 'demo'), |
|
51
|
|
|
'no password' => array('demo', null), |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$data = array(); |
|
55
|
|
|
|
|
56
|
|
|
foreach ($driversData as $name => $driver) { |
|
57
|
|
|
foreach ($credentialsData as $pair => $credentials) { |
|
58
|
|
|
$data[sprintf('%s %s', $name, $pair)] = array_merge($driver, $credentials); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $data; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param DriverInterface $driver |
|
67
|
|
|
* @param $username |
|
68
|
|
|
* @param $password |
|
69
|
|
|
* |
|
70
|
|
|
* @dataProvider invalidCredentialsProvider |
|
71
|
|
|
*/ |
|
72
|
|
|
public function testInvalidCredentialsHandling(DriverInterface $driver, $username, $password) |
|
73
|
|
|
{ |
|
74
|
|
|
$connection = new Connection($driver, $username, $password, Connection::TEST_ENABLED); |
|
75
|
|
|
$message = $this->getMessageMock(); |
|
76
|
|
|
|
|
77
|
|
|
try { |
|
78
|
|
|
$connection->send($message); |
|
79
|
|
|
} catch (WebSMSException $exception) { |
|
80
|
|
|
if ($exception instanceof DeliveryException){ |
|
81
|
|
|
return; |
|
82
|
|
|
} elseif ($exception instanceof DriverException){ |
|
83
|
|
|
return; |
|
84
|
|
|
} else { |
|
85
|
|
|
$this->fail('Unexpected exception'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|