FeatureContext::documentNotContainsImageWithSrc()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Stfalcon\Bundle\SponsorBundle\Features\Context;
4
5
use Symfony\Component\HttpKernel\KernelInterface;
6
use Behat\Symfony2Extension\Context\KernelAwareInterface;
7
use Behat\MinkExtension\Context\MinkContext;
8
use Behat\CommonContexts\DoctrineFixturesContext;
9
use Doctrine\Common\DataFixtures\Loader;
10
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
11
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
12
use PHPUnit_Framework_Assert as Assert;
13
14
/**
15
 * Feature context for StfalconSponsorBundle.
16
 */
17
class FeatureContext extends MinkContext implements KernelAwareInterface
18
{
19
    /**
20
     * Constructor.
21
     */
22
    public function __construct()
23
    {
24
        $this->useContext('DoctrineFixturesContext', new DoctrineFixturesContext());
25
    }
26
27
    /**
28
     * @var \Symfony\Component\HttpKernel\KernelInterface
29
     */
30
    protected $kernel;
31
32
    /**
33
     * @param \Symfony\Component\HttpKernel\KernelInterface $kernel
34
     */
35
    public function setKernel(KernelInterface $kernel)
36
    {
37
        $this->kernel = $kernel;
38
    }
39
40
    /**
41
     * @BeforeScenario
42
     */
43
    public function beforeScen()
44
    {
45
        $loader = new Loader();
46
        $this->getMainContext()
47
            ->getSubcontext('DoctrineFixturesContext')
48
            ->loadFixtureClass($loader, 'Stfalcon\Bundle\SponsorBundle\DataFixtures\ORM\LoadEventSponsorData');
0 ignored issues
show
Bug introduced by
The method loadFixtureClass() does not exist on Behat\Behat\Context\ExtendedContextInterface. It seems like you code against a sub-type of Behat\Behat\Context\ExtendedContextInterface such as Behat\CommonContexts\Behat1BCContext or Behat\CommonContexts\DoctrineFixturesContext. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
            ->/** @scrutinizer ignore-call */ loadFixtureClass($loader, 'Stfalcon\Bundle\SponsorBundle\DataFixtures\ORM\LoadEventSponsorData');
Loading history...
49
50
        /** @var $em \Doctrine\ORM\EntityManager */
51
        $em = $this->kernel->getContainer()->get('doctrine.orm.entity_manager');
52
53
        $purger = new ORMPurger();
54
        $executor = new ORMExecutor($em, $purger);
55
        $executor->purge();
56
        $executor->execute($loader->getFixtures(), true);
57
    }
58
59
    /**
60
     * Check that some element contains image from some source.
61
     *
62
     * @param string $src     Source of image
63
     * @param string $element Selector engine name
64
     *
65
     * @Given /^я должен видеть картинку "([^"]*)" внутри элемента "([^"]*)"$/
66
     */
67
    public function elementContainsImageWithSrc($src, $element)
68
    {
69
        Assert::assertTrue($this->_findImageWithSrc($src, $element));
70
    }
71
72
    /**
73
     * Check that some element not contains image from some source.
74
     *
75
     * @param string $src     Source of image
76
     * @param string $element Selector engine name
77
     *
78
     * @Given /^я не должен видеть картинку "([^"]*)" внутри элемента "([^"]*)"$/
79
     */
80
    public function documentNotContainsImageWithSrc($src, $element)
81
    {
82
        Assert::assertTrue(!$this->_findImageWithSrc($src, $element));
83
    }
84
85
    private function _findImageWithSrc($src, $element)
86
    {
87
        $rawImages = $this->getSession()->getPage()->findAll('css', $element);
88
89
        foreach ($rawImages as $rawImage) {
90
            if (strstr($rawImage->getAttribute('src'), $src)) {
91
                return true;
92
            }
93
        }
94
95
        return false;
96
    }
97
}
98