Passed
Branch master (27c48c)
by Wilmer
02:16
created

testCacheFragmentThrowExceptionIfNotSetId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Widgets\Tests\FragmentCache;
6
7
use PHPUnit\Framework\TestCase;
8
use RuntimeException;
9
use Yiisoft\Definitions\Exception\CircularReferenceException;
10
use Yiisoft\Definitions\Exception\InvalidConfigException;
11
use Yiisoft\Definitions\Exception\NotInstantiableException;
12
use Yiisoft\Factory\NotFoundException;
13
use Yiisoft\Yii\Widgets\FragmentCache;
14
use Yiisoft\Yii\Widgets\Tests\Support\TestTrait;
15
16
/**
17
 * @psalm-suppress PropertyNotSetInConstructor
18
 */
19
final class ExceptionTest extends TestCase
20
{
21
    use TestTrait;
22
23
    /**
24
     * @throws CircularReferenceException
25
     * @throws InvalidConfigException
26
     * @throws NotFoundException
27
     * @throws NotInstantiableException
28
     * @throws RuntimeException
29
     */
30
    public function testCacheFragmentThrowExceptionIfNotSetId(): void
31
    {
32
        $this->expectException(RuntimeException::class);
33
        $this->expectExceptionMessage('You must assign the "id" using the "id()" setter.');
34
35
        FragmentCache::widget()->begin();
36
        echo 'cached fragment';
37
        FragmentCache::end();
38
    }
39
}
40