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\Behat\Context\Domain; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Behat\Mink\Exception\ExpectationException; |
16
|
|
|
use Behat\Mink\Tests\Exception\ExpectationExceptionTest; |
17
|
|
|
use PhpSpec\Exception\Example\NotEqualException; |
18
|
|
|
use PhpSpec\ObjectBehavior; |
19
|
|
|
use Prophecy\Argument; |
20
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
21
|
|
|
use Sylius\Component\Core\Repository\OrderRepositoryInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Łukasz Chruściel <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class OrderContextSpec extends ObjectBehavior |
27
|
|
|
{ |
28
|
|
|
function let(OrderRepositoryInterface $orderRepository) |
29
|
|
|
{ |
30
|
|
|
$this->beConstructedWith($orderRepository); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_is_initializable() |
34
|
|
|
{ |
35
|
|
|
$this->shouldHaveType('Sylius\Behat\Context\Domain\OrderContext'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_implements_context_interface() |
39
|
|
|
{ |
40
|
|
|
$this->shouldImplement(Context::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_deletes_an_order(OrderRepositoryInterface $orderRepository, OrderInterface $order) |
44
|
|
|
{ |
45
|
|
|
$orderRepository->findOneBy(['number' => '#00000000'])->willReturn($order); |
46
|
|
|
|
47
|
|
|
$orderRepository->remove($order)->shouldBeCalled(); |
48
|
|
|
|
49
|
|
|
$this->iDeleteTheOrder('#00000000'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
function it_throws_an_exception_when_order_is_not_found(OrderRepositoryInterface $orderRepository) |
53
|
|
|
{ |
54
|
|
|
$orderRepository->findOneBy(['number' => '#00000000'])->willReturn(null); |
55
|
|
|
|
56
|
|
|
$this->shouldThrow(new \InvalidArgumentException('Order with #00000000 number was not found in an order repository'))->during('iDeleteTheOrder', ['#00000000']); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function it_checks_if_an_order_exists_in_repository(OrderRepositoryInterface $orderRepository, OrderInterface $order) |
60
|
|
|
{ |
61
|
|
|
$order->getId()->willReturn(1); |
62
|
|
|
$orderRepository->find(1)->willReturn(null); |
63
|
|
|
|
64
|
|
|
$this->orderShouldNotExistInTheRegistry($order); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
function it_throws_an_exception_if_order_still_exists(OrderRepositoryInterface $orderRepository, OrderInterface $order) |
68
|
|
|
{ |
69
|
|
|
$order->getId()->willReturn(1); |
70
|
|
|
$orderRepository->find(1)->willReturn($order); |
71
|
|
|
|
72
|
|
|
$this->shouldThrow(NotEqualException::class)->during('orderShouldNotExistInTheRegistry', [$order]); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|