Completed
Pull Request — demo (#202)
by Loïc
02:17
created

ArticleContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A thereIsAnAdministratorIdentifiedBy() 0 4 1
A createArticle() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of monofony.
5
 *
6
 * (c) Mobizel
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\Setup;
15
16
use App\Behat\Service\SharedStorageInterface;
17
use App\Entity\Article;
18
use App\Fixture\Factory\ArticleExampleFactory;
19
use Behat\Behat\Context\Context;
20
use Sylius\Component\Resource\Repository\RepositoryInterface;
21
22
final class ArticleContext implements Context
23
{
24
    /** @var SharedStorageInterface */
25
    private $sharedStorage;
26
27
    /** @var ArticleExampleFactory */
28
    private $articleFactory;
29
30
    /** @var RepositoryInterface */
31
    private $articleRepository;
32
33
    public function __construct(
34
        SharedStorageInterface $sharedStorage,
35
        ArticleExampleFactory $articleFactory,
36
        RepositoryInterface $articleRepository
37
    ) {
38
        $this->sharedStorage = $sharedStorage;
39
        $this->articleFactory = $articleFactory;
40
        $this->articleRepository = $articleRepository;
41
    }
42
43
    /**
44
     * @Given there is (also )an article titled :title
45
     */
46
    public function thereIsAnAdministratorIdentifiedBy(string $title): void
47
    {
48
        $this->createArticle(['title' => $title]);
49
    }
50
51
    /**
52
     * @param array $options
53
     */
54
    private function createArticle(array $options): void
55
    {
56
        /** @var Article $article */
57
        $article = $this->articleFactory->create($options);
58
        $this->articleRepository->add($article);
59
        $this->sharedStorage->set('article', $article);
60
    }
61
}
62