Completed
Push — master ( c133b5...561394 )
by G
04:50
created

OrderDepositTaxesApplicatorSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 24
c 1
b 0
f 1
dl 0
loc 64
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 6 1
A it_is_initializable() 0 3 1
A it_apply_taxes() 0 44 1
A it_implements_order_processor_interface() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace spec\Gweb\SyliusProductDepositPlugin\Taxation;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Gweb\SyliusProductDepositPlugin\Entity\ChannelDepositInterface;
9
use Gweb\SyliusProductDepositPlugin\Entity\ProductVariantInterface;
10
use Gweb\SyliusProductDepositPlugin\Taxation\OrderDepositTaxesApplicator;
11
use PhpSpec\ObjectBehavior;
12
use Sylius\Component\Addressing\Model\ZoneInterface;
13
use Sylius\Component\Core\Model\AdjustmentInterface;
14
use Sylius\Component\Core\Model\ChannelInterface;
15
use Sylius\Component\Core\Model\OrderInterface;
16
use Sylius\Component\Core\Model\OrderItemInterface;
17
use Sylius\Component\Core\Model\OrderItemUnitInterface;
18
use Sylius\Component\Core\Model\TaxRateInterface;
19
use Sylius\Component\Core\Taxation\Applicator\OrderTaxesApplicatorInterface;
20
use Sylius\Component\Order\Factory\AdjustmentFactoryInterface;
21
use Sylius\Component\Resource\Repository\RepositoryInterface;
22
use Sylius\Component\Taxation\Calculator\CalculatorInterface;
23
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
24
25
final class OrderDepositTaxesApplicatorSpec extends ObjectBehavior
26
{
27
    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...
28
        CalculatorInterface $calculator,
29
        AdjustmentFactoryInterface $adjustmentFactory,
30
        RepositoryInterface $taxRateRepository
31
    ) {
32
        $this->beConstructedWith($calculator, $adjustmentFactory, $taxRateRepository);
33
    }
34
35
    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...
36
    {
37
        $this->shouldHaveType(OrderDepositTaxesApplicator::class);
38
    }
39
40
    function it_implements_order_processor_interface(): void
41
    {
42
        $this->shouldImplement(OrderTaxesApplicatorInterface::class);
43
    }
44
45
    function it_apply_taxes(
46
        AdjustmentFactoryInterface $adjustmentFactory,
47
        AdjustmentInterface $adjustment,
48
        CalculatorInterface $calculator,
49
        ChannelInterface $channel,
50
        ChannelDepositInterface $channelDeposit,
51
        OrderInterface $order,
52
        OrderItemInterface $orderItem,
53
        OrderItemUnitInterface $orderItemUnit,
54
        ProductVariantInterface $productVariant,
55
        RepositoryInterface $taxRateRepository,
56
        TaxCategoryInterface $taxCategory,
57
        TaxRateInterface $taxRate,
58
        ZoneInterface $zone
59
    ): void {
60
        $adjustmentFactory->createWithData(
61
            AdjustmentInterface::TAX_ADJUSTMENT,
62
            'Returnable tax (exclude)',
63
            15,
64
            false
65
        )->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

65
        )->/** @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...
66
67
        $taxRate->getLabel()->willReturn('Returnable tax (exclude)');
68
        $taxRate->isIncludedInPrice()->willReturn(false);
69
70
        $calculator->calculate(100, $taxRate)->willReturn(15);
71
        $taxRateRepository->findOneBy(['category' => $taxCategory, 'zone' => $zone])->willReturn($taxRate);
72
        $this->beConstructedWith($calculator, $adjustmentFactory, $taxRateRepository);
73
74
        $channelDeposit->getPrice()->willReturn(100);
75
76
        $productVariant->getChannelDepositForChannel($channel)->willReturn($channelDeposit);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Gweb\SyliusProductDeposi...ChannelDepositInterface. ( Ignorable by Annotation )

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

76
        $productVariant->getChannelDepositForChannel($channel)->/** @scrutinizer ignore-call */ willReturn($channelDeposit);

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...
77
        $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

77
        $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...
78
79
        $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

79
        $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...
80
        $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

80
        $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

80
        $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...
81
82
        $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...
83
84
        $order->getChannel()->willReturn($channel);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on Sylius\Component\Channel\Model\ChannelInterface. ( Ignorable by Annotation )

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

84
        $order->getChannel()->/** @scrutinizer ignore-call */ willReturn($channel);

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...
85
        $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

85
        $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...
86
87
88
        $this->apply($order, $zone);
0 ignored issues
show
Bug introduced by
The method apply() does not exist on spec\Gweb\SyliusProductD...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

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