EventStreamTests   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 33.85 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 22
loc 65
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testStreamName() 11 11 1
A testAggregateId() 11 11 1
B testEvents() 0 29 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\EventStore;
13
14
use Cubiche\Domain\EventSourcing\EventStore\EventStream;
15
use Cubiche\Domain\EventSourcing\Tests\Fixtures\Event\PostWasCreated;
16
use Cubiche\Domain\EventSourcing\Tests\Units\TestCase;
17
use Cubiche\Domain\Model\Tests\Fixtures\PostId;
18
19
/**
20
 * EventStreamTests class.
21
 *
22
 * Generated by TestGenerator on 2016-06-28 at 14:36:54.
23
 */
24
class EventStreamTests extends TestCase
25
{
26
    /**
27
     * Test StreamName method.
28
     */
29 View Code Duplication
    public function testStreamName()
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($postId = PostId::fromNative(md5(rand())))
33
            ->and($streamName = 'Posts-'.$postId)
34
            ->and($eventStream = new EventStream($streamName, $postId, []))
35
            ->then()
36
                ->string($eventStream->streamName())
37
                    ->isEqualTo($streamName)
38
        ;
39
    }
40
41
    /**
42
     * Test AggregateId method.
43
     */
44 View Code Duplication
    public function testAggregateId()
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...
45
    {
46
        $this
47
            ->given($postId = PostId::fromNative(md5(rand())))
48
            ->and($streamName = 'Posts-'.$postId)
49
            ->and($eventStream = new EventStream($streamName, $postId, []))
50
            ->then()
51
                ->object($eventStream->aggregateId())
52
                    ->isEqualTo($postId)
53
        ;
54
    }
55
56
    /**
57
     * Test Events method.
58
     */
59
    public function testEvents()
60
    {
61
        $this
62
            ->given($postId = PostId::fromNative(md5(rand())))
63
            ->and($streamName = 'Posts-'.$postId)
64
            ->and($eventStream = new EventStream($streamName, $postId, []))
65
            ->then()
66
                ->array($eventStream->events())
67
                    ->isEmpty()
68
        ;
69
70
        $this
71
            ->given($postId = PostId::fromNative(md5(rand())))
72
            ->and($streamName = 'Posts-'.$postId)
73
            ->and($eventStream = new EventStream($streamName, $postId, [new PostWasCreated($postId, 'foo', 'bar')]))
74
            ->then()
75
                ->array($eventStream->events())
76
                    ->hasSize(1)
77
        ;
78
79
        $this
80
            ->given($postId = PostId::fromNative(md5(rand())))
81
            ->and($streamName = 'Posts-'.$postId)
82
            ->then()
83
                ->exception(function () use ($streamName, $postId) {
84
                    new EventStream($streamName, $postId, ['bar']);
0 ignored issues
show
Documentation introduced by
array('bar') is of type array<integer,string,{"0":"string"}>, but the function expects a array<integer,object<Cub...\DomainEventInterface>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
                })->isInstanceOf(\InvalidArgumentException::class)
86
        ;
87
    }
88
}
89