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

ProductVariantContextSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 39
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_converts_product_variant_and_product_names_into_product_object() 0 11 1
A it_throws_element_not_found_exception_if_product_variant_has_not_been_found() 0 10 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 Sylius\Component\Core\Model\ProductInterface;
17
use Sylius\Component\Core\Model\ProductVariantInterface;
18
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
19
use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface;
20
21
/**
22
 * @author Łukasz Chruściel <[email protected]>
23
 */
24
class ProductVariantContextSpec extends ObjectBehavior
25
{
26
    function let(ProductRepositoryInterface $productRepository, ProductVariantRepositoryInterface $productVariantRepository)
27
    {
28
        $this->beConstructedWith($productRepository, $productVariantRepository);
29
    }
30
    function it_is_initializable()
31
    {
32
        $this->shouldHaveType('Sylius\Behat\Context\Transform\ProductVariantContext');
33
    }
34
35
    function it_implements_context_interface()
36
    {
37
        $this->shouldImplement(Context::class);
38
    }
39
40
    function it_converts_product_variant_and_product_names_into_product_object(
41
        ProductRepositoryInterface $productRepository,
42
        ProductVariantRepositoryInterface $productVariantRepository,
43
        ProductInterface $product,
44
        ProductVariantInterface $productVariant
45
    ) {
46
        $productRepository->findOneByName('Mug')->willReturn($product);
47
        $productVariantRepository->findOneBy(['presentation' => 'Eagle Millenium Mug', 'object' => $product])->willReturn($productVariant);
48
49
        $this->getProductVariantByNameAndProduct('Eagle Millenium Mug', 'Mug')->shouldReturn($productVariant);
50
    }
51
52
    function it_throws_element_not_found_exception_if_product_variant_has_not_been_found (
53
        ProductRepositoryInterface $productRepository,
54
        ProductVariantRepositoryInterface $productVariantRepository,
55
        ProductInterface $product
56
    ) {
57
        $productRepository->findOneByName('T-Shirt')->willReturn($product);
58
        $productVariantRepository->findOneBy(['presentation' => 'Han Solo T-Shirt', 'object' => $product])->willReturn(null);
59
60
        $this->shouldThrow(\InvalidArgumentException::class)->during('getProductVariantByNameAndProduct', ['Han Solo T-Shirt', 'T-Shirt']);
61
    }
62
}
63