OrderDepositTaxesApplicatorSpec   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A it_apply_taxes() 0 47 1
A it_implements_order_processor_interface() 0 3 1
A let() 0 6 1
A it_is_initializable() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\Gewebe\SyliusProductDepositPlugin\Taxation;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Gewebe\SyliusProductDepositPlugin\Entity\ProductVariantInterface;
9
use Gewebe\SyliusProductDepositPlugin\Taxation\OrderDepositTaxesApplicator;
10
use PhpSpec\ObjectBehavior;
11
use Sylius\Component\Addressing\Model\ZoneInterface;
12
use Sylius\Component\Core\Model\AdjustmentInterface;
13
use Sylius\Component\Core\Model\OrderInterface;
14
use Sylius\Component\Core\Model\OrderItemInterface;
15
use Sylius\Component\Core\Model\OrderItemUnitInterface;
16
use Sylius\Component\Core\Model\TaxRateInterface;
17
use Sylius\Component\Core\Taxation\Applicator\OrderTaxesApplicatorInterface;
18
use Sylius\Component\Order\Factory\AdjustmentFactoryInterface;
19
use Sylius\Component\Resource\Repository\RepositoryInterface;
20
use Sylius\Component\Taxation\Calculator\CalculatorInterface;
21
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
22
23
final class OrderDepositTaxesApplicatorSpec extends ObjectBehavior
24
{
25
    function let(
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
26
        AdjustmentFactoryInterface $adjustmentFactory,
27
        CalculatorInterface $calculator,
28
        RepositoryInterface $taxRateRepository
29
    ) {
30
        $this->beConstructedWith($adjustmentFactory, $calculator, $taxRateRepository);
31
    }
32
33
    function it_is_initializable(): void
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34
    {
35
        $this->shouldHaveType(OrderDepositTaxesApplicator::class);
36
    }
37
38
    function it_implements_order_processor_interface(): void
39
    {
40
        $this->shouldImplement(OrderTaxesApplicatorInterface::class);
41
    }
42
43
    function it_apply_taxes(
44
        AdjustmentFactoryInterface $adjustmentFactory,
45
        AdjustmentInterface $adjustment,
46
        CalculatorInterface $calculator,
47
        OrderInterface $order,
48
        OrderItemInterface $orderItem,
49
        OrderItemUnitInterface $orderItemUnit,
50
        ProductVariantInterface $productVariant,
51
        RepositoryInterface $taxRateRepository,
52
        TaxCategoryInterface $taxCategory,
53
        TaxRateInterface $taxRate,
54
        ZoneInterface $zone
55
    ): void {
56
        $adjustmentFactory->createWithData(
57
            AdjustmentInterface::TAX_ADJUSTMENT,
58
            'Deposit Tax (3%)',
59
            15,
60
            false,
61
            [
62
                'taxRateCode' => 'deposit',
63
                'taxRateName' => 'Deposit Tax',
64
                'taxRateAmount' => 0.03,
65
            ]
66
        )->willReturn($adjustment);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Order\Model\AdjustmentInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        )->/** @scrutinizer ignore-call */ willReturn($adjustment);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
68
        $taxRate->getLabel()->willReturn('Deposit Tax (3%)');
69
        $taxRate->getName()->willReturn('Deposit Tax');
70
        $taxRate->getCode()->willReturn('deposit');
71
        $taxRate->getAmount()->willReturn(0.03);
72
        $taxRate->isIncludedInPrice()->willReturn(false);
73
74
        $calculator->calculate(100, $taxRate)->willReturn(15);
75
        $taxRateRepository->findOneBy(['category' => $taxCategory, 'zone' => $zone])->willReturn($taxRate);
76
        $this->beConstructedWith($adjustmentFactory, $calculator, $taxRateRepository);
77
78
        $productVariant->getDepositTaxCategory()->willReturn($taxCategory);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Taxatio...el\TaxCategoryInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
        $productVariant->getDepositTaxCategory()->/** @scrutinizer ignore-call */ willReturn($taxCategory);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
79
80
        $orderItem->getVariant()->willReturn($productVariant);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Core\Mo...ProductVariantInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

80
        $orderItem->getVariant()->/** @scrutinizer ignore-call */ willReturn($productVariant);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
81
        $orderItem->getUnits()->willReturn(new ArrayCollection([$orderItemUnit->getWrappedObject()]));
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Doctrine\Common\Collections\Collection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
        $orderItem->getUnits()->/** @scrutinizer ignore-call */ willReturn(new ArrayCollection([$orderItemUnit->getWrappedObject()]));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getWrappedObject() does not exist on Sylius\Component\Core\Model\OrderItemUnitInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
        $orderItem->getUnits()->willReturn(new ArrayCollection([$orderItemUnit->/** @scrutinizer ignore-call */ getWrappedObject()]));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
83
        $orderItemUnit->getAdjustmentsTotal('deposit')->willReturn(100);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on integer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
        $orderItemUnit->getAdjustmentsTotal('deposit')->/** @scrutinizer ignore-call */ willReturn(100);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
84
        $orderItemUnit->addAdjustment($adjustment)->shouldBeCalled();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $orderItemUnit->addAdjustment($adjustment) targeting Sylius\Component\Order\M...erface::addAdjustment() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
85
86
        $order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
0 ignored issues
show
Bug introduced by
The method getWrappedObject() does not exist on Sylius\Component\Core\Model\OrderItemInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
        $order->getItems()->willReturn(new ArrayCollection([$orderItem->/** @scrutinizer ignore-call */ getWrappedObject()]));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
88
89
        $this->apply($order, $zone);
0 ignored issues
show
Bug introduced by
The method apply() does not exist on spec\Gewebe\SyliusProduc...ositTaxesApplicatorSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

89
        $this->/** @scrutinizer ignore-call */ 
90
               apply($order, $zone);
Loading history...
90
    }
91
}
92