ExceptionTest::testLabelNotString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Widgets\Tests\Breadcrumbs;
6
7
use InvalidArgumentException;
8
use PHPUnit\Framework\TestCase;
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\Breadcrumbs;
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 InvalidArgumentException
26
     * @throws InvalidConfigException
27
     * @throws NotFoundException
28
     * @throws NotInstantiableException
29
     */
30
    public function testHomeItemThrowExceptionForEmptyArray(): void
31
    {
32
        $this->expectException(InvalidArgumentException::class);
33
        $this->expectExceptionMessage(
34
            'The home item cannot be an empty array. To disable rendering of the home item, specify null.',
35
        );
36
        Breadcrumbs::widget()->homeItem([]);
0 ignored issues
show
Bug introduced by
The method homeItem() 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\Breadcrumbs. ( Ignorable by Annotation )

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

36
        Breadcrumbs::widget()->/** @scrutinizer ignore-call */ homeItem([]);
Loading history...
37
    }
38
39
    /**
40
     * @throws CircularReferenceException
41
     * @throws InvalidArgumentException
42
     * @throws InvalidConfigException
43
     * @throws NotFoundException
44
     * @throws NotInstantiableException
45
     */
46
    public function testLabelNotString(): void
47
    {
48
        $this->expectException(InvalidArgumentException::class);
49
        $this->expectExceptionMessage('The "label" element must be a string.');
50
        Breadcrumbs::widget()->items([['label' => 1]])->render();
0 ignored issues
show
Bug introduced by
The method items() 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\Menu or Yiisoft\Yii\Widgets\Breadcrumbs or Yiisoft\Yii\Widgets\Dropdown. ( Ignorable by Annotation )

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

50
        Breadcrumbs::widget()->/** @scrutinizer ignore-call */ items([['label' => 1]])->render();
Loading history...
51
    }
52
53
    /**
54
     * @throws CircularReferenceException
55
     * @throws InvalidArgumentException
56
     * @throws InvalidConfigException
57
     * @throws NotFoundException
58
     * @throws NotInstantiableException
59
     */
60
    public function testRenderItem(): void
61
    {
62
        $this->expectException(InvalidArgumentException::class);
63
        $this->expectExceptionMessage('The "label" element is required for each item.');
64
        Breadcrumbs::widget()->homeItem(null)->items([['url' => 'http://my.example.com/yii2/link/page']])->render();
65
    }
66
}
67