Completed
Push — master ( b70f30...259e2d )
by Kamil
32:06
created

CouponContextSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 32
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_context_interface() 0 4 1
A it_gets_coupon_by_its_code() 0 7 1
A it_throws_exception_when_coupon_with_given_code_was_not_found() 0 6 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\Transform;
13
14
use Behat\Behat\Context\Context;
15
use PhpSpec\ObjectBehavior;
16
use Prophecy\Argument;
17
use Sylius\Behat\Context\Transform\CouponContext;
18
use Sylius\Component\Promotion\Model\CouponInterface;
19
use Sylius\Component\Resource\Repository\RepositoryInterface;
20
21
/**
22
 * @mixin CouponContext
23
 *
24
 * @author Jan Góralski <[email protected]>
25
 */
26
class CouponContextSpec extends ObjectBehavior
27
{
28
    function let(RepositoryInterface $couponRepository)
29
    {
30
        $this->beConstructedWith($couponRepository);
31
    }
32
33
    function it_is_initializable()
34
    {
35
        $this->shouldHaveType('Sylius\Behat\Context\Transform\CouponContext');
36
    }
37
38
    function it_implements_context_interface()
39
    {
40
        $this->shouldImplement(Context::class);
41
    }
42
43
    function it_gets_coupon_by_its_code(RepositoryInterface $couponRepository, CouponInterface $coupon)
44
    {
45
        $coupon->getCode()->willReturn('BEST-CODE');
46
        $couponRepository->findOneBy(['code' => 'BEST-CODE'])->willReturn($coupon);
47
48
        $this->getCouponByCode('BEST-CODE');
49
    }
50
51
    function it_throws_exception_when_coupon_with_given_code_was_not_found(RepositoryInterface $couponRepository)
52
    {
53
        $couponRepository->findOneBy(['code' => 'NO-CODE'])->willReturn(null);
54
55
        $this->shouldThrow(\InvalidArgumentException::class)->during('getCouponByCode', ['NO-CODE']);
56
    }
57
}
58