AddAttributesValidationTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 29
c 1
b 0
f 0
dl 0
loc 61
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testAfterValidate() 0 16 1
A setUp() 0 8 1
A testAfterValidateForCart() 0 15 1
1
<?php
2
3
namespace Hryvinskyi\QuoteAddressValidator\Test\Unit\Plugin;
4
5
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Hryvinskyi\QuoteAddressValidator\Plugin\AddAttributesValidation;
7
use Hryvinskyi\QuoteAddressValidator\Model\AddressValidationInterface;
8
use Hryvinskyi\QuoteAddressValidator\Model\ConfigInterface;
9
use Magento\Quote\Api\Data\AddressInterface;
10
use Magento\Quote\Api\Data\CartInterface;
11
use Magento\Quote\Model\QuoteAddressValidator;
12
13
class AddAttributesValidationTest extends TestCase
14
{
15
    /**
16
     * @var \PHPUnit\Framework\MockObject\MockObject|AddressValidationInterface
17
     */
18
    private $addressValidationMock;
19
20
    /**
21
     * @var \PHPUnit\Framework\MockObject\MockObject|ConfigInterface
22
     */
23
    private $configMock;
24
25
    /**
26
     * @var AddAttributesValidation
27
     */
28
    private $plugin;
29
30
    protected function setUp(): void
31
    {
32
        $this->addressValidationMock = $this->createMock(AddressValidationInterface::class);
33
        $this->configMock = $this->createMock(ConfigInterface::class);
34
35
        $this->plugin = new AddAttributesValidation(
36
            $this->addressValidationMock,
37
            $this->configMock
38
        );
39
    }
40
41
    public function testAfterValidateForCart()
42
    {
43
        $quoteAddressValidatorMock = $this->createMock(QuoteAddressValidator::class);
44
        $cartMock = $this->createMock(CartInterface::class);
45
        $addressMock = $this->createMock(AddressInterface::class);
46
47
        $this->configMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Hryvinskyi\QuoteAddressV...r\Model\ConfigInterface. ( Ignorable by Annotation )

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

47
        $this->configMock->/** @scrutinizer ignore-call */ 
48
                           expects($this->once())

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...
48
            ->method('isEnabled')
49
            ->willReturn(true);
50
51
        $this->addressValidationMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Hryvinskyi\QuoteAddressV...ressValidationInterface. ( Ignorable by Annotation )

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

51
        $this->addressValidationMock->/** @scrutinizer ignore-call */ 
52
                                      expects($this->once())

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...
52
            ->method('validate')
53
            ->with($addressMock);
54
55
        $this->plugin->afterValidateForCart($quoteAddressValidatorMock, null, $cartMock, $addressMock);
56
    }
57
58
    public function testAfterValidate()
59
    {
60
        $quoteAddressValidatorMock = $this->createMock(QuoteAddressValidator::class);
61
        $addressMock = $this->createMock(AddressInterface::class);
62
63
        $this->configMock->expects($this->once())
64
            ->method('isEnabled')
65
            ->willReturn(true);
66
67
        $this->addressValidationMock->expects($this->once())
68
            ->method('validate')
69
            ->with($addressMock);
70
71
        $result = $this->plugin->afterValidate($quoteAddressValidatorMock, true, $addressMock);
72
73
        $this->assertTrue($result);
74
    }
75
}
76