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
|
|
|
|