Passed
Push — trunk ( 26fc38...0b2f4f )
by Christian
13:44 queued 13s
created

OrderTransactionBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A amount() 0 5 1
A addCapture() 0 22 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Test\Integration\Builder\Order;
4
5
use Shopware\Core\Checkout\Cart\Price\Struct\CalculatedPrice;
6
use Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTaxCollection;
7
use Shopware\Core\Checkout\Cart\Tax\Struct\TaxRuleCollection;
8
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStates;
9
use Shopware\Core\Checkout\Order\Aggregate\OrderTransactionCapture\OrderTransactionCaptureStates;
10
use Shopware\Core\Framework\Log\Package;
11
use Shopware\Core\Framework\Test\IdsCollection;
12
use Shopware\Core\Framework\Test\TestCaseBase\BasicTestDataBehaviour;
13
use Shopware\Core\Framework\Test\TestCaseBase\KernelTestBehaviour;
14
use Shopware\Core\Test\TestBuilderTrait;
15
16
/**
17
 * @final
18
 */
19
#[Package('customer-order')]
20
class OrderTransactionBuilder
21
{
22
    use BasicTestDataBehaviour;
23
    use KernelTestBehaviour;
24
    use TestBuilderTrait;
25
26
    protected string $id;
27
28
    protected string $orderId;
29
30
    protected string $paymentMethodId;
31
32
    protected CalculatedPrice $amount;
33
34
    protected string $stateId;
35
36
    /**
37
     * @var array<string, array<string, mixed>>
38
     */
39
    protected array $captures = [];
40
41
    public function __construct(
42
        IdsCollection $ids,
43
        string $key,
44
        string $orderNumber = '10000',
45
        float $amount = 420.69,
46
        string $state = OrderTransactionStates::STATE_OPEN
47
    ) {
48
        $this->id = $ids->get($key);
49
        $this->ids = $ids;
50
        $this->paymentMethodId = $this->getValidPaymentMethodId();
51
        $this->orderId = $ids->get($orderNumber);
52
        $this->stateId = $this->getStateMachineState(OrderTransactionStates::STATE_MACHINE, $state);
53
54
        $this->amount($amount);
55
    }
56
57
    public function amount(float $amount): self
58
    {
59
        $this->amount = new CalculatedPrice($amount, $amount, new CalculatedTaxCollection(), new TaxRuleCollection());
60
61
        return $this;
62
    }
63
64
    /**
65
     * @param array<string, mixed> $customParams
66
     */
67
    public function addCapture(string $key, array $customParams = []): self
68
    {
69
        $capture = \array_merge([
70
            'id' => $this->ids->get($key),
71
            'orderTransactionId' => $this->id,
72
            'stateId' => $this->getStateMachineState(
73
                OrderTransactionCaptureStates::STATE_MACHINE,
74
                OrderTransactionCaptureStates::STATE_PENDING
75
            ),
76
            'externalReference' => null,
77
            'totalAmount' => 420.69,
78
            'amount' => new CalculatedPrice(
79
                420.69,
80
                420.69,
81
                new CalculatedTaxCollection(),
82
                new TaxRuleCollection()
83
            ),
84
        ], $customParams);
85
86
        $this->captures[$this->ids->get($key)] = $capture;
87
88
        return $this;
89
    }
90
}
91