DeleteUserHandlerTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 21.21 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 8
dl 7
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 7 7 1
A testUpdateUserGetsHandled() 0 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Tests\Command;
4
5
use PHPUnit_Framework_TestCase;
6
use SumoCoders\FrameworkMultiUserBundle\Command\DeleteUserHandler;
7
use SumoCoders\FrameworkMultiUserBundle\DataTransferObject\BaseUserDataTransferObject;
8
use SumoCoders\FrameworkMultiUserBundle\Entity\BaseUser;
9
use SumoCoders\FrameworkMultiUserBundle\User\InMemoryBaseUserRepository;
10
use SumoCoders\FrameworkMultiUserBundle\User\Interfaces\UserRepository;
11
use SumoCoders\FrameworkMultiUserBundle\User\BaseUserRepositoryCollection;
12
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
13
use Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder;
14
15
class DeleteUserHandlerTest extends PHPUnit_Framework_TestCase
16
{
17
    /** @var UserRepository */
18
    private $userRepository;
19
20
    /** @var BaseUserRepositoryCollection */
21
    private $userRepositoryCollection;
22
23 View Code Duplication
    public function setUp(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $this->userRepository = new InMemoryBaseUserRepository(
26
            new EncoderFactory([BaseUser::class => new PlaintextPasswordEncoder()])
27
        );
28
        $this->userRepositoryCollection = new BaseUserRepositoryCollection([$this->userRepository]);
29
    }
30
31
    /**
32
     * Test if DeleteUserHandler gets handled.
33
     */
34
    public function testUpdateUserGetsHandled(): void
35
    {
36
        $handler = new DeleteUserHandler($this->userRepositoryCollection);
37
38
        $deletingUser = $this->userRepository->findByUsername('wouter');
39
40
        $handler->handle(BaseUserDataTransferObject::fromUser($deletingUser));
41
42
        $this->assertNotNull($deletingUser);
43
        $this->assertNull(
44
            $this->userRepository->findByUsername('wouter')
45
        );
46
    }
47
}
48