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

testPasswordResetGetsHandled()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 26
rs 8.8571
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Tests\Command;
4
5
use SumoCoders\FrameworkMultiUserBundle\Command\ResetPasswordHandler;
6
use SumoCoders\FrameworkMultiUserBundle\DataTransferObject\Form\ChangePassword;
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 gets handled.
32
     *
33
     * @throws InvalidPasswordConfirmationException
34
     */
35
    public function testPasswordResetGetsHandled()
36
    {
37
        $handler = new ResetPasswordHandler($this->userRepositoryCollection);
38
39
        $user = $this->userRepository->findByUsername('reset');
40
41
        $changePasswordTransferObject = ChangePassword::forUser($user);
42
        $changePasswordTransferObject->newPassword = 'changedPassword';
43
44
        $user = $this->userRepositoryCollection
45
            ->findRepositoryByClassName(User::class)
46
            ->findByUsername('reset');
47
        $password = $user->getPassword();
48
        $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...
49
50
        $handler->handle($changePasswordTransferObject);
51
52
        $updatedUser = $this->userRepositoryCollection
53
            ->findRepositoryByClassName(User::class)
54
            ->findByUsername('reset');
55
56
        $this->assertEquals($user->getUsername(), $updatedUser->getUsername());
57
        $this->assertNotEquals($password, $updatedUser->getPassword());
58
        $this->assertNotNull($token);
59
        $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...
60
    }
61
}
62