-
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathOrderPlacedProducerSpec.php
More file actions
82 lines (65 loc) · 2.73 KB
/
OrderPlacedProducerSpec.php
File metadata and controls
82 lines (65 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace spec\Sylius\InvoicingPlugin\EventProducer;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Persistence\ObjectManager;
use Mockery;
use Mockery\MockInterface;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\OrderCheckoutStates;
use Sylius\InvoicingPlugin\DateTimeProvider;
use Sylius\InvoicingPlugin\Event\OrderPlaced;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;
final class OrderPlacedProducerSpec extends ObjectBehavior
{
function let(MessageBusInterface $eventBus, DateTimeProvider $dateTimeProvider): void
{
$this->beConstructedWith($eventBus, $dateTimeProvider);
}
function it_dispatches_an_order_placed_event_for_persisted_order(
MessageBusInterface $eventBus,
DateTimeProvider $dateTimeProvider,
OrderInterface $order,
ObjectManager $objectManager
): void {
$dateTime = new \DateTime('2018-12-14');
$dateTimeProvider->__invoke()->willReturn($dateTime);
$order->getNumber()->willReturn('000666');
$order->getCheckoutState()->willReturn(OrderCheckoutStates::STATE_COMPLETED);
$orderPlacedEvent = new OrderPlaced('000666', $dateTime);
$eventBus->dispatch($orderPlacedEvent)->shouldBeCalled()->willReturn(new Envelope($orderPlacedEvent));
$this->__invoke($order);
}
function it_dispatches_an_order_placed_event_for_updated_order(
MessageBusInterface $eventBus,
DateTimeProvider $dateTimeProvider,
EntityManagerInterface $entityManager,
OrderInterface $order
): void {
$dateTime = new \DateTime('2018-12-14');
$dateTimeProvider->__invoke()->willReturn($dateTime);
/** @var UnitOfWork|MockInterface $unitOfWork */
$unitOfWork = Mockery::mock(UnitOfWork::class);
$unitOfWork->shouldReceive('getEntityChangeSet')->withArgs([$order->getWrappedObject()])->andReturn([
'checkoutState' => [OrderCheckoutStates::STATE_CART, OrderCheckoutStates::STATE_COMPLETED],
]);
$entityManager->getUnitOfWork()->willReturn($unitOfWork);
$order->getNumber()->willReturn('000666');
$orderPlacedEvent = new OrderPlaced('000666', $dateTime);
$eventBus->dispatch($orderPlacedEvent)->shouldBeCalled()->willReturn(new Envelope($orderPlacedEvent));
$this->__invoke($order);
}
}