This repository was archived by the owner on Jan 29, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -279,11 +279,11 @@ public function setName($name)
279
279
*
280
280
* @param int $visibility T_PUBLIC | T_PRIVATE | T_PROTECTED
281
281
* @return self
282
- * @throws \Zend\Code\Exception
282
+ * @throws \Zend\Code\Exception\InvalidArgumentException
283
283
*/
284
284
public function setVisibility ($ visibility )
285
285
{
286
- switch (strtolower ( $ visibility) ) {
286
+ switch ($ visibility ) {
287
287
case T_PUBLIC :
288
288
$ this ->isPublic = true ;
289
289
$ this ->isPrivate = false ;
@@ -303,7 +303,7 @@ public function setVisibility($visibility)
303
303
break ;
304
304
305
305
default :
306
- throw new Exception ('Invalid visibility argument passed to setVisibility. ' );
306
+ throw new Exception \ InvalidArgumentException ('Invalid visibility argument passed to setVisibility. ' );
307
307
}
308
308
309
309
return $ this ;
Original file line number Diff line number Diff line change 12
12
use PHPUnit \Framework \TestCase ;
13
13
use Zend \Code \Scanner \FileScanner ;
14
14
use Zend \Code \Scanner \ParameterScanner ;
15
+ use Zend \Code \Scanner \MethodScanner ;
15
16
use ZendTest \Code \TestAsset \AbstractClass ;
16
17
use ZendTest \Code \TestAsset \BarClass ;
17
18
use ZendTest \Code \TestAsset \FooClass ;
@@ -110,4 +111,24 @@ public function testMethodScannerWorksWithSingleAbstractFunction()
110
111
111
112
self ::assertTrue ($ method ->isAbstract ());
112
113
}
114
+
115
+ public function testMethodScannerSetVisibilityThrowsInvalidArgumentException ()
116
+ {
117
+ $ methodScanner = new MethodScanner ([]);
118
+
119
+ // make sure test argument is invalid
120
+ $ invalidArgument = max (T_PUBLIC , T_PROTECTED , T_PRIVATE ) + 1 ;
121
+
122
+ $ this ->expectException ('\Zend\Code\Exception\InvalidArgumentException ' );
123
+ $ methodScanner ->setVisibility ($ invalidArgument );
124
+ }
125
+
126
+ public function testMethodScannerSetVisibilityAcceptsIntegerTokens ()
127
+ {
128
+ $ methodScanner = new MethodScanner ([]);
129
+
130
+ $ this ->assertSame ($ methodScanner ->setVisibility (T_PUBLIC ), $ methodScanner );
131
+ $ this ->assertSame ($ methodScanner ->setVisibility (T_PROTECTED ), $ methodScanner );
132
+ $ this ->assertSame ($ methodScanner ->setVisibility (T_PRIVATE ), $ methodScanner );
133
+ }
113
134
}
You can’t perform that action at this time.
0 commit comments