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

PasswordResetHandlerTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
B testPasswordResetGetsHandled() 0 26 1
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Tests\Command;
4
5
use SumoCoders\FrameworkMultiUserBundle\Command\ResetPassword;
6
use SumoCoders\FrameworkMultiUserBundle\Command\ResetPasswordHandler;
7
use SumoCoders\FrameworkMultiUserBundle\DataTransferObject\Form\ChangePassword;
8
use SumoCoders\FrameworkMultiUserBundle\Exception\InvalidPasswordConfirmationException;
9
use SumoCoders\FrameworkMultiUserBundle\User\InMemoryUserRepository;
10
use SumoCoders\FrameworkMultiUserBundle\User\User;
11
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection;
12
13
class PasswordResetHandlerTest extends \PHPUnit_Framework_TestCase
14
{
15
    /**
16
     * @var UserRepository
17
     */
18
    private $userRepository;
19
20
    /**
21
     * @var UserRepositoryCollection
22
     */
23
    private $userRepositoryCollection;
24
25
    public function setUp()
26
    {
27
        $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...
28
        $this->userRepositoryCollection = new UserRepositoryCollection([$this->userRepository]);
29
    }
30
31
    /**
32
     * Test if PAsswordResetHandler gets handled.
33
     *
34
     * @throws InvalidPasswordConfirmationException
35
     */
36
    public function testPasswordResetGetsHandled()
37
    {
38
        $handler = new ResetPasswordHandler($this->userRepositoryCollection);
39
40
        $user = $this->userRepository->findByUsername('reset');
41
        
42
        $dataTransferObject = ChangePassword::forUser($user);
43
        $dataTransferObject->newPassword = 'changedPassword';
44
45
        $user = $this->userRepositoryCollection
46
            ->findRepositoryByClassName(User::class)
47
            ->findByUsername('reset');
48
        $password = $user->getPassword();
49
        $token = $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...
50
51
        $handler->handle($dataTransferObject);
52
53
        $updatedUser = $this->userRepositoryCollection
54
            ->findRepositoryByClassName(User::class)
55
            ->findByUsername('reset');
56
57
        $this->assertEquals($user->getUsername(), $updatedUser->getUsername());
58
        $this->assertNotEquals($password, $updatedUser->getPassword());
59
        $this->assertNotNull($token);
60
        $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...
61
    }
62
}
63