Completed
Pull Request — master (#52)
by Alexander
03:31
created

SpacelessTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testShouldTriggerBeforeRun() 0 13 1
A testWidget() 0 28 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Yiisoft\Widget\Tests;
5
6
use Yiisoft\Tests\TestCase;
7
use Yiisoft\Widget\Spaceless;
8
use Yiisoft\Widget\Event\BeforeRun;
9
10
/**
11
 * SpacelessTest.
12
 */
13
class SpacelessTest extends TestCase
14
{
15
    public function testWidget(): void
16
    {
17
        ob_start();
18
        ob_implicit_flush(0);
19
20
        echo "<body>\n";
21
22
        Spaceless::begin()->init();
23
        echo "\t<div class='wrapper'>\n";
24
25
        Spaceless::begin()->init();
26
        echo "\t\t<div class='left-column'>\n";
27
        echo "\t\t\t<p>This is a left bar!</p>\n";
28
        echo "\t\t</div>\n\n";
29
        echo "\t\t<div class='right-column'>\n";
30
        echo "\t\t\t<p>This is a right bar!</p>\n";
31
        echo "\t\t</div>\n";
32
        Spaceless::end();
33
34
        echo "\t</div>\n";
35
        Spaceless::end();
36
37
        echo "\t<p>Bye!</p>\n";
38
        echo "</body>\n";
39
40
        $expected = "<body>\n<div class='wrapper'><div class='left-column'><p>This is a left bar!</p>".
41
            "</div><div class='right-column'><p>This is a right bar!</p></div></div>\t<p>Bye!</p>\n</body>\n";
42
        $this->assertEquals($expected, ob_get_clean());
43
    }
44
45
    public function testShouldTriggerBeforeRun(): void
46
    {
47
        $initTriggered = false;
48
49
        // adding some listeners
50
        $this->listenerProvider->attach(static function (BeforeRun $event) use (&$initTriggered) {
0 ignored issues
show
Bug introduced by
The method attach() does not exist on Psr\EventDispatcher\ListenerProviderInterface. It seems like you code against a sub-type of Psr\EventDispatcher\ListenerProviderInterface such as Yiisoft\EventDispatcher\Provider\Aggregate or Yiisoft\EventDispatcher\Provider\Provider. ( Ignorable by Annotation )

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

50
        $this->listenerProvider->/** @scrutinizer ignore-call */ 
51
                                 attach(static function (BeforeRun $event) use (&$initTriggered) {
Loading history...
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

50
        $this->listenerProvider->attach(static 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...
51
            $initTriggered = true;
52
        });
53
54
        Spaceless::begin()->init();
55
        Spaceless::end();
56
57
        $this->assertTrue($initTriggered);
58
    }
59
}
60