Completed
Push — checkout-optimisation ( 4a6bfb...756f29 )
by Kamil
18:24
created

ResourceUpdateHandlerSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 45
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_a_resource_update_handler_interface() 0 4 1
A it_uses_decorated_updater_to_handle_update() 0 10 1
A it_throws_a_race_condition_exception_if_catch_an_optimistic_lock_exception() 0 16 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
namespace spec\Sylius\Bundle\CoreBundle\Doctrine\ORM\Updater;
13
14
use Doctrine\Common\Persistence\ObjectManager;
15
use Doctrine\ORM\OptimisticLockException;
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Bundle\CoreBundle\Doctrine\ORM\Updater\ResourceUpdateHandler;
18
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
19
use Sylius\Bundle\ResourceBundle\Controller\ResourceUpdateHandlerInterface;
20
use Sylius\Component\Resource\Exception\RaceConditionException;
21
use Sylius\Component\Resource\Model\ResourceInterface;
22
23
/**
24
 * @author Grzegorz Sadowski <[email protected]>
25
 */
26
final class ResourceUpdateHandlerSpec extends ObjectBehavior
27
{
28
    function let(ResourceUpdateHandlerInterface $decoratedUpdater)
29
    {
30
        $this->beConstructedWith($decoratedUpdater);
31
    }
32
33
    function it_is_initializable()
34
    {
35
        $this->shouldHaveType(ResourceUpdateHandler::class);
36
    }
37
38
    function it_implements_a_resource_update_handler_interface()
39
    {
40
        $this->shouldImplement(ResourceUpdateHandlerInterface::class);
41
    }
42
43
    function it_uses_decorated_updater_to_handle_update(
44
        ResourceUpdateHandlerInterface $decoratedUpdater,
45
        ResourceInterface $resource,
46
        RequestConfiguration $configuration,
47
        ObjectManager $manager
48
    ) {
49
        $decoratedUpdater->handle($resource, $configuration, $manager);
50
51
        $this->handle($resource, $configuration, $manager);
52
    }
53
54
    function it_throws_a_race_condition_exception_if_catch_an_optimistic_lock_exception(
55
        ResourceUpdateHandlerInterface $decoratedUpdater,
56
        ResourceInterface $resource,
57
        RequestConfiguration $configuration,
58
        ObjectManager $manager
59
    ) {
60
        $decoratedUpdater
61
            ->handle($resource, $configuration, $manager)
62
            ->willThrow(OptimisticLockException::class)
63
        ;
64
65
        $this
66
            ->shouldThrow(RaceConditionException::class)
67
            ->during('handle', [$resource, $configuration, $manager])
68
        ;
69
    }
70
}
71