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

BlockTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testBlockRenderInPlaceTrue() 0 15 1
A testGetBlockException() 0 4 1
A testShouldTriggerInitEvent() 0 18 1
A testBlock() 0 11 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Yiisoft\Widget\Tests;
5
6
use Yiisoft\Tests\TestCase;
7
use Yiisoft\Widget\Block;
8
use Yiisoft\Widget\Event\BeforeRun;
9
10
/**
11
 * @group widgets
12
 */
13
class BlockTest extends TestCase
14
{
15
    public function testBlock(): void
16
    {
17
        Block::begin()
18
            ->id('testme')
19
            ->init();
20
21
        echo '<block-testme>';
22
23
        Block::end();
24
25
        $this->assertStringContainsString('<block-testme>', $this->webView->getBlock('testme'));
26
    }
27
28
    public function testBlockRenderInPlaceTrue(): void
29
    {
30
        ob_start();
31
        ob_implicit_flush(0);
32
33
        Block::begin()
34
            ->id('testme')
35
            ->renderInPlace(true)
36
            ->init();
37
38
        echo '<block-testme>';
39
40
        Block::end();
41
42
        $this->assertStringContainsString('<block-testme>', ob_get_clean());
43
    }
44
45
    public function testGetBlockException(): void
46
    {
47
        $this->expectException(\InvalidArgumentException::class);
48
        $this->webView->getBlock('notfound');
49
    }
50
51
    /**
52
     * @see https://github.com/yiisoft/yii2/issues/15536
53
     */
54
    public function testShouldTriggerInitEvent(): void
55
    {
56
        $initTriggered = false;
57
58
        // adding some listeners
59
        $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

59
        $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...
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

59
        $this->listenerProvider->/** @scrutinizer ignore-call */ 
60
                                 attach(function (BeforeRun $event) use (&$initTriggered) {
Loading history...
60
            $initTriggered = true;
61
        });
62
63
        ob_start();
64
        ob_implicit_flush(0);
65
66
        Block::begin()->init();
67
        Block::end();
68
69
        ob_get_clean();
70
71
        $this->assertTrue($initTriggered);
72
    }
73
}
74