Completed
Push — master ( 4f4b30...79d213 )
by Kamil
49:20 queued 33s
created

PaymentContextSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
c 2
b 1
f 0
lcom 0
cbo 3
dl 0
loc 38
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 8 1
A it_is_initializable() 0 4 1
A it_implements_context_interface() 0 4 1
A it_converts_payment_method_name_into_payment_method_object() 0 8 1
A it_throws_element_not_found_exception_if_payment_method_has_not_been_found() 0 7 1
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\Behat\Context\Setup;
13
14
use Behat\Behat\Context\Context;
15
use PhpSpec\ObjectBehavior;
16
use Prophecy\Argument;
17
use Sylius\Bundle\CoreBundle\Test\Services\PaymentMethodNameToGatewayConverterInterface;
18
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
19
use Sylius\Component\Payment\Model\PaymentMethod;
20
use Sylius\Component\Resource\Factory\FactoryInterface;
21
use Sylius\Component\Resource\Repository\RepositoryInterface;
22
23
/**
24
 * @author Łukasz Chruściel <[email protected]>
25
 */
26
class PaymentContextSpec extends ObjectBehavior
27
{
28
    function let(
29
        RepositoryInterface $paymentMethodRepository,
30
        SharedStorageInterface $sharedStorage,
31
        FactoryInterface $paymentMethodFactory,
32
        PaymentMethodNameToGatewayConverterInterface $paymentMethodNameToGatewayConverter
33
    ) {
34
        $this->beConstructedWith($paymentMethodRepository, $sharedStorage, $paymentMethodFactory, $paymentMethodNameToGatewayConverter);
35
    }
36
37
    function it_is_initializable()
38
    {
39
        $this->shouldHaveType('Sylius\Behat\Context\Setup\PaymentContext');
40
    }
41
42
    function it_implements_context_interface()
43
    {
44
        $this->shouldImplement(Context::class);
45
    }
46
47
    function it_converts_payment_method_name_into_payment_method_object(
48
        RepositoryInterface $paymentMethodRepository,
49
        PaymentMethod $paymentMethod
50
    ) {
51
        $paymentMethodRepository->findOneBy(['name' => 'Offline'])->willReturn($paymentMethod);
52
53
        $this->getPaymentMethodByName('Offline')->shouldReturn($paymentMethod);
54
    }
55
56
    function it_throws_element_not_found_exception_if_payment_method_has_not_been_found (
57
        RepositoryInterface $paymentMethodRepository
58
    ) {
59
        $paymentMethodRepository->findOneBy(['name' => 'Free'])->willReturn(null);
60
61
        $this->shouldThrow(\InvalidArgumentException::class)->during('getPaymentMethodByName', ['Free']);
62
    }
63
}
64