-
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.
chore: use named constructor for exceptions in MultipleType class
- Loading branch information
1 parent
be6b0a3
commit 084f627
Showing
6 changed files
with
147 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the "schema" extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Brotkrueml\Schema\Core\Exception; | ||
|
||
final class InvalidNumberOfTypesException extends \DomainException | ||
{ | ||
/** | ||
* @param string[] $singleTypes | ||
*/ | ||
public static function fromSingleTypes(array $singleTypes): self | ||
{ | ||
return new self( | ||
\sprintf( | ||
'At least two types have to be assigned, "%s" (%d) given', | ||
\implode(', ', $singleTypes), | ||
\count($singleTypes), | ||
), | ||
1621871446, | ||
); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Classes/Core/Exception/SameTypeForMultipleTypeException.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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the "schema" extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Brotkrueml\Schema\Core\Exception; | ||
|
||
final class SameTypeForMultipleTypeException extends \DomainException | ||
{ | ||
/** | ||
* @param string[] $singleTypes | ||
*/ | ||
public static function fromSingleTypes(array $singleTypes): self | ||
{ | ||
return new self( | ||
\sprintf( | ||
'Only different types can be used as arguments for a multiple type, "%s" given', | ||
\implode(', ', $singleTypes), | ||
), | ||
1621871950, | ||
); | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
Tests/Unit/Core/Exception/InvalidNumberOfTypesExceptionTest.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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the "schema" extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Brotkrueml\Schema\Tests\Unit\Core\Exception; | ||
|
||
use Brotkrueml\Schema\Core\Exception\InvalidNumberOfTypesException; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(InvalidNumberOfTypesException::class)] | ||
final class InvalidNumberOfTypesExceptionTest extends TestCase | ||
{ | ||
#[Test] | ||
public function fromSingleTypesWithNoneGiven(): void | ||
{ | ||
$actual = InvalidNumberOfTypesException::fromSingleTypes([]); | ||
|
||
self::assertSame( | ||
'At least two types have to be assigned, "" (0) given', | ||
$actual->getMessage(), | ||
); | ||
self::assertSame(1621871446, $actual->getCode()); | ||
} | ||
|
||
#[Test] | ||
public function fromSingleTypesWithOneGiven(): void | ||
{ | ||
$actual = InvalidNumberOfTypesException::fromSingleTypes(['SomeType']); | ||
|
||
self::assertSame( | ||
'At least two types have to be assigned, "SomeType" (1) given', | ||
$actual->getMessage(), | ||
); | ||
self::assertSame(1621871446, $actual->getCode()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Tests/Unit/Core/Exception/SameTypeForMultipleTypeExceptionTest.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 | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the "schema" extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Brotkrueml\Schema\Tests\Unit\Core\Exception; | ||
|
||
use Brotkrueml\Schema\Core\Exception\SameTypeForMultipleTypeException; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(SameTypeForMultipleTypeException::class)] | ||
final class SameTypeForMultipleTypeExceptionTest extends TestCase | ||
{ | ||
#[Test] | ||
public function fromSingleTypes(): void | ||
{ | ||
$actual = SameTypeForMultipleTypeException::fromSingleTypes(['SomeType', 'AnotherType', 'SomeType']); | ||
|
||
self::assertSame( | ||
'Only different types can be used as arguments for a multiple type, "SomeType, AnotherType, SomeType" given', | ||
$actual->getMessage(), | ||
); | ||
self::assertSame(1621871950, $actual->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