Passed
Push — master ( 6a344f...81ee12 )
by Tim
01:36
created

TestLdapBindTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testBindSuccesful() 0 17 1
A testAuthenticationFailed() 0 17 1
A testBindFailed() 0 17 1
1
<?php
2
3
namespace SimpleSAML\Module\monitor\Test;
4
5
use \SimpleSAML\Module\monitor\TestCase as TestCase;
6
use \SimpleSAML\Module\monitor\TestData as TestData;
7
use \SimpleSAML\Module\monitor\State as State;
8
9
/**
10
 * Tests for TestCase\Ldap\Configuration
11
 */
12
class TestLdapBindTest extends \PHPUnit_Framework_TestCase
13
{
14
    public function testBindSuccesful()
15
    {
16
        $authSourceData = [
17
            'search.username' => 'testuser',
18
            'search.password' => 'password',
19
        ];
20
        $connectionMock = $this->getMock('LdapConnection', array('bind'));
21
        $connectionMock->expects($this->once())->method('bind')->will($this->returnValue(true));
22
        $confTest = new TestCase\AuthSource\Ldap\Bind(
23
            new TestData([
24
                'authSourceData' => $authSourceData,
25
                'connection' => $connectionMock,
26
            ])
27
        );
28
        $testResult = $confTest->getTestResult();
29
30
        $this->assertEquals(State::OK, $testResult->getState());
31
    }
32
33
    public function testBindFailed()
34
    {
35
        $authSourceData = [
36
            'search.username' => 'testuser',
37
            'search.password' => 'password',
38
        ];
39
        $connectionMock = $this->getMock('LdapConnection', array('bind'));
40
        $connectionMock->expects($this->once())->method('bind')->will($this->throwException(new \Exception()));
41
        $confTest = new TestCase\AuthSource\Ldap\Bind(
42
            new TestData([
43
                'authSourceData' => $authSourceData,
44
                'connection' => $connectionMock,
45
            ])
46
        );
47
        $testResult = $confTest->getTestResult();
48
49
        $this->assertEquals(State::FATAL, $testResult->getState());
50
    }
51
52
    public function testAuthenticationFailed()
53
    {
54
        $authSourceData = [
55
            'search.username' => 'testuser',
56
            'search.password' => 'password',
57
        ];
58
        $connectionMock = $this->getMock('LdapConnection', array('bind'));
59
        $connectionMock->expects($this->once())->method('bind')->will($this->returnValue(false));
60
        $confTest = new TestCase\AuthSource\Ldap\Bind(
61
            new TestData([
62
                'authSourceData' => $authSourceData,
63
                'connection' => $connectionMock,
64
            ])
65
        );
66
        $testResult = $confTest->getTestResult();
67
68
        $this->assertEquals(State::ERROR, $testResult->getState());
69
    }
70
}
71