Completed
Push — master ( 1671b1...4e9462 )
by Kamil
23:39
created

ProductReviewContext   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 2 Features 1
Metric Value
wmc 2
c 2
b 2
f 1
lcom 1
cbo 3
dl 0
loc 47
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A productHasAReview() 0 11 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 Sylius\Behat\Context\Setup;
13
14
use Behat\Behat\Context\Context;
15
use Doctrine\Common\Persistence\ObjectManager;
16
use Sylius\Component\Core\Model\ProductInterface;
17
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
18
use Sylius\Component\Resource\Factory\FactoryInterface;
19
use Sylius\Component\Resource\Repository\RepositoryInterface;
20
21
/**
22
 * @author Magdalena Banasiak <[email protected]>
23
 */
24
final class ProductReviewContext implements Context
25
{
26
    /**
27
     * @var SharedStorageInterface
28
     */
29
    private $sharedStorage;
30
31
    /**
32
     * @var FactoryInterface
33
     */
34
    private $productReviewFactory;
35
36
    /**
37
     * @var RepositoryInterface
38
     */
39
    private $productReviewRepository;
40
41
    /**
42
     * @param SharedStorageInterface $sharedStorage
43
     * @param FactoryInterface $productReviewFactory
44
     * @param RepositoryInterface $productReviewRepository
45
     */
46
    public function __construct(
47
        SharedStorageInterface $sharedStorage,
48
        FactoryInterface $productReviewFactory,
49
        RepositoryInterface $productReviewRepository
50
    ) {
51
        $this->sharedStorage = $sharedStorage;
52
        $this->productReviewFactory = $productReviewFactory;
53
        $this->productReviewRepository = $productReviewRepository;
54
    }
55
56
    /**
57
     * @Given /^(this product) has one review$/
58
     */
59
    public function productHasAReview(ProductInterface $product)
60
    {
61
        $review = $this->productReviewFactory->createNew();
62
        $review->setTitle('title');
63
        $review->setRating(5);
64
        $review->setReviewSubject($product);
65
66
        $product->addReview($review);
67
68
        $this->productReviewRepository->add($review);
69
    }
70
}
71