Completed
Push — master ( e6fe6f...a29d2d )
by Hannes
09:33
created

IdProcessorSpec::it_creates_valid_personal_ids()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace spec\byrokrat\autogiro\Processor;
6
7
use byrokrat\autogiro\Processor\IdProcessor;
8
use byrokrat\autogiro\Tree\OrganizationIdNode;
9
use byrokrat\autogiro\Tree\PersonalIdNode;
10
use byrokrat\id\OrganizationIdFactory;
11
use byrokrat\id\PersonalIdFactory;
12
use byrokrat\id\Id;
13
use byrokrat\id\Exception\RuntimeException as IdException;
14
use PhpSpec\ObjectBehavior;
15
16
class IdProcessorSpec extends ObjectBehavior
17
{
18
    function let(
19
        OrganizationIdFactory $organizationIdFactory,
20
        PersonalIdFactory $personalIdFactory,
21
        OrganizationIdNode $organizationIdNode,
22
        PersonalIdNode $personalIdNode,
23
        Id $id
24
    ) {
25
        $organizationIdFactory->create('not-valid')->willThrow(IdException::CLASS);
0 ignored issues
show
Bug introduced by
The method willThrow() does not seem to exist on object<byrokrat\id\Id>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
        $organizationIdFactory->create('valid')->willReturn($id);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<byrokrat\id\Id>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
28
        $personalIdFactory->create('not-valid')->willThrow(IdException::CLASS);
0 ignored issues
show
Bug introduced by
The method willThrow() does not seem to exist on object<byrokrat\id\Id>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
        $personalIdFactory->create('valid')->willReturn($id);
0 ignored issues
show
Bug introduced by
The method willReturn() does not seem to exist on object<byrokrat\id\Id>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
31
        $organizationIdNode->getLineNr()->willReturn(1);
32
        $personalIdNode->getLineNr()->willReturn(1);
33
34
        $this->beConstructedWith($organizationIdFactory, $personalIdFactory);
35
    }
36
37
    function it_is_initializable()
38
    {
39
        $this->shouldHaveType(IdProcessor::CLASS);
40
    }
41
42
    function it_fails_on_unvalid_organizational_id(OrganizationIdNode $organizationIdNode)
43
    {
44
        $organizationIdNode->getValue()->willReturn('not-valid');
45
        $this->visitOrganizationIdNode($organizationIdNode);
46
        $this->getErrors()->shouldHaveCount(1);
47
    }
48
49
    function it_creates_valid_organizational_ids(OrganizationIdNode $organizationIdNode, Id $id)
50
    {
51
        $organizationIdNode->getValue()->willReturn('valid');
52
        $organizationIdNode->setAttribute('id', $id)->shouldBeCalled();
53
        $this->visitOrganizationIdNode($organizationIdNode);
54
        $this->getErrors()->shouldHaveCount(0);
55
    }
56
57
    function it_fails_on_unvalid_personal_id(PersonalIdNode $personalIdNode)
58
    {
59
        $personalIdNode->getValue()->willReturn('not-valid');
60
        $this->visitPersonalIdNode($personalIdNode);
61
        $this->getErrors()->shouldHaveCount(1);
62
    }
63
64
    function it_creates_valid_personal_ids(PersonalIdNode $personalIdNode, Id $id)
65
    {
66
        $personalIdNode->getValue()->willReturn('valid');
67
        $personalIdNode->setAttribute('id', $id)->shouldBeCalled();
68
        $this->visitPersonalIdNode($personalIdNode);
69
        $this->getErrors()->shouldHaveCount(0);
70
    }
71
}
72