Completed
Pull Request — master (#13)
by
unknown
07:15
created

  A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 1
eloc 6
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
        $dataTransferObject = ChangePassword::forUser($user);
42
        $dataTransferObject->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($dataTransferObject);
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