Completed
Push — master ( 84505b...5678fc )
by Ivannis Suárez
02:56
created

ProjectionTests   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 84
Duplicated Lines 22.62 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreate() 19 19 1
B testSetReadModel() 0 29 1
A testSetAction() 0 22 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 Cubiche/EventSourcing component.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Domain\EventSourcing\Tests\Units\Projector;
13
14
use Cubiche\Domain\EventSourcing\Projector\Action;
15
use Cubiche\Domain\EventSourcing\Projector\Projection;
16
use Cubiche\Domain\EventSourcing\Tests\Fixtures\ReadModel\PublishedPost;
17
use Cubiche\Domain\EventSourcing\Tests\Units\TestCase;
18
use Cubiche\Domain\Model\Tests\Fixtures\PostId;
19
20
/**
21
 * ProjectionTests class.
22
 *
23
 * Generated by TestGenerator on 2017-05-05 at 11:37:18.
24
 */
25
class ProjectionTests extends TestCase
26
{
27
    /**
28
     * Test create.
29
     */
30 View Code Duplication
    public function testCreate()
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...
31
    {
32
        $this
33
            ->given(
34
                $readModel = new PublishedPost(
35
                    PostId::fromNative(md5(rand())),
36
                    $this->faker->title,
37
                    $this->faker->text()
0 ignored issues
show
Unused Code introduced by
The call to PublishedPost::__construct() has too many arguments starting with $this->faker->text().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
38
                )
39
            )
40
            ->and($action = Action::NONE())
41
            ->when($projection = new Projection($readModel, $action))
42
            ->then()
43
                ->object($projection->readModel())
44
                    ->isEqualTo($readModel)
45
                ->object($projection->action())
46
                    ->isEqualTo($action)
47
        ;
48
    }
49
50
    /**
51
     * Test SetReadModel method.
52
     */
53
    public function testSetReadModel()
54
    {
55
        $this
56
            ->given(
57
                $readModel = new PublishedPost(
58
                    PostId::fromNative(md5(rand())),
59
                    $this->faker->title,
60
                    $this->faker->text()
0 ignored issues
show
Unused Code introduced by
The call to PublishedPost::__construct() has too many arguments starting with $this->faker->text().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
61
                )
62
            )
63
            ->and(
64
                $newReadModel = new PublishedPost(
65
                    PostId::fromNative(md5(rand())),
66
                    $this->faker->title,
67
                    $this->faker->text()
0 ignored issues
show
Unused Code introduced by
The call to PublishedPost::__construct() has too many arguments starting with $this->faker->text().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
68
                )
69
            )
70
            ->and($action = Action::NONE())
71
            ->when($projection = new Projection($readModel, $action))
72
            ->then()
73
                ->object($projection->readModel())
74
                    ->isEqualTo($readModel)
75
                ->and()
76
                ->when($projection->setReadModel($newReadModel))
77
                ->then()
78
                    ->object($projection->readModel())
79
                        ->isEqualTo($newReadModel)
80
        ;
81
    }
82
83
    /**
84
     * Test SetAction method.
85
     */
86
    public function testSetAction()
87
    {
88
        $this
89
            ->given(
90
                $readModel = new PublishedPost(
91
                    PostId::fromNative(md5(rand())),
92
                    $this->faker->title,
93
                    $this->faker->text()
0 ignored issues
show
Unused Code introduced by
The call to PublishedPost::__construct() has too many arguments starting with $this->faker->text().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
94
                )
95
            )
96
            ->and($action = Action::NONE())
97
            ->when($projection = new Projection($readModel, $action))
98
            ->then()
99
                ->object($projection->action())
100
                    ->isEqualTo($action)
101
                ->and()
102
                ->when($projection->setAction(Action::REMOVE()))
103
                ->then()
104
                    ->object($projection->action())
105
                        ->isEqualTo(Action::REMOVE())
106
        ;
107
    }
108
}
109