SnapshotTests   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 84
Duplicated Lines 57.14 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 48
loc 84
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testSnapshotName() 16 16 1
A testAggregate() 16 16 1
A testVersion() 0 18 1
A testCreatedAt() 16 16 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\Snapshot;
13
14
use Cubiche\Domain\EventSourcing\Snapshot\Snapshot;
15
use Cubiche\Domain\EventSourcing\Tests\Fixtures\PostEventSourcedFactory;
16
use Cubiche\Domain\EventSourcing\Tests\Units\TestCase;
17
use Cubiche\Domain\EventSourcing\Versioning\Version;
18
19
/**
20
 * SnapshotTests class.
21
 *
22
 * Generated by TestGenerator on 2016-06-28 at 14:36:54.
23
 */
24
class SnapshotTests extends TestCase
25
{
26
    /**
27
     * Test snapshotName method.
28
     */
29 View Code Duplication
    public function testSnapshotName()
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...
30
    {
31
        $this
32
            ->given(
33
                $post = PostEventSourcedFactory::create(
34
                    $this->faker->sentence,
35
                    $this->faker->paragraph
36
                )
37
            )
38
            ->and($snapshotName = 'Posts-'.$post->id()->toNative())
39
            ->and($snapshot = new Snapshot($snapshotName, $post))
40
            ->then()
41
                ->string($snapshot->snapshotName())
42
                    ->isEqualTo($snapshotName)
43
        ;
44
    }
45
46
    /**
47
     * Test Aggregate method.
48
     */
49 View Code Duplication
    public function testAggregate()
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...
50
    {
51
        $this
52
            ->given(
53
                $post = PostEventSourcedFactory::create(
54
                    $this->faker->sentence,
55
                    $this->faker->paragraph
56
                )
57
            )
58
            ->and($snapshotName = 'Posts-'.$post->id()->toNative())
59
            ->and($snapshot = new Snapshot($snapshotName, $post))
60
            ->then()
61
                ->object($snapshot->aggregate())
62
                    ->isEqualTo($post)
63
        ;
64
    }
65
66
    /**
67
     * Test Version method.
68
     */
69
    public function testVersion()
70
    {
71
        $this
72
            ->given(
73
                $post = PostEventSourcedFactory::create(
74
                    $this->faker->sentence,
75
                    $this->faker->paragraph
76
                )
77
            )
78
            ->and($post->setVersion(345))
79
            ->and($snapshotName = 'Posts-'.$post->id()->toNative())
80
            ->and($snapshot = new Snapshot($snapshotName, $post))
81
            ->then()
82
                ->integer($snapshot->version())
83
                    ->isEqualTo($post->version())
84
                    ->isEqualTo(345)
85
        ;
86
    }
87
88
    /**
89
     * Test CreatedAt method.
90
     */
91 View Code Duplication
    public function testCreatedAt()
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...
92
    {
93
        $this
94
            ->given(
95
                $post = PostEventSourcedFactory::create(
96
                    $this->faker->sentence,
97
                    $this->faker->paragraph
98
                )
99
            )
100
            ->and($snapshotName = 'Posts-'.$post->id()->toNative())
101
            ->and($snapshot = new Snapshot($snapshotName, $post))
102
            ->then()
103
                ->object($snapshot->createdAt())
104
                    ->isInstanceOf(\DateTime::class)
105
        ;
106
    }
107
}
108