Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit e428e46

Browse files
committed
Merge pull request #140 from fhein/MethodScanner-setVisibility-Corrected_Exception_class_used
Corrected the exception class used and removed unnecessary strtolower in MethodScanner::setVisibility
2 parents af13903 + 5e9f463 commit e428e46

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/Scanner/MethodScanner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,11 @@ public function setName($name)
279279
*
280280
* @param int $visibility T_PUBLIC | T_PRIVATE | T_PROTECTED
281281
* @return self
282-
* @throws \Zend\Code\Exception
282+
* @throws \Zend\Code\Exception\InvalidArgumentException
283283
*/
284284
public function setVisibility($visibility)
285285
{
286-
switch (strtolower($visibility)) {
286+
switch ($visibility) {
287287
case T_PUBLIC:
288288
$this->isPublic = true;
289289
$this->isPrivate = false;
@@ -303,7 +303,7 @@ public function setVisibility($visibility)
303303
break;
304304

305305
default:
306-
throw new Exception('Invalid visibility argument passed to setVisibility.');
306+
throw new Exception\InvalidArgumentException('Invalid visibility argument passed to setVisibility.');
307307
}
308308

309309
return $this;

test/Scanner/MethodScannerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPUnit\Framework\TestCase;
1313
use Zend\Code\Scanner\FileScanner;
1414
use Zend\Code\Scanner\ParameterScanner;
15+
use Zend\Code\Scanner\MethodScanner;
1516
use ZendTest\Code\TestAsset\AbstractClass;
1617
use ZendTest\Code\TestAsset\BarClass;
1718
use ZendTest\Code\TestAsset\FooClass;
@@ -110,4 +111,24 @@ public function testMethodScannerWorksWithSingleAbstractFunction()
110111

111112
self::assertTrue($method->isAbstract());
112113
}
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+
}
113134
}

0 commit comments

Comments
 (0)