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

WidgetTest::testWidget()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Yiisoft\Widget\Tests;
5
6
use Yiisoft\Tests\TestCase;
7
use Yiisoft\Widget\Tests\Stubs\TestWidget;
8
use Yiisoft\Widget\Tests\Stubs\TestWidgetA;
9
use Yiisoft\Widget\Tests\Stubs\TestWidgetB;
10
use Yiisoft\Widget\Widget;
11
12
/**
13
 * WidgetTest.
14
 */
15
class WidgetTest extends TestCase
16
{
17
    /**
18
     * @var Widget $widget
19
     */
20
    protected $widget;
21
22
    public function testWidget(): void
23
    {
24
        $output = TestWidget::widget()->id('w0')->run();
25
26
        $this->assertSame('<run-w0>', $output);
27
    }
28
29
    public function testBeginEnd(): void
30
    {
31
        ob_start();
32
        ob_implicit_flush(0);
33
34
        $widget = TestWidgetA::begin()->id('test');
35
36
        $this->assertInstanceOf(Widget::class, $widget);
37
38
        TestWidgetA::end();
39
        $output = ob_get_clean();
40
41
        $this->assertSame('<run-test>', $output);
42
    }
43
44
    /**
45
     * @depends testBeginEnd
46
     */
47
    public function testStackTracking(): void
48
    {
49
        $this->expectException('BadFunctionCallException');
50
        TestWidget::end();
51
    }
52
53
    /**
54
     * @depends testBeginEnd
55
     */
56
    public function testStackTrackingDisorder(): void
57
    {
58
        $this->expectException('BadFunctionCallException');
59
        TestWidgetA::begin();
60
        TestWidgetB::end();
61
    }
62
}
63