SnapshotAggregateRepositoryTests   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 11
dl 0
loc 78
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createRepository() 0 11 3
B testGet() 0 26 1
B testPersist() 0 24 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
12
namespace Cubiche\Domain\EventSourcing\Tests\Units\Snapshot;
13
14
use Cubiche\Domain\EventSourcing\EventStore\InMemoryEventStore;
15
use Cubiche\Domain\EventSourcing\Snapshot\InMemorySnapshotStore;
16
use Cubiche\Domain\EventSourcing\Snapshot\Policy\EventsBasedSnapshottingPolicy;
17
use Cubiche\Domain\EventSourcing\Snapshot\Policy\NoSnapshottingPolicy;
18
use Cubiche\Domain\EventSourcing\Snapshot\Policy\SnapshottingPolicyInterface;
19
use Cubiche\Domain\EventSourcing\Snapshot\Snapshot;
20
use Cubiche\Domain\EventSourcing\Snapshot\SnapshotAggregateRepository;
21
use Cubiche\Domain\EventSourcing\Snapshot\SnapshotStoreInterface;
22
use Cubiche\Domain\EventSourcing\Tests\Fixtures\PostEventSourced;
23
use Cubiche\Domain\EventSourcing\Tests\Fixtures\PostEventSourcedFactory;
24
use Cubiche\Domain\EventSourcing\Tests\Units\AggregateRepositoryTests;
25
use Cubiche\Domain\EventSourcing\Utils\NameResolver;
26
27
/**
28
 * SnapshotAggregateRepositoryTests class.
29
 *
30
 * Generated by TestGenerator on 2016-06-28 at 14:36:54.
31
 */
32
class SnapshotAggregateRepositoryTests extends AggregateRepositoryTests
33
{
34
    /**
35
     * @param SnapshotStoreInterface      $snapshotStore
36
     * @param SnapshottingPolicyInterface $snapshottingPolicy
37
     *
38
     * @return SnapshotAggregateRepository
39
     */
40
    protected function createRepository(
41
        SnapshotStoreInterface $snapshotStore = null,
42
        SnapshottingPolicyInterface $snapshottingPolicy = null
43
    ) {
44
        return new SnapshotAggregateRepository(
45
            new InMemoryEventStore(),
46
            $snapshotStore ? $snapshotStore : new InMemorySnapshotStore(),
47
            $snapshottingPolicy ? $snapshottingPolicy : new NoSnapshottingPolicy(),
48
            PostEventSourced::class
49
        );
50
    }
51
52
    /**
53
     * Test Get method.
54
     */
55
    public function testGet()
56
    {
57
        $this
58
            ->given($store = new InMemorySnapshotStore())
59
            ->and($repository = $this->createRepository($store))
60
            ->and(
61
                $post = PostEventSourcedFactory::create(
62
                    $this->faker->sentence,
63
                    $this->faker->paragraph
64
                )
65
            )
66
            ->and($post->changeTitle($this->faker->sentence))
67
            ->and(
68
                $snapshot = new Snapshot(NameResolver::resolve(get_class($post), $post->id()), $post, new \DateTime())
0 ignored issues
show
Unused Code introduced by
The call to Snapshot::__construct() has too many arguments starting with new \DateTime().

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...
69
            )
70
            ->when($repository->persist($post))
71
            ->then()
72
                ->object($repository->get($post->id()))
73
                    ->isEqualTo($post)
74
            ->and()
75
            ->when($store->persist($snapshot))
76
            ->then()
77
                ->object($repository->get($post->id()))
78
                    ->isEqualTo($post)
79
        ;
80
    }
81
82
    /**
83
     * Test Persist method.
84
     */
85
    public function testPersist()
86
    {
87
        parent::testPersist();
88
89
        $this
90
            ->given(
91
                $repository = $this->createRepository(
92
                    new InMemorySnapshotStore(),
93
                    new EventsBasedSnapshottingPolicy()
94
                )
95
            )
96
            ->and(
97
                $post = PostEventSourcedFactory::create(
98
                    $this->faker->sentence,
99
                    $this->faker->paragraph
100
                )
101
            )
102
            ->and($post->changeTitle($this->faker->sentence))
103
            ->when($repository->persist($post))
104
            ->then()
105
                ->object($repository->get($post->id()))
106
                    ->isEqualTo($post)
107
        ;
108
    }
109
}
110