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

CouponContextSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
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\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