Completed
Pull Request — 1.5 (#758)
by Paweł
11:13
created

TemplatingContext::renderedTemplateShouldContain()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
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\PyStringNode;
9
10
final class TemplatingContext implements Context
11
{
12
    private $templating;
13
14
    /**
15
     * @var string
16
     */
17
    private $lastRenderedContent;
18
19
    public function __construct(\Twig_Environment $templating)
20
    {
21
        $this->templating = $templating;
22
    }
23
24
    /**
25
     * @Given I render a template with content:
26
     */
27
    public function iRenderATemplateWithContent(PyStringNode $templateContent): void
28
    {
29
        $template = $this->templating->createTemplate($templateContent->getRaw());
30
        $this->lastRenderedContent = $template->render([]);
31
    }
32
33
    /**
34
     * @Then rendered template should contain :searchString
35
     */
36
    public function renderedTemplateShouldContain(string $searchString): void
37
    {
38
        if (false === \strpos($this->lastRenderedContent, $searchString)) {
39
            throw new \Exception('Searched string was not found in rendered template.');
40
        }
41
    }
42
43
    /**
44
     * @Then rendered template should not contain :searchString
45
     */
46
    public function renderedTemplateShouldNotContain(string $searchString)
47
    {
48
        if (false !== \strpos($this->lastRenderedContent, $searchString)) {
49
            throw new \Exception('Searched string was found in rendered template (and was not expected).');
50
        }
51
    }
52
}
53