Completed
Push — master ( 22512f...2e0539 )
by Kamil
24:53
created

ProductContext::storeHasAProductPricedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 3
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 Sylius\Behat\Context\Setup;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
16
use Sylius\Component\Resource\Factory\FactoryInterface;
17
use Sylius\Component\Resource\Repository\RepositoryInterface;
18
19
/**
20
 * @author Arkadiusz Krakowiak <[email protected]>
21
 */
22
class ProductContext implements Context
23
{
24
    /**
25
     * @var RepositoryInterface
26
     */
27
    private $productRepository;
28
29
    /**
30
     * @var SharedStorageInterface
31
     */
32
    private $sharedStorage;
33
34
    /**
35
     * @var FactoryInterface
36
     */
37
    private $productFactory;
38
39
    /**
40
     * @param RepositoryInterface $productRepository
41
     * @param SharedStorageInterface $sharedStorage
42
     * @param FactoryInterface $productFactory
43
     */
44
    public function __construct(RepositoryInterface $productRepository, SharedStorageInterface $sharedStorage, FactoryInterface $productFactory)
45
    {
46
        $this->productRepository = $productRepository;
47
        $this->sharedStorage = $sharedStorage;
48
        $this->productFactory = $productFactory;
49
    }
50
51
    /**
52
     * @Given /^store has a product "([^"]*)" priced at "(€|£|\$)([^"]*)"$/
53
     */
54
    public function storeHasAProductPricedAt($productName, $currency, $price)
55
    {
56
        $product = $this->productFactory->createNew();
57
        $product->setName($productName);
58
        $product->setPrice((int) $price * 100);
59
        $product->setDescription('Awesome star wars mug');
60
61
        $channel = $this->sharedStorage->getCurrentResource('channel');
62
        $product->addChannel($channel);
63
64
        $this->productRepository->add($product);
65
    }
66
}
67