AdminContext   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 48
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntityManager() 0 3 1
A iAmOnTheDashboard() 0 3 1
A clearData() 0 3 1
A iHaveItemsInTheDatabase() 0 7 1
A iShouldSeeAButton() 0 3 1
A getPurger() 0 3 1
1
<?php
2
3
namespace KunicMarko\SonataAnnotationBundle\Features\Context;
4
5
use Behat\MinkExtension\Context\MinkContext;
6
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
7
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
8
use Doctrine\ORM\EntityManagerInterface;
9
use Behat\Symfony2Extension\Context\KernelDictionary;
10
use KunicMarko\SonataAnnotationBundle\Features\Fixtures\CategoryFixtures;
11
use Doctrine\Common\DataFixtures\Loader;
12
13
class AdminContext extends MinkContext
14
{
15
    use KernelDictionary;
16
17
    /**
18
     * @BeforeScenario
19
     */
20
    public function clearData()
21
    {
22
        $this->getPurger()->purge();
23
    }
24
25
    private function getPurger()
26
    {
27
        return new ORMPurger($this->getEntityManager());
28
    }
29
30
    private function getEntityManager(): EntityManagerInterface
31
    {
32
        return $this->getContainer()->get('doctrine.orm.entity_manager');
33
    }
34
35
    /**
36
     * @Given I am on the dashboard
37
     */
38
    public function iAmOnTheDashboard()
39
    {
40
        $this->visitPath('/admin/dashboard');
41
    }
42
43
    /**
44
     * @Given I have items in the database
45
     */
46
    public function iHaveItemsInTheDatabase()
47
    {
48
        $loader = new Loader();
49
        $loader->addFixture(new CategoryFixtures());
50
51
        $executor = new ORMExecutor($this->getEntityManager(), $this->getPurger());
52
        $executor->execute($loader->getFixtures());
53
    }
54
55
    /**
56
     * @Then I should see :button button
57
     */
58
    public function iShouldSeeAButton($button)
59
    {
60
        $this->getSession()->getPage()->find('xpath', "//a[contains(text(), $button)]");
61
    }
62
}
63