Completed
Push — example/managing-articles ( b68239 )
by Loïc
02:46
created

ArticleContext::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
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 App\Behat\Context\Setup;
13
14
use App\Behat\Service\SharedStorageInterface;
15
use App\Entity\Article;
16
use App\Fixture\Factory\ExampleFactoryInterface;
17
use Behat\Behat\Context\Context;
18
use Sylius\Component\Resource\Repository\RepositoryInterface;
19
20
class ArticleContext implements Context
21
{
22
    /**
23
     * @var SharedStorageInterface
24
     */
25
    private $sharedStorage;
26
27
    /**
28
     * @var ExampleFactoryInterface
29
     */
30
    private $articleFactory;
31
32
    /**
33
     * @var RepositoryInterface
34
     */
35
    private $articleRepository;
36
37
    /**
38
     * @param SharedStorageInterface  $sharedStorage
39
     * @param ExampleFactoryInterface $articleFactory
40
     * @param RepositoryInterface     $articleRepository
41
     */
42
    public function __construct(
43
        SharedStorageInterface $sharedStorage,
44
        ExampleFactoryInterface $articleFactory,
45
        RepositoryInterface $articleRepository
46
    ) {
47
        $this->sharedStorage = $sharedStorage;
48
        $this->articleFactory = $articleFactory;
49
        $this->articleRepository = $articleRepository;
50
    }
51
52
    /**
53
     * @Given there is (also )an article titled :title
54
     */
55
    public function thereIsAnAdministratorIdentifiedBy(string $title): void
56
    {
57
        $this->createArticle(['title' => $title]);
58
    }
59
60
    /**
61
     * @param array $options
62
     */
63
    private function createArticle(array $options): void
64
    {
65
        /** @var Article $article */
66
        $article = $this->articleFactory->create($options);
67
        $this->articleRepository->add($article);
68
        $this->sharedStorage->set('article', $article);
69
    }
70
}
71