Completed
Push — master ( d01ad3...6b97e6 )
by Paweł
21s queued 10s
created

SlideshowContext::theFollowingContentLists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SWP\Behat\Contexts;
6
7
use Behat\Behat\Context\Context;
8
use Behat\Gherkin\Node\TableNode;
9
use Doctrine\ORM\EntityManagerInterface;
10
use SWP\Bundle\CoreBundle\Repository\ArticleRepositoryInterface;
11
use SWP\Component\Storage\Factory\FactoryInterface;
12
13 View Code Duplication
final class SlideshowContext extends AbstractContext implements Context
14
{
15
    private $slideshowFactory;
16
17
    private $entityManager;
18
19
    private $articleRepository;
20
21
    public function __construct(
22
        FactoryInterface $slideshowFactory,
23
        EntityManagerInterface $entityManager,
24
        ArticleRepositoryInterface $articleRepository
25
    ) {
26
        $this->slideshowFactory = $slideshowFactory;
27
        $this->entityManager = $entityManager;
28
        $this->articleRepository = $articleRepository;
29
    }
30
31
    /**
32
     * @Given the following Slideshows:
33
     */
34
    public function theFollowingContentLists(TableNode $table)
35
    {
36
        foreach ($table as $row => $columns) {
37
            $slideshow = $this->slideshowFactory->create();
38
39
            $columns['article'] = $this->articleRepository->findOneBy(['title' => $columns['article']]);
40
41
            $this->fillObject($slideshow, $columns);
42
            $this->entityManager->persist($slideshow);
43
        }
44
45
        $this->entityManager->flush();
46
    }
47
}
48