Completed
Push — master ( dc98b4...3f93b5 )
by Loïc
30s
created

getProductAssociationTypeByName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of Jedisjeux.
5
 *
6
 * (c) Loïc Frémont
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
declare(strict_types=1);
13
14
namespace App\Behat\Context\Transform;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Component\Product\Repository\ProductAssociationTypeRepositoryInterface;
18
use Webmozart\Assert\Assert;
19
20
final class ProductAssociationTypeContext implements Context
21
{
22
    /** @var ProductAssociationTypeRepositoryInterface */
23
    private $productAssociationTypeRepository;
24
25
    public function __construct(ProductAssociationTypeRepositoryInterface $productAssociationTypeRepository)
26
    {
27
        $this->productAssociationTypeRepository = $productAssociationTypeRepository;
28
    }
29
30
    /**
31
     * @Transform /^association "([^"]+)"$/
32
     * @Transform :productAssociationType
33
     */
34
    public function getProductAssociationTypeByName($productAssociationTypeName)
35
    {
36
        $productAssociationTypes = $this->productAssociationTypeRepository->findByName(
37
            $productAssociationTypeName,
38
            'en_US'
39
        );
40
41
        Assert::eq(
42
            count($productAssociationTypes),
43
            1,
44
            sprintf(
45
                '%d product association types has been found with name "%s".',
46
                count($productAssociationTypes),
47
                $productAssociationTypeName
48
            )
49
        );
50
51
        return $productAssociationTypes[0];
52
    }
53
}
54