Passed
Branch monitor-2.5.x (1a1f16)
by Tim
03:17
created

TestLdapBindTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testBindFailed() 0 17 1
A testAuthenticationFailed() 0 17 1
A testBindSuccesful() 0 17 1
1
<?php
2
3
namespace SimpleSAML\Modules\Monitor\Test;
4
5
use \SimpleSAML_Configuration as ApplicationConfiguration;
6
use \SimpleSAML\Modules\Monitor\TestCase as TestCase;
7
use \SimpleSAML\Modules\Monitor\TestData as TestData;
8
use \SimpleSAML\Modules\Monitor\State as State;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Modules\Monitor\State was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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