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

WidgetTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testStackTrackingDisorder() 0 5 1
A testWidget() 0 5 1
A testStackTracking() 0 4 1
A testBeginEnd() 0 13 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Yiisoft\Widget\Tests;
5
6
use Psr\EventDispatcher\EventDispatcherInterface;
7
use Psr\EventDispatcher\ListenerProviderInterface;
8
use Yiisoft\Tests\TestCase;
9
use Yiisoft\Widget\Tests\Stubs\TestWidget;
10
use Yiisoft\Widget\Tests\Stubs\TestWidgetA;
11
use Yiisoft\Widget\Tests\Stubs\TestWidgetB;
12
use Yiisoft\Widget\Widget;
13
14
/**
15
 * WidgetTest.
16
 */
17
class WidgetTest extends TestCase
18
{
19
    /**
20
     * @var Widget $widget
21
     */
22
    protected $widget;
23
24
    public function testWidget()
25
    {
26
        $output = TestWidget::widget()->id('w0')->run();
27
28
        $this->assertSame('<run-w0>', $output);
29
    }
30
31
    public function testBeginEnd()
32
    {
33
        ob_start();
34
        ob_implicit_flush(0);
35
36
        $widget = TestWidgetA::begin()->id('test');
37
38
        $this->assertTrue($widget instanceof Widget);
39
40
        TestWidgetA::end();
41
        $output = ob_get_clean();
42
43
        $this->assertSame('<run-test>', $output);
44
    }
45
46
    /**
47
     * @depends testBeginEnd
48
     */
49
    public function testStackTracking()
50
    {
51
        $this->expectException('BadFunctionCallException');
52
        TestWidget::end();
53
    }
54
55
    /**
56
     * @depends testBeginEnd
57
     */
58
    public function testStackTrackingDisorder()
59
    {
60
        $this->expectException('BadFunctionCallException');
61
        TestWidgetA::begin();
62
        TestWidgetB::end();
63
    }
64
}
65