This repository has been archived by the owner on Jul 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented convenience methods. Closes #4.
- Loading branch information
Erin Millard
committed
Mar 24, 2012
1 parent
651f401
commit 7dd8697
Showing
4 changed files
with
217 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Eloquent/Enumeration/Exception/UndefinedEnumerationValueException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Enumeration package. | ||
* | ||
* Copyright © 2011 Erin Millard | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eloquent\Enumeration\Exception; | ||
|
||
final class UndefinedEnumerationValueException extends LogicException | ||
{ | ||
/** | ||
* @param string $class | ||
* @param scalar $value | ||
* @param \Exception $previous | ||
*/ | ||
public function __construct($class, $value, \Exception $previous = null) | ||
{ | ||
$message = | ||
"No enumeration with value " | ||
.var_export($value, true) | ||
." defined in class '" | ||
.$class | ||
."'." | ||
; | ||
|
||
parent::__construct($message, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
test/suite/src/Eloquent/Enumeration/Exception/UndefinedEnumerationValueExceptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Enumeration package. | ||
* | ||
* Copyright © 2011 Erin Millard | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eloquent\Enumeration\Exception; | ||
|
||
class UndefinedEnumerationValueExceptionTest extends \Eloquent\Enumeration\Test\TestCase | ||
{ | ||
/** | ||
* @covers Eloquent\Enumeration\Exception\UndefinedEnumerationValueException | ||
* @covers Eloquent\Enumeration\Exception\LogicException | ||
* @covers Eloquent\Enumeration\Exception\Exception | ||
* @group exceptions | ||
* @group core | ||
*/ | ||
public function testException() | ||
{ | ||
$class = 'foo'; | ||
$value = 'bar'; | ||
$exception = new UndefinedEnumerationValueException($class, $value); | ||
$expectedMessage = "No enumeration with value 'bar' defined in class 'foo'."; | ||
|
||
$this->assertSame($expectedMessage, $exception->getMessage()); | ||
} | ||
} |