Completed
Pull Request — master (#183)
by Beñat
04:47
created

AsyncEventSerializerSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 39
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 5 1
A it_serializes() 0 8 1
A it_does_not_serialize_when_event_is_not_instance_of_domain_event() 0 4 1
A it_deserializes() 0 5 1
A it_does_not_deserialize_when_name_or_occurred_on_or_values_do_not_exist() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Spec\Kreta\SharedKernel\Serialization;
14
15
use Kreta\SharedKernel\Domain\Model\Exception;
16
use Kreta\SharedKernel\Event\AsyncEvent;
17
use Kreta\SharedKernel\Serialization\AsyncEventSerializer;
18
use Kreta\SharedKernel\Serialization\InvalidSerializationObjectException;
19
use Kreta\SharedKernel\Serialization\Resolver;
20
use Kreta\SharedKernel\Serialization\Serializer;
21
use Kreta\SharedKernel\Tests\Double\Domain\Model\DomainEventStub;
22
use PhpSpec\ObjectBehavior;
23
24
class AsyncEventSerializerSpec extends ObjectBehavior
25
{
26
    function let(Resolver $resolver)
27
    {
28
        $this->beConstructedWith($resolver);
29
    }
30
31
    function it_is_initializable()
32
    {
33
        $this->shouldHaveType(AsyncEventSerializer::class);
34
        $this->shouldImplement(Serializer::class);
35
    }
36
37
    function it_serializes(Resolver $resolver)
38
    {
39
        $event = new DomainEventStub('foo', 'bar', new \DateTimeImmutable('2016-11-06 23:02:21'));
40
        $resolver->resolve(DomainEventStub::class)->shouldBeCalled()->willReturn('event-name');
41
        $this->serialize($event)->shouldReturn(
42
            '{"name":"event-name","occurredOn":"2016-11-06 23:02:21","values":{"bar":"bar","foo":"foo","occurredOn":"2016-11-06 23:02:21"}}'
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 140 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
43
        );
44
    }
45
46
    function it_does_not_serialize_when_event_is_not_instance_of_domain_event($notDomainEvent)
47
    {
48
        $this->shouldThrow(InvalidSerializationObjectException::class)->duringSerialize($notDomainEvent);
49
    }
50
51
    function it_deserializes()
52
    {
53
        $this->deserialize('{"name":"event-name","occurredOn":"2016-11-06 23:02:21","values":{"bar":"bar","foo":"foo","occurredOn":"2016-11-06 23:02:21"}}')
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 156 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
54
            ->shouldReturnAnInstanceOf(AsyncEvent::class);
55
    }
56
57
    function it_does_not_deserialize_when_name_or_occurred_on_or_values_do_not_exist()
58
    {
59
        $this->shouldThrow(Exception::class)
60
        ->duringDeserialize('{"name":"event-name","values":{"bar":"bar","foo":"foo","occurredOn":"2016-11-06 23:02:21"}}');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
61
    }
62
}
63