1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Cubiche package. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) Cubiche |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Cubiche\Core\Bus\Tests\Units\Exception; |
12
|
|
|
|
13
|
|
|
use Cubiche\Core\Bus\Exception\NotFoundException; |
14
|
|
|
use Cubiche\Core\Bus\Tests\Units\TestCase; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* NotFoundExceptionTests class. |
18
|
|
|
* |
19
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class NotFoundExceptionTests extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Test class. |
25
|
|
|
*/ |
26
|
|
|
public function testClass() |
27
|
|
|
{ |
28
|
|
|
$this |
29
|
|
|
->testedClass |
30
|
|
|
->extends(\RuntimeException::class) |
31
|
|
|
; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Test nameOfMessage method. |
36
|
|
|
*/ |
37
|
|
|
public function testNameOfMessage() |
38
|
|
|
{ |
39
|
|
|
$this |
40
|
|
|
->given($cause = new \Exception('some cause')) |
41
|
|
|
->when($exception = NotFoundException::nameOfMessage('foo', $cause)) |
42
|
|
|
->then() |
43
|
|
|
->object($exception) |
44
|
|
|
->isInstanceOf(NotFoundException::class) |
45
|
|
|
->integer($exception->getCode()) |
46
|
|
|
->isEqualTo(1) |
47
|
|
|
->object($exception->getPrevious()) |
48
|
|
|
->isIdenticalTo($cause) |
49
|
|
|
; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Test handlerMethodNameForObject method. |
54
|
|
|
*/ |
55
|
|
View Code Duplication |
public function testMethodNameForObject() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$this |
58
|
|
|
->given($exception = NotFoundException::handlerMethodNameForObject('bar')) |
59
|
|
|
->then() |
60
|
|
|
->variable($exception->getPrevious()) |
61
|
|
|
->isNull() |
62
|
|
|
->integer($exception->getCode()) |
63
|
|
|
->isEqualTo(3) |
64
|
|
|
; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Test handlerFor method. |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
public function testHandlerFor() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$this |
73
|
|
|
->given($exception = NotFoundException::handlerFor('bar')) |
74
|
|
|
->then() |
75
|
|
|
->variable($exception->getPrevious()) |
76
|
|
|
->isNull() |
77
|
|
|
->integer($exception->getCode()) |
78
|
|
|
->isEqualTo(5) |
79
|
|
|
; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Test middlewareOfType method. |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function testMiddlewareOfType() |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$this |
88
|
|
|
->given($exception = NotFoundException::middlewareOfType('bar')) |
89
|
|
|
->then() |
90
|
|
|
->variable($exception->getPrevious()) |
91
|
|
|
->isNull() |
92
|
|
|
->integer($exception->getCode()) |
93
|
|
|
->isEqualTo(6) |
94
|
|
|
; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Test nameOfCommand method. |
99
|
|
|
*/ |
100
|
|
View Code Duplication |
public function testNameOfCommand() |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
$this |
103
|
|
|
->given($exception = NotFoundException::nameOfCommand('bar')) |
104
|
|
|
->then() |
105
|
|
|
->variable($exception->getPrevious()) |
106
|
|
|
->isNull() |
107
|
|
|
->integer($exception->getCode()) |
108
|
|
|
->isEqualTo(2) |
109
|
|
|
; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Test nameOfQuery method. |
114
|
|
|
*/ |
115
|
|
View Code Duplication |
public function testNameOfQuery() |
|
|
|
|
116
|
|
|
{ |
117
|
|
|
$this |
118
|
|
|
->given($exception = NotFoundException::nameOfQuery('bar')) |
119
|
|
|
->then() |
120
|
|
|
->variable($exception->getPrevious()) |
121
|
|
|
->isNull() |
122
|
|
|
->integer($exception->getCode()) |
123
|
|
|
->isEqualTo(4) |
124
|
|
|
; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Test methodForObject method. |
129
|
|
|
*/ |
130
|
|
View Code Duplication |
public function testMethodForObject() |
|
|
|
|
131
|
|
|
{ |
132
|
|
|
$this |
133
|
|
|
->given($exception = NotFoundException::methodForObject('foo', 'bar')) |
134
|
|
|
->then() |
135
|
|
|
->variable($exception->getPrevious()) |
136
|
|
|
->isNull() |
137
|
|
|
->integer($exception->getCode()) |
138
|
|
|
->isEqualTo(7) |
139
|
|
|
; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.