OrderTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 39
dl 0
loc 73
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetFormattedBalance() 0 13 1
A providerGetFormattedBalance() 0 6 1
A testSetStatusWillNotGiveAccessIfStayingValidated() 0 14 1
A testSetStatusWillNotGiveAccessIfGoingBackToPending() 0 14 1
A testSetStatusWillGiveAccess() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Model;
6
7
use Application\Enum\OrderStatus;
8
use Application\Model\Order;
9
use Application\Model\OrderLine;
10
use Money\Money;
11
use PHPUnit\Framework\TestCase;
12
13
class OrderTest extends TestCase
14
{
15
    /**
16
     * @dataProvider providerGetFormattedBalance
17
     */
18
    public function testGetFormattedBalance(int $chf, int $eur, string $expected): void
19
    {
20
        $order = $this->getMockBuilder(Order::class)->onlyMethods(['getBalanceCHF', 'getBalanceEUR'])->getMock();
21
22
        $order->expects(self::any())
23
            ->method('getBalanceCHF')
24
            ->willReturn(Money::CHF($chf));
25
26
        $order->expects(self::any())
27
            ->method('getBalanceEUR')
28
            ->willReturn(Money::EUR($eur));
29
30
        self::assertSame($expected, $order->getFormattedBalance());
31
    }
32
33
    public static function providerGetFormattedBalance(): iterable
34
    {
35
        yield [0, 0, '0.00 CHF'];
36
        yield [150, 0, '1.50 CHF'];
37
        yield [0, 275, '2.75 EUR'];
38
        yield [150, 275, '2.75 EUR'];
39
    }
40
41
    public function testSetStatusWillGiveAccess(): void
42
    {
43
        $orderLine = $this->getMockBuilder(OrderLine::class)
44
            ->onlyMethods(['maybeGiveTemporaryAccess'])
45
            ->getMock();
46
47
        $orderLine->expects(self::once())
48
            ->method('maybeGiveTemporaryAccess');
49
50
        $order = new Order();
51
        $orderLine->setOrder($order);
52
53
        $order->setStatus(OrderStatus::Validated);
54
    }
55
56
    public function testSetStatusWillNotGiveAccessIfGoingBackToPending(): void
57
    {
58
        $orderLine = $this->getMockBuilder(OrderLine::class)
59
            ->onlyMethods(['maybeGiveTemporaryAccess'])
60
            ->getMock();
61
62
        $orderLine->expects(self::never())
63
            ->method('maybeGiveTemporaryAccess');
64
65
        $order = new Order();
66
        $order->setStatus(OrderStatus::Validated);
67
        $orderLine->setOrder($order);
68
69
        $order->setStatus(OrderStatus::Pending);
70
    }
71
72
    public function testSetStatusWillNotGiveAccessIfStayingValidated(): void
73
    {
74
        $orderLine = $this->getMockBuilder(OrderLine::class)
75
            ->onlyMethods(['maybeGiveTemporaryAccess'])
76
            ->getMock();
77
78
        $orderLine->expects(self::never())
79
            ->method('maybeGiveTemporaryAccess');
80
81
        $order = new Order();
82
        $order->setStatus(OrderStatus::Validated);
83
        $orderLine->setOrder($order);
84
85
        $order->setStatus(OrderStatus::Validated);
86
    }
87
}
88