Passed
Push — master ( bb5c60...87d27f )
by Tim
01:35
created

TestLdapSearchTest::testSearchSuccesful()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 18
rs 9.8666
c 0
b 0
f 0
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\Search
12
 */
13
class TestLdapSearchTest extends \PHPUnit_Framework_TestCase
14
{
15
    public function testSearchSuccesful()
16
    {
17
        $authSourceData = [
18
            'search.base' => 'OU=example,DC=example,DC=org',
19
            'search.username' => 'testuser',
20
            'search.password' => 'password',
21
        ];
22
        $connectionMock = $this->getMock('LdapSearch', array('searchfordn'));
23
        $connectionMock->expects($this->once())->method('searchfordn')->will($this->returnValue(true));
24
        $confTest = new TestCase\AuthSource\Ldap\Search(
25
            new TestData([
26
                'authSourceData' => ApplicationConfiguration::loadFromArray($authSourceData),
27
                'connection' => $connectionMock,
28
            ])
29
        );
30
        $testResult = $confTest->getTestResult();
31
32
        $this->assertEquals(State::OK, $testResult->getState());
33
    }
34
35
    public function testSearchFailed()
36
    {
37
        $authSourceData = [
38
            'search.base' => 'OU=example,DC=example,DC=org',
39
            'search.username' => 'CN=testuser,OU=example,DC=example,DC=org',
40
            'search.password' => 'password',
41
        ];
42
        $connectionMock = $this->getMock('LdapSearch', array('searchfordn'));
43
        $connectionMock->expects($this->once())->method('searchfordn')->will($this->throwException(new \SimpleSAML_Error_Error('UNHANDLEDEXCEPTION')));
44
        $confTest = new TestCase\AuthSource\Ldap\Search(
45
            new TestData([
46
                'authSourceData' => ApplicationConfiguration::loadFromArray($authSourceData),
47
                'connection' => $connectionMock,
48
            ])
49
        );
50
        $testResult = $confTest->getTestResult();
51
52
        $this->assertEquals(State::ERROR, $testResult->getState());
53
    }
54
}
55