Completed
Push — master ( 4f4b30...79d213 )
by Kamil
49:20 queued 33s
created

OrderContext::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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 Sylius\Behat\Context\Domain;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Component\Core\Model\OrderInterface;
16
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
17
18
/**
19
 * @author Łukasz Chruściel <[email protected]>
20
 */
21
final class OrderContext implements Context
22
{
23
    /**
24
     * @var OrderRepositoryInterface
25
     */
26
    private $orderRepository;
27
28
    /**
29
     * @param OrderRepositoryInterface $orderRepository
30
     */
31
    public function __construct(OrderRepositoryInterface $orderRepository)
32
    {
33
        $this->orderRepository = $orderRepository;
34
    }
35
36
    /**
37
     * @When I delete the order :orderNumber
38
     */
39
    public function iDeleteTheOrder($orderNumber)
40
    {
41
        /** @var OrderInterface $order */
42
        $order = $this->orderRepository->findOneBy(['number' => $orderNumber]);
43
        if (null === $order) {
44
            throw new \InvalidArgumentException(sprintf('Order with %s number was not found in an order repository', $orderNumber));
45
        }
46
47
        $this->orderRepository->remove($order);
48
    }
49
50
    /**
51
     * @Then /^([^"]+) should not exist in the registry$/
52
     */
53
    public function orderShouldNotExistInTheRegistry(OrderInterface $order)
54
    {
55
        /** @var OrderInterface $order */
56
        $order = $this->orderRepository->find($order->getId());
57
58
        expect($order)->toBe(null);
59
    }
60
}
61