Completed
Pull Request — master (#12)
by
unknown
03:12
created

PasswordResetHandlerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 3
c 3
b 0
f 2
lcom 1
cbo 6
dl 0
loc 63
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testPasswordResetThrowsError() 0 11 1
A testPasswordResetGetsHandled() 0 22 1
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Tests\Command;
4
5
use SumoCoders\FrameworkMultiUserBundle\Command\ResetPassword;
6
use SumoCoders\FrameworkMultiUserBundle\Command\PasswordResetHandler;
7
use SumoCoders\FrameworkMultiUserBundle\Exception\InvalidPasswordConfirmationException;
8
use SumoCoders\FrameworkMultiUserBundle\User\InMemoryUserRepository;
9
use SumoCoders\FrameworkMultiUserBundle\User\User;
10
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection;
11
12
class PasswordResetHandlerTest extends \PHPUnit_Framework_TestCase
13
{
14
    /**
15
     * @var UserRepository
16
     */
17
    private $userRepository;
18
19
    /**
20
     * @var UserRepositoryCollection
21
     */
22
    private $userRepositoryCollection;
23
24
    public function setUp()
25
    {
26
        $this->userRepository = new InMemoryUserRepository();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \SumoCoders\Framewor...nMemoryUserRepository() of type object<SumoCoders\Framew...InMemoryUserRepository> is incompatible with the declared type object<SumoCoders\Framew...Command\UserRepository> of property $userRepository.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
        $this->userRepositoryCollection = new UserRepositoryCollection([$this->userRepository]);
28
    }
29
30
    /**
31
     * Test if PasswordResetHandler throws error.
32
     *
33
     * @throws InvalidPasswordConfirmationException
34
     */
35
    public function testPasswordResetThrowsError()
36
    {
37
        $handler = new PasswordResetHandler($this->userRepositoryCollection);
38
39
        $user = $this->userRepository->findByUsername('wouter');
40
        $event = new ResetPassword($user, 'password', 'wrong_confirmation');
41
42
        $this->setExpectedException(InvalidPasswordConfirmationException::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
43
44
        $handler->handle($event);
45
    }
46
47
    /**
48
     * Test if PAsswordResetHandler gets handled.
49
     *
50
     * @throws InvalidPasswordConfirmationException
51
     */
52
    public function testPasswordResetGetsHandled()
53
    {
54
        $handler = new PasswordResetHandler($this->userRepositoryCollection);
55
56
        $user = $this->userRepository->findByUsername('reset');
57
        $event = new ResetPassword($user, 'password', 'password');
58
59
        $user = $this->userRepositoryCollection
60
            ->findRepositoryByClassName(User::class)
61
            ->findByUsername('reset');
62
63
        $handler->handle($event);
64
65
        $updatedUser = $this->userRepositoryCollection
66
            ->findRepositoryByClassName(User::class)
67
            ->findByUsername('reset');
68
69
        $this->assertEquals($user->getUsername(), $updatedUser->getUsername());
70
        $this->assertNotEquals($user->getPassword(), $updatedUser->getPassword());
71
        $this->assertNotNull($user->getPasswordResetToken());
0 ignored issues
show
Bug introduced by
The method getPasswordResetToken() does not exist on SumoCoders\FrameworkMult...ndle\User\UserInterface. Did you maybe mean getPassword()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
72
        $this->assertNull($updatedUser->getPasswordResetToken());
0 ignored issues
show
Bug introduced by
The method getPasswordResetToken() does not exist on SumoCoders\FrameworkMult...ndle\User\UserInterface. Did you maybe mean getPassword()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
73
    }
74
}
75