Completed
Pull Request — master (#12)
by
unknown
07:31 queued 04:16
created

CreateUserHandlerTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
B testCreateUserGetsHandled() 0 25 1
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Tests\Command;
4
5
use SumoCoders\FrameworkMultiUserBundle\Command\CreateUser;
6
use SumoCoders\FrameworkMultiUserBundle\Command\CreateUserHandler;
7
use SumoCoders\FrameworkMultiUserBundle\User\InMemoryUserRepository;
8
use SumoCoders\FrameworkMultiUserBundle\User\User;
9
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection;
10
11
class CreateUserHandlerTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @var UserRepository
15
     */
16
    private $userRepository;
17
18
    /**
19
     * @var UserRepositoryCollection
20
     */
21
    private $userRepositoryCollection;
22
23
    public function setUp()
24
    {
25
        $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...
26
        $this->userRepositoryCollection = new UserRepositoryCollection([$this->userRepository]);
27
    }
28
29
    /**
30
     * Test if CreateUserHandler gets handled.
31
     */
32
    public function testCreateUserGetsHandled()
33
    {
34
        $handler = new CreateUserHandler($this->userRepositoryCollection);
35
36
        $user = new CreateUser('sumo', 'randomPassword', 'sumocoders', '[email protected]');
37
38
        $handler->handle($user, User::class);
39
40
        $this->assertEquals(
41
            'sumo',
42
            $this->userRepository->findByUsername('sumo')->getUsername()
43
        );
44
        $this->assertEquals(
45
            'sumocoders',
46
            $this->userRepository->findByUsername('sumo')->getDisplayName()
47
        );
48
        $this->assertEquals(
49
            'randomPassword',
50
            $this->userRepository->findByUsername('sumo')->getPassword()
51
        );
52
        $this->assertEquals(
53
            '[email protected]',
54
            $this->userRepository->findByUsername('sumo')->getEmail()
55
        );
56
    }
57
}
58