Completed
Push — symfony3 ( 405d0c...88ded0 )
by Kamil
32:03 queued 12:32
created

PaymentMethodSpec::getMatchers()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace spec\Sylius\Component\Core\Model;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Core\Model\ChannelInterface;
18
use Sylius\Component\Core\Model\PaymentMethod;
19
use Sylius\Component\Core\Model\PaymentMethodInterface;
20
use Sylius\Component\Payment\Model\PaymentMethod as BasePaymentMethod;
21
22
/**
23
 * @author Mateusz Zalewski <[email protected]>
24
 */
25
final class PaymentMethodSpec extends ObjectBehavior
26
{
27
    function it_is_initializable()
28
    {
29
        $this->shouldHaveType(PaymentMethod::class);
30
    }
31
32
    function it_is_payment_method()
33
    {
34
        $this->shouldHaveType(BasePaymentMethod::class);
35
    }
36
37
    function it_implements_payment_method_interface()
38
    {
39
        $this->shouldImplement(PaymentMethodInterface::class);
40
    }
41
42
    function it_has_channels_collection(ChannelInterface $firstChannel, ChannelInterface $secondChannel)
43
    {
44
        $this->addChannel($firstChannel);
45
        $this->addChannel($secondChannel);
46
47
        $this->getChannels()->shouldBeSameAs(new ArrayCollection([$firstChannel, $secondChannel]));
48
    }
49
50
    function it_can_add_and_remove_channels(ChannelInterface $channel)
51
    {
52
        $this->addChannel($channel);
53
        $this->hasChannel($channel)->shouldReturn(true);
54
55
        $this->removeChannel($channel);
56
        $this->hasChannel($channel)->shouldReturn(false);
57
    }
58
59
    public function getMatchers()
60
    {
61
        return [
62
            'beSameAs' => function ($subject, $key) {
63
                if (!$subject instanceof Collection || !$key instanceof Collection) {
64
                    return false;
65
                }
66
67
                for ($i = 0; $i < $subject->count(); $i++) {
68
                    if ($subject->get($i) !== $key->get($i)->getWrappedObject()) {
69
                        return false;
70
                    }
71
                }
72
73
                return true;
74
            },
75
        ];
76
    }
77
}
78