-
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 AbstractBaseType class
- Loading branch information
1 parent
0a31871
commit be6b0a3
Showing
8 changed files
with
203 additions
and
30 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,26 @@ | ||
<?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 InvalidIdValueException extends \InvalidArgumentException | ||
{ | ||
public static function fromValueType(string $valueType): self | ||
{ | ||
return new self( | ||
\sprintf( | ||
'Value for id has not a valid data type (given: "%s"). Valid types are: null, string, instanceof NodeIdentifierInterface', | ||
$valueType, | ||
), | ||
1620654936, | ||
); | ||
} | ||
} |
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,27 @@ | ||
<?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 InvalidPropertyValueException extends \InvalidArgumentException | ||
{ | ||
public static function fromValueType(string $propertyName, string $propertyValueType): self | ||
{ | ||
return new self( | ||
\sprintf( | ||
'Value for property "%s" has not a valid data type (given: "%s"). Valid types are: null, string, int, array, bool, instanceof TypeInterface, instanceof NodeIdentifierInterface', | ||
$propertyName, | ||
$propertyValueType, | ||
), | ||
1561830012, | ||
); | ||
} | ||
} |
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 UnknownPropertyException extends \DomainException | ||
{ | ||
/** | ||
* @param string|string[] $type | ||
*/ | ||
public static function fromPropertyName(string|array $type, string $propertyName): self | ||
{ | ||
return new self( | ||
\sprintf( | ||
'Property "%s" is unknown for type "%s"', | ||
$propertyName, | ||
\is_array($type) ? \implode(' / ', $type) : $type, | ||
), | ||
1561829996, | ||
); | ||
} | ||
} |
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,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\InvalidIdValueException; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(InvalidIdValueException::class)] | ||
final class InvalidIdValueExceptionTest extends TestCase | ||
{ | ||
#[Test] | ||
public function fromDebugType(): void | ||
{ | ||
$actual = InvalidIdValueException::fromValueType('invalid_type'); | ||
|
||
self::assertSame( | ||
'Value for id has not a valid data type (given: "invalid_type"). Valid types are: null, string, instanceof NodeIdentifierInterface', | ||
$actual->getMessage(), | ||
); | ||
self::assertSame(1620654936, $actual->getCode()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Tests/Unit/Core/Exception/InvalidPropertyValueExceptionTest.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\InvalidPropertyValueException; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(InvalidPropertyValueException::class)] | ||
final class InvalidPropertyValueExceptionTest extends TestCase | ||
{ | ||
#[Test] | ||
public function fromValueType(): void | ||
{ | ||
$actual = InvalidPropertyValueException::fromValueType('someProperty', 'invalid_type'); | ||
|
||
self::assertSame( | ||
'Value for property "someProperty" has not a valid data type (given: "invalid_type"). Valid types are: null, string, int, array, bool, instanceof TypeInterface, instanceof NodeIdentifierInterface', | ||
$actual->getMessage(), | ||
); | ||
self::assertSame(1561830012, $actual->getCode()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
Tests/Unit/Core/Exception/UnknownPropertyExceptionTest.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,39 @@ | ||
<?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\UnknownPropertyException; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(UnknownPropertyException::class)] | ||
final class UnknownPropertyExceptionTest extends TestCase | ||
{ | ||
#[Test] | ||
public function fromPropertyNameWithTypeAsString(): void | ||
{ | ||
$actual = UnknownPropertyException::fromPropertyName('SomeType', 'someProperty'); | ||
|
||
self::assertSame('Property "someProperty" is unknown for type "SomeType"', $actual->getMessage()); | ||
self::assertSame(1561829996, $actual->getCode()); | ||
} | ||
|
||
#[Test] | ||
public function fromPropertyNameWithTypeAsArray(): void | ||
{ | ||
$actual = UnknownPropertyException::fromPropertyName(['SomeType', 'AnotherType'], 'someProperty'); | ||
|
||
self::assertSame('Property "someProperty" is unknown for type "SomeType / AnotherType"', $actual->getMessage()); | ||
self::assertSame(1561829996, $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