ContentDecoratorTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testContentDecorator() 0 31 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Widgets\Tests\ContentDecorator;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Definitions\Exception\CircularReferenceException;
9
use Yiisoft\Definitions\Exception\InvalidConfigException;
10
use Yiisoft\Definitions\Exception\NotInstantiableException;
11
use Yiisoft\Factory\NotFoundException;
12
use Yiisoft\Yii\Widgets\ContentDecorator;
13
use Yiisoft\Yii\Widgets\Tests\Support\Assert;
14
use Yiisoft\Yii\Widgets\Tests\Support\TestTrait;
15
16
/**
17
 * @psalm-suppress PropertyNotSetInConstructor
18
 */
19
final class ContentDecoratorTest extends TestCase
20
{
21
    use TestTrait;
22
23
    /**
24
     * @link https://github.com/yiisoft/yii2/issues/15536
25
     *
26
     * @throws CircularReferenceException
27
     * @throws InvalidConfigException
28
     * @throws NotFoundException
29
     * @throws NotInstantiableException
30
     */
31
    public function testContentDecorator(): void
32
    {
33
        ContentDecorator::widget()->viewFile('@public/view/layout.php')->begin();
0 ignored issues
show
Bug introduced by
The method viewFile() does not exist on Yiisoft\Widget\Widget. It seems like you code against a sub-type of Yiisoft\Widget\Widget such as Yiisoft\Yii\Widgets\ContentDecorator. ( Ignorable by Annotation )

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

33
        ContentDecorator::widget()->/** @scrutinizer ignore-call */ viewFile('@public/view/layout.php')->begin();
Loading history...
34
        echo "<div class='left-column'>\n";
35
        echo "<p>This is a left bar!</p>\n";
36
        echo "</div>\n";
37
        echo "<div class='right-column'>\n";
38
        echo "<p>This is a right bar!</p>\n";
39
        echo '</div>';
40
        $html = ContentDecorator::end();
41
42
        $this->assertStringContainsString('<title>Test</title>', $html);
43
44
        Assert::equalsWithoutLE(
45
            <<<HTML
46
            <!DOCTYPE html>
47
            <html lang="en">
48
            <head>
49
            <title>Test</title>
50
            </head>
51
            <body>
52
            <div class='left-column'>
53
            <p>This is a left bar!</p>
54
            </div>
55
            <div class='right-column'>
56
            <p>This is a right bar!</p>
57
            </div></body>
58
            </html>
59
60
            HTML,
61
            $html,
62
        );
63
    }
64
}
65