getLifecycleEventArgs()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Loevgaard\DandomainStockBundle\Tests\EventListener;
6
7
use Doctrine\ORM\Event\LifecycleEventArgs;
8
use Doctrine\ORM\Events;
9
use Loevgaard\DandomainFoundation\Entity\Generated\OrderInterface;
10
use Loevgaard\DandomainFoundation\Entity\Generated\ProductInterface;
11
use Loevgaard\DandomainFoundation\Entity\Order;
12
use Loevgaard\DandomainFoundation\Entity\OrderLine;
13
use Loevgaard\DandomainFoundation\Entity\State;
14
use Loevgaard\DandomainStock\Exception\CurrencyMismatchException;
15
use Loevgaard\DandomainStock\Exception\StockMovementProductMismatchException;
16
use Loevgaard\DandomainStock\Exception\UndefinedPriceForCurrencyException;
17
use Loevgaard\DandomainStock\Exception\UnsetCurrencyException;
18
use Loevgaard\DandomainStock\Exception\UnsetProductException;
19
use Loevgaard\DandomainStockBundle\EventListener\StockMovementSubscriber;
20
use PHPUnit\Framework\TestCase;
21
22
final class StockMovementSubscriberTest extends TestCase
23
{
24
    public function testEventsAndCorrespondingMethods()
25
    {
26
        $subscriber = new StockMovementSubscriber([]);
27
28
        $events = [
29
            Events::onFlush,
30
        ];
31
32
        $this->assertEquals($events, $subscriber->getSubscribedEvents());
33
34
        $refl = new \ReflectionClass(StockMovementSubscriber::class);
35
36
        foreach ($events as $event) {
37
            $this->assertTrue($refl->hasMethod($event));
38
        }
39
    }
40
41
    /**
42
     * @param object $object
43
     *
44
     * @return \PHPUnit\Framework\MockObject\MockObject|LifecycleEventArgs
45
     */
46
    private function getLifecycleEventArgs($object)
47
    {
48
        $lifecycleEventArgs = $this->getMockBuilder(LifecycleEventArgs::class)->disableOriginalConstructor()->getMock();
49
        $lifecycleEventArgs->method('getObject')->willReturn($object);
50
51
        return $lifecycleEventArgs;
52
    }
53
54
    private function getOrder(int $orderStateId = 1, $orderLineQuantity = 1, ProductInterface $product = null): OrderInterface
55
    {
56
        $order = new Order();
57
        $order->setCreatedDate(new \DateTimeImmutable());
58
59
        // set state
60
        $state = new State();
61
        $state->setExternalId($orderStateId);
62
        $order->setState($state);
63
64
        // add order line
65
        $orderLine = new OrderLine();
66
        $orderLine->setQuantity($orderLineQuantity);
67
        if ($product) {
68
            $orderLine->setProduct($product);
69
        }
70
        $order->addOrderLine($orderLine);
71
72
        return $order;
73
    }
74
}
75