Passed
Branch master (022a1c)
by Darwin
03:39
created

LdapUserProviderTest::testLoadUserByUsername()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace DoL\LdapBundle\Tests\Security\User;
4
5
use DoL\LdapBundle\Security\User\LdapUserProvider;
6
use DoL\LdapBundle\Tests\TestUser;
7
use FR3D\Psr3MessagesAssertions\PhpUnit\TestLogger;
8
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
9
10
/**
11
 * @covers \DoL\LdapBundle\Security\User\LdapUserProvider
12
 */
13
class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
14
{
15
    /**
16
     * @var \DoL\LdapBundle\Ldap\LdapManager|\PHPUnit_Framework_MockObject_MockObject
17
     */
18
    protected $ldapManager;
19
20
    /**
21
     * @var \DoL\LdapBundle\Security\User\LdapUserProvider
22
     */
23
    protected $userProvider;
24
25
    protected function setUp()
26
    {
27
        $this->ldapManager = $this->getMockBuilder('DoL\LdapBundle\Ldap\LdapManager')
28
            ->disableOriginalConstructor()
29
            ->getMock();
30
31
        $this->userProvider = new LdapUserProvider($this->ldapManager, new TestLogger());
32
    }
33
34 View Code Duplication
    public function testLoadUserByUsername()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        $username = 'test_username';
37
        $user = new TestUser();
38
        $user->setUsername($username);
39
40
        $this->ldapManager->expects($this->once())
41
            ->method('findUserByUsername')
42
            ->with($this->equalTo($username))
43
            ->will($this->returnValue($user));
44
45
        self::assertEquals($username, $this->userProvider->loadUserByUsername($username)->getUsername());
46
    }
47
48
    public function testLoadUserByUsernameNotFound()
49
    {
50
        $username = 'invalid_username';
51
52
        $this->ldapManager->expects($this->once())
53
            ->method('findUserByUsername')
54
            ->will($this->returnValue(null));
55
56
        try {
57
            $this->userProvider->loadUserByUsername($username);
58
            self::fail('Expected Symfony\Component\Security\Core\Exception\UsernameNotFoundException to be thrown');
59
        } catch (UsernameNotFoundException $notFoundException) {
60
            self::assertEquals($username, $notFoundException->getUsername());
61
        }
62
    }
63
64 View Code Duplication
    public function testRefreshUser()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
        $username = 'test_username';
67
        $user = new TestUser();
68
        $user->setUsername($username);
69
70
        $this->ldapManager->expects($this->once())
71
            ->method('findUserByUsername')
72
            ->with($this->equalTo($username))
73
            ->will($this->returnValue($user));
74
75
        self::assertEquals($user, $this->userProvider->refreshUser($user));
76
    }
77
}
78