Completed
Pull Request — master (#52)
by Wilmer
01:35
created

ContentDecoratorTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
eloc 25
c 2
b 0
f 0
dl 0
loc 41
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testShouldTriggerInitEvent() 0 36 1
1
<?php
2
3
namespace Yiisoft\Widget\Tests;
4
5
use Yiisoft\Tests\TestCase;
6
use Yiisoft\Widget\ContentDecorator;
7
use Yiisoft\Widget\Event\BeforeRun;
8
9
/**
10
 * @group widgets
11
 */
12
class ContentDecoratorTest extends TestCase
13
{
14
    /**
15
     * @see https://github.com/yiisoft/yii2/issues/15536
16
     */
17
    public function testShouldTriggerInitEvent()
18
    {
19
        $initTriggered = false;
20
21
        // adding some listeners
22
        $this->listenerProvider->attach(function (BeforeRun $event) use (&$initTriggered) {
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

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

22
        $this->listenerProvider->attach(function (/** @scrutinizer ignore-unused */ BeforeRun $event) use (&$initTriggered) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
            $initTriggered = true;
24
        });
25
26
        ob_start();
27
        ob_implicit_flush(0);
28
29
        ContentDecorator::begin()
30
            ->viewFile($this->aliases->get('@view/layout.php'))
0 ignored issues
show
Bug introduced by
It seems like $this->aliases->get('@view/layout.php') can also be of type boolean; however, parameter $value of Yiisoft\Widget\ContentDecorator::viewFile() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

30
            ->viewFile(/** @scrutinizer ignore-type */ $this->aliases->get('@view/layout.php'))
Loading history...
31
            ->params([])
32
            ->init();
33
34
        echo "\t\t<div class='left-column'>\n";
35
        echo "\t\t\t<p>This is a left bar!</p>\n";
36
        echo "\t\t</div>\n\n";
37
        echo "\t\t<div class='right-column'>\n";
38
        echo "\t\t\t<p>This is a right bar!</p>\n";
39
        echo "\t\t</div>\n";
40
41
        ContentDecorator::end();
42
43
        $this->assertTrue($initTriggered);
44
45
        $expected = "\t\t<div class='left-column'>\n" .
46
                    "\t\t\t<p>This is a left bar!</p>\n" .
47
                    "\t\t</div>\n\n" .
48
                    "\t\t<div class='right-column'>\n" .
49
                    "\t\t\t<p>This is a right bar!</p>\n" .
50
                    "\t\t</div>\n";
51
52
        $this->assertStringContainsString($expected, ob_get_clean());
53
    }
54
}
55