CompositeSnapshottingPolicyTests   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
c 1
b 0
f 1
lcom 1
cbo 7
dl 0
loc 51
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testShouldCreateSnapshot() 0 45 1
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
namespace Cubiche\Domain\EventSourcing\Tests\Units\Snapshot\Policy;
12
13
use Cubiche\Domain\EventSourcing\Snapshot\Policy\AllwaysSnapshottingPolicy;
14
use Cubiche\Domain\EventSourcing\Snapshot\Policy\CompositeSnapshottingPolicy;
15
use Cubiche\Domain\EventSourcing\Snapshot\Policy\EventsBasedSnapshottingPolicy;
16
use Cubiche\Domain\EventSourcing\Tests\Fixtures\PostEventSourcedFactory;
17
use Cubiche\Domain\EventSourcing\Tests\Units\TestCase;
18
19
/**
20
 * CompositeSnapshottingPolicyTests class.
21
 *
22
 * Generated by TestGenerator on 2016-07-26 at 14:15:46.
23
 */
24
class CompositeSnapshottingPolicyTests extends TestCase
25
{
26
    /**
27
     * Test ShouldCreateSnapshot method.
28
     */
29
    public function testShouldCreateSnapshot()
30
    {
31
        $this
32
            ->given(
33
                $policy = new CompositeSnapshottingPolicy(
34
                    [new AllwaysSnapshottingPolicy(), new EventsBasedSnapshottingPolicy()]
35
                )
36
            )
37
            ->and(
38
                $post = PostEventSourcedFactory::create(
39
                    $this->faker->sentence,
40
                    $this->faker->paragraph
41
                )
42
            )
43
            ->then()
44
                ->boolean($policy->shouldCreateSnapshot($post))
45
                    ->isTrue()
46
        ;
47
48
        $this
49
            ->given(
50
                $policy = new CompositeSnapshottingPolicy(
51
                    [new AllwaysSnapshottingPolicy(), new EventsBasedSnapshottingPolicy()]
52
                )
53
            )
54
            ->and(
55
                $post = PostEventSourcedFactory::create(
56
                    $this->faker->sentence,
57
                    $this->faker->paragraph
58
                )
59
            )
60
            ->and($post->clearEvents())
61
            ->then()
62
                ->boolean($policy->shouldCreateSnapshot($post))
63
                    ->isFalse()
64
        ;
65
66
        $this
67
            ->exception(function () {
68
                new CompositeSnapshottingPolicy(
69
                    [new AllwaysSnapshottingPolicy(), 'foo']
0 ignored issues
show
Documentation introduced by
array(new \Cubiche\Domai...hottingPolicy(), 'foo') is of type array<integer,object<Cub...Policy>","1":"string"}>, but the function expects a array<integer,object<Cub...ottingPolicyInterface>>.

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...
70
                );
71
            })->isInstanceOf(\InvalidArgumentException::class)
72
        ;
73
    }
74
}
75