ProjectorTests   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 10

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 10
dl 0
loc 64
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createProjector() 0 4 1
A testCreate() 0 50 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\Projector;
13
14
use Cubiche\Core\Specification\Criteria;
15
use Cubiche\Domain\EventPublisher\DomainEventPublisher;
16
use Cubiche\Domain\EventSourcing\AggregateRepository;
17
use Cubiche\Domain\EventSourcing\EventStore\InMemoryEventStore;
18
use Cubiche\Domain\EventSourcing\Tests\Fixtures\PostEventSourced;
19
use Cubiche\Domain\EventSourcing\Tests\Fixtures\Projector\PublishedPostProjector;
20
use Cubiche\Domain\EventSourcing\Tests\Fixtures\ReadModel\PublishedPost;
21
use Cubiche\Domain\EventSourcing\Tests\Units\TestCase;
22
use Cubiche\Domain\Model\Tests\Fixtures\PostId;
23
use Cubiche\Domain\Repository\InMemory\InMemoryQueryRepository;
24
use Cubiche\Domain\Repository\QueryRepositoryInterface;
25
26
/**
27
 * ProjectorTests class.
28
 *
29
 * Generated by TestGenerator on 2016-06-28 at 14:36:54.
30
 */
31
class ProjectorTests extends TestCase
32
{
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function createProjector(QueryRepositoryInterface $repository)
37
    {
38
        return new PublishedPostProjector($repository);
39
    }
40
41
    /**
42
     * Test create.
43
     */
44
    public function testCreate()
45
    {
46
        $readModelRepository = new InMemoryQueryRepository(PublishedPost::class);
47
        $writeModelRepository = new AggregateRepository(new InMemoryEventStore(), PostEventSourced::class);
48
49
        $this
50
            ->given($projector = $this->createProjector($readModelRepository))
51
            ->and(DomainEventPublisher::subscribe($projector))
52
            ->and(
53
                $postId = PostId::fromNative(md5(rand())),
54
                $writeModel = new PostEventSourced(
55
                    $postId,
56
                    'The post title',
57
                    'The post description'
58
                )
59
            )
60
            ->then()
61
                ->boolean($readModelRepository->isEmpty())
62
                    ->isTrue()
63
                ->and()
64
                ->when($writeModelRepository->persist($writeModel))
65
                ->then()
66
                    ->boolean($readModelRepository->isEmpty())
67
                        ->isTrue()
68
                ->and()
69
                ->when($writeModel->publish())
70
                ->and($writeModelRepository->persist($writeModel))
71
                ->then()
72
                    ->boolean($readModelRepository->isEmpty())
73
                        ->isFalse()
74
                    ->object($readModel = $readModelRepository->findOne(Criteria::property('id')->eq($postId)))
75
                        ->isInstanceOf(PublishedPost::class)
76
                    ->string($readModel->title())
77
                        ->isEqualTo('The post title')
78
                ->and()
79
                ->when($writeModel->changeTitle('foo'))
80
                ->and($writeModelRepository->persist($writeModel))
81
                ->then()
82
                    ->object($readModel = $readModelRepository->findOne(Criteria::property('id')->eq($postId)))
83
                        ->isInstanceOf(PublishedPost::class)
84
                    ->string($readModel->title())
85
                        ->isEqualTo('foo')
86
                ->and()
87
                ->when($writeModel->unpublish())
88
                ->and($writeModelRepository->persist($writeModel))
89
                ->then()
90
                    ->boolean($readModelRepository->isEmpty())
91
                        ->isTrue()
92
        ;
93
    }
94
}
95