Completed
Pull Request — master (#366)
by Beñat
14:40
created

SignUpUserHandlerSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 26
loc 26
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 4 4 1
A it_signs_up_user() 7 7 1
A it_does_not_sign_up_user_when_the_user_already_exists() 10 10 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
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Spec\Kreta\Notifier\Application\Command\Inbox;
16
17
use Kreta\Notifier\Application\Command\Inbox\SignUpUserCommand;
18
use Kreta\Notifier\Domain\Model\Inbox\User;
19
use Kreta\Notifier\Domain\Model\Inbox\UserAlreadyExists;
20
use Kreta\Notifier\Domain\Model\Inbox\UserDoesNotExist;
21
use Kreta\Notifier\Domain\Model\Inbox\UserId;
22
use Kreta\Notifier\Domain\Model\Inbox\UserRepository;
23
use PhpSpec\ObjectBehavior;
24
use Prophecy\Argument;
25
26 View Code Duplication
class SignUpUserHandlerSpec extends ObjectBehavior
0 ignored issues
show
Duplication introduced by
This class 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...
27
{
28
    function let(UserRepository $repository)
29
    {
30
        $this->beConstructedWith($repository);
31
    }
32
33
    function it_signs_up_user(SignUpUserCommand $command, UserRepository $repository)
34
    {
35
        $command->userId()->shouldBeCalled()->willReturn('user-id');
36
        $repository->get(UserId::generate('user-id'))->willThrow(UserDoesNotExist::class);
37
        $repository->save(Argument::type(User::class))->shouldBeCalled();
38
        $this->__invoke($command);
39
    }
40
41
    function it_does_not_sign_up_user_when_the_user_already_exists(
42
        SignUpUserCommand $command,
43
        UserRepository $repository,
44
        User $user
45
    ) {
46
        $command->userId()->shouldBeCalled()->willReturn('user-id');
47
        $repository->get(UserId::generate('user-id'))->shouldBeCalled()->willReturn($user);
48
        $user->id()->shouldBeCalled()->willReturn(UserId::generate('user-id'));
49
        $this->shouldThrow(UserAlreadyExists::class)->during__invoke($command);
50
    }
51
}
52