Completed
Push — scalar-types/registry ( 38a5a0 )
by Kamil
75:54 queued 51:59
created

it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 29 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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
declare(strict_types=1);
13
14
namespace spec\Sylius\Component\Registry;
15
16
require_once __DIR__.'/Fixture/SampleServiceInterface.php';
17
18
use PhpSpec\ObjectBehavior;
19
use Prophecy\Argument;
20
use spec\Sylius\Component\Registry\Fixture\SampleServiceInterface;
21
use Sylius\Component\Registry\NonExistingServiceException;
22
use Sylius\Component\Registry\PrioritizedServiceRegistry;
23
use Sylius\Component\Registry\PrioritizedServiceRegistryInterface;
24
use Zend\Stdlib\PriorityQueue;
25
26
/**
27
 * @author Mark McKelvie <[email protected]>
28
 */
29
final class PrioritizedServiceRegistrySpec extends ObjectBehavior
30
{
31
    function let(): void
32
    {
33
        $this->beConstructedWith(SampleServiceInterface::class);
34
    }
35
36
    function it_implements_prioritized_service_registry_interface(): void
37
    {
38
        $this->shouldImplement(PrioritizedServiceRegistryInterface::class);
39
    }
40
41
    function it_initializes_services_priority_queue_by_default(): void
42
    {
43
        $this->all()->shouldReturnAnInstanceOf(PriorityQueue::class);
44
45
        $this->all()->shouldBeEmpty();
46
    }
47
48
    function it_registers_services_in_the_correct_prioritized_order(
49
        SampleServiceInterface $serviceOne,
50
        SampleServiceInterface $serviceTwo,
51
        SampleServiceInterface $serviceThree
52
    ): void {
53
        $this->has($serviceOne)->shouldReturn(false);
54
        $this->has($serviceTwo)->shouldReturn(false);
55
        $this->has($serviceThree)->shouldReturn(false);
56
57
        $this->register($serviceOne);
58
        $this->register($serviceTwo, -1);
59
        $this->register($serviceThree, 1);
60
61
        $this->has($serviceOne)->shouldReturn(true);
62
        $this->has($serviceTwo)->shouldReturn(true);
63
        $this->has($serviceThree)->shouldReturn(true);
64
65
        $this->all()->shouldHaveCount(3);
66
        $this->all()->shouldHavePriority(1);
67
        $this->all()->shouldHavePriority(0);
68
        $this->all()->shouldHavePriority(-1);
69
    }
70
71
    function it_throws_exception_when_trying_to_register_service_without_required_interface(\stdClass $service): void
72
    {
73
        $this
74
            ->shouldThrow(\InvalidArgumentException::class)
75
            ->duringRegister($service)
76
        ;
77
    }
78
79
    function it_throws_exception_when_trying_to_check_for_a_registered_service_without_required_interface(
80
        \stdClass $service
81
    ): void {
82
        $this
83
            ->shouldThrow(\InvalidArgumentException::class)
84
            ->duringHas($service)
85
        ;
86
    }
87
88
    function it_unregisters_service(SampleServiceInterface $service): void
89
    {
90
        $this->register($service);
91
        $this->has($service)->shouldReturn(true);
92
93
        $this->unregister($service);
94
        $this->has($service)->shouldReturn(false);
95
    }
96
97
    function it_throws_exception_if_trying_to_unregister_service_of_non_existing_type(SampleServiceInterface $service): void
98
    {
99
        $this
100
            ->shouldThrow(NonExistingServiceException::class)
101
            ->duringUnregister($service)
102
        ;
103
    }
104
}
105