Issues (151)

tests/Menu/ExceptionTest.php (4 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Widgets\Tests\Menu;
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\Menu;
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 testAfterTag(): void
31
    {
32
        $this->expectException(InvalidArgumentException::class);
33
        $this->expectExceptionMessage('Tag name must be a string and cannot be empty.');
34
        Menu::widget()->afterTag('')->afterContent('tests')->items([['label' => 'Item 1']])->render();
0 ignored issues
show
The method afterTag() 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. ( Ignorable by Annotation )

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

34
        Menu::widget()->/** @scrutinizer ignore-call */ afterTag('')->afterContent('tests')->items([['label' => 'Item 1']])->render();
Loading history...
35
    }
36
37
    /**
38
     * @throws CircularReferenceException
39
     * @throws InvalidArgumentException
40
     * @throws InvalidConfigException
41
     * @throws NotFoundException
42
     * @throws NotInstantiableException
43
     */
44
    public function testBeforeTag(): void
45
    {
46
        $this->expectException(InvalidArgumentException::class);
47
        $this->expectExceptionMessage('Tag name must be a string and cannot be empty.');
48
        Menu::widget()->beforeTag('')->beforeContent('tests')->items([['label' => 'Item 1']])->render();
0 ignored issues
show
The method beforeTag() 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. ( Ignorable by Annotation )

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

48
        Menu::widget()->/** @scrutinizer ignore-call */ beforeTag('')->beforeContent('tests')->items([['label' => 'Item 1']])->render();
Loading history...
49
    }
50
51
    /**
52
     * @throws CircularReferenceException
53
     * @throws InvalidArgumentException
54
     * @throws InvalidConfigException
55
     * @throws NotFoundException
56
     * @throws NotInstantiableException
57
     */
58
    public function testDropdownContainerTag(): void
59
    {
60
        $this->expectException(InvalidArgumentException::class);
61
        $this->expectExceptionMessage('Tag name must be a string and cannot be empty.');
62
        Menu::widget()
63
            ->dropdownContainerTag('')
0 ignored issues
show
The method dropdownContainerTag() 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. ( Ignorable by Annotation )

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

63
            ->/** @scrutinizer ignore-call */ dropdownContainerTag('')
Loading history...
64
            ->items([
65
                [
66
                    'label' => 'Dropdown',
67
                    'link' => '#',
68
                    'items' => [
69
                        ['label' => 'Action', 'link' => '#'],
70
                        ['label' => 'Another action', 'link' => '#'],
71
                        ['label' => 'Something else here', 'link' => '#'],
72
                        '-',
73
                        ['label' => 'Separated link', 'link' => '#'],
74
                    ],
75
                ],
76
            ])
77
            ->render();
78
    }
79
80
    /**
81
     * @throws CircularReferenceException
82
     * @throws InvalidArgumentException
83
     * @throws InvalidConfigException
84
     * @throws NotFoundException
85
     * @throws NotInstantiableException
86
     */
87
    public function testItemsTag(): void
88
    {
89
        $this->expectException(InvalidArgumentException::class);
90
        $this->expectExceptionMessage('Tag name must be a string and cannot be empty.');
91
        Menu::widget()->items([['label' => 'Item 1']])->itemsTag('')->render();
0 ignored issues
show
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

91
        Menu::widget()->/** @scrutinizer ignore-call */ items([['label' => 'Item 1']])->itemsTag('')->render();
Loading history...
92
    }
93
94
    /**
95
     * @throws CircularReferenceException
96
     * @throws InvalidArgumentException
97
     * @throws InvalidConfigException
98
     * @throws NotFoundException
99
     * @throws NotInstantiableException
100
     */
101
    public function testLabelExceptionEmpty(): void
102
    {
103
        $this->expectException(InvalidArgumentException::class);
104
        $this->expectExceptionMessage('The "label" option is required.');
105
        Menu::widget()->items([['link' => '/home']])->render();
106
    }
107
108
    /**
109
     * @throws CircularReferenceException
110
     * @throws InvalidArgumentException
111
     * @throws InvalidConfigException
112
     * @throws NotFoundException
113
     * @throws NotInstantiableException
114
     */
115
    public function testLabelExceptionEmptyString(): void
116
    {
117
        $this->expectException(InvalidArgumentException::class);
118
        $this->expectExceptionMessage('The "label" cannot be an empty string.');
119
        Menu::widget()->items([['label' => '']])->render();
120
    }
121
122
    /**
123
     * @throws CircularReferenceException
124
     * @throws InvalidArgumentException
125
     * @throws InvalidConfigException
126
     * @throws NotFoundException
127
     * @throws NotInstantiableException
128
     */
129
    public function testLabelExceptionNotString(): void
130
    {
131
        $this->expectException(InvalidArgumentException::class);
132
        $this->expectExceptionMessage('The "label" option must be a string.');
133
        Menu::widget()->items([['label' => 1]])->render();
134
    }
135
136
    /**
137
     * @throws CircularReferenceException
138
     * @throws InvalidArgumentException
139
     * @throws InvalidConfigException
140
     * @throws NotFoundException
141
     * @throws NotInstantiableException
142
     */
143
    public function testLinkTag(): void
144
    {
145
        $this->expectException(InvalidArgumentException::class);
146
        $this->expectExceptionMessage('Tag name must be a string and cannot be empty.');
147
        Menu::widget()->items([['label' => 'Item 1']])->linkTag('')->render();
148
    }
149
150
    /**
151
     * @throws CircularReferenceException
152
     * @throws InvalidArgumentException
153
     * @throws InvalidConfigException
154
     * @throws NotFoundException
155
     * @throws NotInstantiableException
156
     */
157
    public function testTagName(): void
158
    {
159
        $this->expectException(InvalidArgumentException::class);
160
        $this->expectExceptionMessage('Tag name must be a string and cannot be empty.');
161
        Menu::widget()->items([['label' => 'Item 1']])->tagName('')->render();
162
    }
163
}
164