Completed
Pull Request — 3.1 (#348)
by Piotr
20:24
created

ResourceContext   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 6
dl 0
loc 52
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setKernel() 0 4 1
A thereAreFollowingResourcesAddedToResourceMap() 0 12 3
A iFillFormFieldWith() 0 4 1
A iShouldSeeFormFieldWithValue() 0 4 1
A getResourceMapBuilder() 0 4 1
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminBundle\Behat\Context;
13
14
use Behat\Gherkin\Node\TableNode;
15
use Behat\Symfony2Extension\Context\KernelAwareContext;
16
use FSi\Bundle\ResourceRepositoryBundle\Repository\MapBuilder;
17
use SensioLabs\Behat\PageObjectExtension\Context\PageObjectContext;
18
use Symfony\Component\HttpKernel\KernelInterface;
19
20
class ResourceContext extends PageObjectContext implements KernelAwareContext
21
{
22
    /**
23
     * @var KernelInterface
24
     */
25
    protected $kernel;
26
27
    /**
28
     * @param KernelInterface $kernel
29
     */
30
    public function setKernel(KernelInterface $kernel): void
31
    {
32
        $this->kernel = $kernel;
33
    }
34
35
    /**
36
     * @Given /^there are following resources added to resource map$/
37
     */
38
    public function thereAreFollowingResourcesAddedToResourceMap(TableNode $resources)
39
    {
40
        foreach ($resources->getHash() as $resource) {
41
            expect($this->getResourceMapBuilder()->hasResource($resource['Key']))->toBe(true);
42
43
            if (isset($resource['Type'])) {
44
                expect($this->getResourceMapBuilder()->getResource($resource['Key']))->toBeAnInstanceOf(
0 ignored issues
show
Bug introduced by
The method toBeAnInstanceOf() does not exist on Bossa\PhpSpec\Expect\Subject. Did you maybe mean beAnInstanceOf()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
45
                    sprintf('FSi\Bundle\ResourceRepositoryBundle\Repository\Resource\Type\%sType', ucfirst($resource['Type']))
46
                );
47
            }
48
        }
49
    }
50
51
    /**
52
     * @Given /^I fill form "Content" field with "([^"]*)"$/
53
     */
54
    public function iFillFormFieldWith($value)
55
    {
56
        $this->getElement('Form')->fillField('Content', $value);
57
    }
58
59
    /**
60
     * @Given /^I should see form "Content" field with value "([^"]*)"$/
61
     */
62
    public function iShouldSeeFormFieldWithValue($value)
63
    {
64
        expect($this->getElement('Form')->findField('Content')->getValue())->toBe($value);
65
    }
66
67
    private function getResourceMapBuilder(): MapBuilder
68
    {
69
        return $this->kernel->getContainer()->get('test.fsi_resource_repository.map_builder');
70
    }
71
}
72