DriverTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 74
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testConnectionRequest() 0 7 1
A testBalanceChecking() 0 6 1
A invalidCredentialsProvider() 0 19 3
A testInvalidCredentialsHandling() 0 18 4
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