ExceptionTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testCacheFragmentThrowExceptionIfNotSetId() 0 8 1
A testGetBlockNotFound() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Widgets\Tests\Block;
6
7
use InvalidArgumentException;
8
use PHPUnit\Framework\TestCase;
9
use RuntimeException;
10
use Yiisoft\Definitions\Exception\CircularReferenceException;
11
use Yiisoft\Definitions\Exception\InvalidConfigException;
12
use Yiisoft\Definitions\Exception\NotInstantiableException;
13
use Yiisoft\Factory\NotFoundException;
14
use Yiisoft\Yii\Widgets\Block;
15
use Yiisoft\Yii\Widgets\Tests\Support\TestTrait;
16
17
/**
18
 * @psalm-suppress PropertyNotSetInConstructor
19
 */
20
final class ExceptionTest extends TestCase
21
{
22
    use TestTrait;
23
24
    /**
25
     * @throws CircularReferenceException
26
     * @throws InvalidConfigException
27
     * @throws NotFoundException
28
     * @throws NotInstantiableException
29
     * @throws RuntimeException
30
     */
31
    public function testCacheFragmentThrowExceptionIfNotSetId(): void
32
    {
33
        $this->expectException(RuntimeException::class);
34
        $this->expectExceptionMessage('You must assign the "id" using the "id()" setter.');
35
36
        Block::widget()->begin();
37
        echo '<block-testme>';
38
        Block::end();
39
    }
40
41
    /**
42
     * @throws CircularReferenceException
43
     * @throws InvalidArgumentException
44
     * @throws InvalidConfigException
45
     * @throws NotFoundException
46
     * @throws NotInstantiableException
47
     */
48
    public function testGetBlockNotFound(): void
49
    {
50
        $this->expectException(InvalidArgumentException::class);
51
        $this->webView->getBlock('notfound');
52
    }
53
}
54