Completed
Push — scalar-types/fixtures ( 9e7ef5 )
by Kamil
33:42 queued 09:21
created

LazySuiteRegistrySpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_implements_suite_registry_interface() 0 4 1
A it_returns_a_constructed_suite() 0 9 1
A it_constructs_a_suite_only_once() 0 9 1
A it_returns_an_empty_suites_list_if_none_was_registered() 0 4 1
A it_throws_an_exception_if_trying_to_get_unexisting_suite() 0 4 1
1
<?php
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\Bundle\FixturesBundle\Suite;
15
16
use PhpSpec\ObjectBehavior;
17
use Prophecy\Argument;
18
use Sylius\Bundle\FixturesBundle\Suite\LazySuiteRegistry;
19
use Sylius\Bundle\FixturesBundle\Suite\SuiteFactoryInterface;
20
use Sylius\Bundle\FixturesBundle\Suite\SuiteInterface;
21
use Sylius\Bundle\FixturesBundle\Suite\SuiteNotFoundException;
22
use Sylius\Bundle\FixturesBundle\Suite\SuiteRegistryInterface;
23
24
/**
25
 * @author Kamil Kokot <[email protected]>
26
 */
27
final class LazySuiteRegistrySpec extends ObjectBehavior
28
{
29
    function let(SuiteFactoryInterface $suiteFactory): void
30
    {
31
        $this->beConstructedWith($suiteFactory);
32
    }
33
34
    function it_implements_suite_registry_interface(): void
35
    {
36
        $this->shouldImplement(SuiteRegistryInterface::class);
37
    }
38
39
    function it_returns_a_constructed_suite(SuiteFactoryInterface $suiteFactory, SuiteInterface $suite): void
40
    {
41
        $this->addSuite('suite_name', ['fixtures' => []]);
42
43
        $suiteFactory->createSuite('suite_name', ['fixtures' => []])->willReturn($suite);
44
45
        $this->getSuite('suite_name')->shouldReturn($suite);
46
        $this->getSuites()->shouldReturn(['suite_name' => $suite]);
47
    }
48
49
    function it_constructs_a_suite_only_once(SuiteFactoryInterface $suiteFactory, SuiteInterface $suite): void
50
    {
51
        $this->addSuite('suite_name', ['fixtures' => []]);
52
53
        $suiteFactory->createSuite('suite_name', ['fixtures' => []])->shouldBeCalledTimes(1)->willReturn($suite);
54
55
        $this->getSuite('suite_name')->shouldReturn($suite);
56
        $this->getSuite('suite_name')->shouldReturn($suite);
57
    }
58
59
    function it_returns_an_empty_suites_list_if_none_was_registered(): void
60
    {
61
        $this->getSuites()->shouldReturn([]);
62
    }
63
64
    function it_throws_an_exception_if_trying_to_get_unexisting_suite(): void
65
    {
66
        $this->shouldThrow(SuiteNotFoundException::class)->during('getSuite', ['the_river_snake_is_dangerous']);
67
    }
68
}
69