generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Throw EntityDefinitionAlreadyRegistered exception
- Loading branch information
1 parent
ed73b90
commit 75ae235
Showing
5 changed files
with
72 additions
and
6 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
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2020 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/factory-bot | ||
*/ | ||
|
||
namespace Ergebnis\FactoryBot\Exception; | ||
|
||
final class EntityDefinitionAlreadyRegistered extends \RuntimeException implements Exception | ||
{ | ||
public static function for(string $className): self | ||
{ | ||
return new self(\sprintf( | ||
'An entity definition for class name "%s" has already been registered.', | ||
$className | ||
)); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
test/Unit/Exception/EntityDefinitionAlreadyRegisteredTest.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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2020 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/factory-bot | ||
*/ | ||
|
||
namespace Ergebnis\FactoryBot\Test\Unit\Exception; | ||
|
||
use Ergebnis\FactoryBot\Exception; | ||
use PHPUnit\Framework; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @covers \Ergebnis\FactoryBot\Exception\EntityDefinitionAlreadyRegistered | ||
*/ | ||
final class EntityDefinitionAlreadyRegisteredTest extends Framework\TestCase | ||
{ | ||
public function testForReturnsException(): void | ||
{ | ||
$className = self::class; | ||
|
||
$exception = Exception\EntityDefinitionAlreadyRegistered::for($className); | ||
|
||
$message = \sprintf( | ||
'An entity definition for class name "%s" has already been registered.', | ||
$className | ||
); | ||
|
||
self::assertSame($message, $exception->getMessage()); | ||
self::assertSame(0, $exception->getCode()); | ||
} | ||
} |
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