From 834b24f34888be1ad777389c9cbe42de8d7486fa Mon Sep 17 00:00:00 2001 From: Meritoo Date: Mon, 2 Jul 2018 08:52:01 +0200 Subject: [PATCH] Exceptions > create instance of exception using static "create()" method (instead of constructor) --- CHANGELOG.md | 1 + src/Exception/Base/UnknownTypeException.php | 13 +++++++------ .../Bundle/IncorrectBundleNameException.php | 8 +++++--- src/Exception/File/EmptyFileException.php | 7 ++++--- src/Exception/File/EmptyFilePathException.php | 6 +++--- .../File/NotExistingFileException.php | 7 ++++--- .../Method/DisabledMethodException.php | 8 +++++--- .../CannotResolveClassNameException.php | 7 ++++--- .../MissingChildClassesException.php | 7 ++++--- .../TooManyChildClassesException.php | 7 ++++--- .../Regex/IncorrectColorHexLengthException.php | 8 +++++--- .../Regex/InvalidColorHexValueException.php | 8 +++++--- .../Regex/InvalidHtmlAttributesException.php | 8 +++++--- src/Exception/Regex/InvalidUrlException.php | 14 +++++++++++--- .../UnknownDatePartTypeException.php | 14 +++++++++----- .../Type/UnknownOopVisibilityTypeException.php | 18 +++++++++++++++--- src/Utilities/Bundle.php | 2 +- src/Utilities/Date.php | 8 ++++---- src/Utilities/Reflection.php | 10 ++++------ .../Base/UnknownTypeExceptionTest.php | 14 +++++++++----- .../Date/UnknownDatePartTypeExceptionTest.php | 8 ++++---- .../Exception/File/EmptyFileExceptionTest.php | 6 +++--- .../File/EmptyFilePathExceptionTest.php | 4 ++-- .../File/NotExistingFileExceptionTest.php | 4 ++-- .../Method/DisabledMethodExceptionTest.php | 4 ++-- .../CannotResolveClassNameExceptionTest.php | 4 ++-- .../MissingChildClassesExceptionTest.php | 4 ++-- .../TooManyChildClassesExceptionTest.php | 4 ++-- .../IncorrectColorHexLengthExceptionTest.php | 4 ++-- .../InvalidColorHexValueExceptionTest.php | 8 ++------ .../InvalidHtmlAttributesExceptionTest.php | 8 ++------ .../Regex/InvalidUrlExceptionTest.php | 4 ++-- .../UnknownOopVisibilityTypeExceptionTest.php | 4 ++-- tests/Utilities/BundleTest.php | 1 - tests/Utilities/DateTest.php | 2 +- 35 files changed, 139 insertions(+), 105 deletions(-) rename src/Exception/{Date => Type}/UnknownDatePartTypeException.php (57%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 115b085..b7007e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Common and useful classes, methods, exceptions etc. 1. Composer > support/require PHP 5.6+ (instead of 5.5.9+) 2. Docker > rename `php-cli` service to `php` +3. Exceptions > create instance of exception using static `create()` method (instead of constructor) # 0.0.21 diff --git a/src/Exception/Base/UnknownTypeException.php b/src/Exception/Base/UnknownTypeException.php index 5bd8721..ea860ca 100644 --- a/src/Exception/Base/UnknownTypeException.php +++ b/src/Exception/Base/UnknownTypeException.php @@ -21,21 +21,22 @@ use Meritoo\Common\Utilities\Arrays; abstract class UnknownTypeException extends Exception { /** - * Class constructor + * Creates exception * * @param string|int $unknownType The unknown type of something (value of constant) * @param BaseType $typeInstance An instance of class that contains type of the something * @param string $typeName Name of the something + * @return UnknownTypeException */ - public function __construct($unknownType, BaseType $typeInstance, $typeName) + public static function create($unknownType, BaseType $typeInstance, $typeName) { - $allTypes = $typeInstance->getAll(); - $types = Arrays::values2string($allTypes, '', ', '); - $template = 'The \'%s\' type of %s is unknown. Probably doesn\'t exist or there is a typo. You should use one' . ' of these types: %s.'; + $allTypes = $typeInstance->getAll(); + $types = Arrays::values2string($allTypes, '', ', '); $message = sprintf(sprintf($template, $unknownType, $typeName, $types)); - parent::__construct($message); + + return new static($message); } } diff --git a/src/Exception/Bundle/IncorrectBundleNameException.php b/src/Exception/Bundle/IncorrectBundleNameException.php index 9ef0413..2c34199 100644 --- a/src/Exception/Bundle/IncorrectBundleNameException.php +++ b/src/Exception/Bundle/IncorrectBundleNameException.php @@ -19,16 +19,18 @@ use Exception; class IncorrectBundleNameException extends Exception { /** - * Class constructor + * Creates exception * * @param string $bundleName Incorrect name of bundle + * @return IncorrectBundleNameException */ - public function __construct($bundleName) + public static function create($bundleName) { $template = 'Name of bundle \'%s\' is incorrect. It should start with big letter and end with "Bundle". Is' . ' there everything ok?'; $message = sprintf($template, $bundleName); - parent::__construct($message); + + return new static($message); } } diff --git a/src/Exception/File/EmptyFileException.php b/src/Exception/File/EmptyFileException.php index b2023a3..4ff9441 100644 --- a/src/Exception/File/EmptyFileException.php +++ b/src/Exception/File/EmptyFileException.php @@ -17,15 +17,16 @@ namespace Meritoo\Common\Exception\File; class EmptyFileException extends \Exception { /** - * Class constructor + * Creates exception * * @param string $emptyFilePath Path of the empty file + * @return EmptyFileException */ - public function __construct($emptyFilePath) + public static function create($emptyFilePath) { $template = 'File with path \'%s\' is empty (has no content). Did you provide path of proper file?'; $message = sprintf($template, $emptyFilePath); - parent::__construct($message); + return new static($message); } } diff --git a/src/Exception/File/EmptyFilePathException.php b/src/Exception/File/EmptyFilePathException.php index d18e543..33333f5 100644 --- a/src/Exception/File/EmptyFilePathException.php +++ b/src/Exception/File/EmptyFilePathException.php @@ -17,10 +17,10 @@ namespace Meritoo\Common\Exception\File; class EmptyFilePathException extends \Exception { /** - * Class constructor + * Creates exception */ - public function __construct() + public static function create() { - parent::__construct('Path of the file is empty. Did you provide path of proper file?'); + return new static('Path of the file is empty. Did you provide path of proper file?'); } } diff --git a/src/Exception/File/NotExistingFileException.php b/src/Exception/File/NotExistingFileException.php index 8ccd0ba..c64a8f8 100644 --- a/src/Exception/File/NotExistingFileException.php +++ b/src/Exception/File/NotExistingFileException.php @@ -17,15 +17,16 @@ namespace Meritoo\Common\Exception\File; class NotExistingFileException extends \Exception { /** - * Class constructor + * Creates exception * * @param string $notExistingFilePath Path of not existing (or not readable) file + * @return NotExistingFileException */ - public function __construct($notExistingFilePath) + public static function create($notExistingFilePath) { $template = 'File with path \'%s\' does not exist (or is not readable). Did you provide path of proper file?'; $message = sprintf($template, $notExistingFilePath); - parent::__construct($message); + return new static($message); } } diff --git a/src/Exception/Method/DisabledMethodException.php b/src/Exception/Method/DisabledMethodException.php index 0345f89..fd0ac7b 100644 --- a/src/Exception/Method/DisabledMethodException.php +++ b/src/Exception/Method/DisabledMethodException.php @@ -19,12 +19,13 @@ use Exception; class DisabledMethodException extends Exception { /** - * Class constructor + * Creates exception * * @param string $disabledMethod Name of the disabled method * @param string $alternativeMethod (optional) Name of the alternative method + * @return DisabledMethodException */ - public function __construct($disabledMethod, $alternativeMethod = '') + public static function create($disabledMethod, $alternativeMethod = '') { $template = 'Method %s() cannot be called, because is disabled.'; @@ -33,6 +34,7 @@ class DisabledMethodException extends Exception } $message = sprintf($template, $disabledMethod, $alternativeMethod); - parent::__construct($message); + + return new static($message); } } diff --git a/src/Exception/Reflection/CannotResolveClassNameException.php b/src/Exception/Reflection/CannotResolveClassNameException.php index adbe9a5..dee9dde 100644 --- a/src/Exception/Reflection/CannotResolveClassNameException.php +++ b/src/Exception/Reflection/CannotResolveClassNameException.php @@ -19,14 +19,15 @@ use Exception; class CannotResolveClassNameException extends Exception { /** - * Class constructor + * Creates exception * * @param array|object|string $source Source of the class's / trait's name. It can be an array of objects, * namespaces, object or namespace. * @param bool $forClass (optional) If is set to true, message of this exception for class is * prepared. Otherwise - for trait. + * @return CannotResolveClassNameException */ - public function __construct($source, $forClass = true) + public static function create($source, $forClass = true) { $forWho = 'trait'; $value = ''; @@ -42,6 +43,6 @@ class CannotResolveClassNameException extends Exception $template = 'Name of %s from given \'%s\'%s cannot be resolved. Is there everything ok?'; $message = sprintf($template, $forWho, gettype($source), $value); - parent::__construct($message); + return new static($message); } } diff --git a/src/Exception/Reflection/MissingChildClassesException.php b/src/Exception/Reflection/MissingChildClassesException.php index c855831..27183ff 100644 --- a/src/Exception/Reflection/MissingChildClassesException.php +++ b/src/Exception/Reflection/MissingChildClassesException.php @@ -20,12 +20,13 @@ use Meritoo\Common\Utilities\Reflection; class MissingChildClassesException extends Exception { /** - * Class constructor + * Creates exception * * @param array|object|string $parentClass Class that hasn't child classes, but it should. An array of objects, * strings, object or string. + * @return MissingChildClassesException */ - public function __construct($parentClass) + public static function create($parentClass) { $template = 'The \'%s\' class requires one child class at least who will extend her (maybe is an abstract' . ' class), but the child classes are missing. Did you forget to extend this class?'; @@ -33,6 +34,6 @@ class MissingChildClassesException extends Exception $parentClassName = Reflection::getClassName($parentClass); $message = sprintf($template, $parentClassName); - parent::__construct($message); + return new static($message); } } diff --git a/src/Exception/Reflection/TooManyChildClassesException.php b/src/Exception/Reflection/TooManyChildClassesException.php index fe9fc5b..f06dab2 100644 --- a/src/Exception/Reflection/TooManyChildClassesException.php +++ b/src/Exception/Reflection/TooManyChildClassesException.php @@ -20,13 +20,14 @@ use Meritoo\Common\Utilities\Reflection; class TooManyChildClassesException extends Exception { /** - * Class constructor + * Creates exception * * @param array|object|string $parentClass Class that has more than one child class, but it shouldn't. An array * of objects, strings, object or string. * @param array $childClasses Child classes + * @return TooManyChildClassesException */ - public function __construct($parentClass, array $childClasses) + public static function create($parentClass, array $childClasses) { $template = "The '%s' class requires one child class at most who will extend her, but more than one child" . " class was found:\n- %s\n\nWhy did you create more than one classes that extend '%s' class?"; @@ -34,6 +35,6 @@ class TooManyChildClassesException extends Exception $parentClassName = Reflection::getClassName($parentClass); $message = sprintf($template, $parentClassName, implode("\n- ", $childClasses), $parentClassName); - parent::__construct($message); + return new static($message); } } diff --git a/src/Exception/Regex/IncorrectColorHexLengthException.php b/src/Exception/Regex/IncorrectColorHexLengthException.php index 44c545f..86af0a3 100644 --- a/src/Exception/Regex/IncorrectColorHexLengthException.php +++ b/src/Exception/Regex/IncorrectColorHexLengthException.php @@ -17,16 +17,18 @@ namespace Meritoo\Common\Exception\Regex; class IncorrectColorHexLengthException extends \Exception { /** - * Class constructor + * Creates exception * * @param string $color Incorrect hexadecimal value of color + * @return IncorrectColorHexLengthException */ - public function __construct($color) + public static function create($color) { $template = 'Length of hexadecimal value of color \'%s\' is incorrect. It\'s %d, but it should be 3 or 6.' . ' Is there everything ok?'; $message = sprintf($template, $color, strlen($color)); - parent::__construct($message); + + return new static($message); } } diff --git a/src/Exception/Regex/InvalidColorHexValueException.php b/src/Exception/Regex/InvalidColorHexValueException.php index e20764e..69b1682 100644 --- a/src/Exception/Regex/InvalidColorHexValueException.php +++ b/src/Exception/Regex/InvalidColorHexValueException.php @@ -17,13 +17,15 @@ namespace Meritoo\Common\Exception\Regex; class InvalidColorHexValueException extends \Exception { /** - * Class constructor + * Creates exception * * @param string $color Invalid hexadecimal value of color + * @return InvalidColorHexValueException */ - public function __construct($color) + public static function create($color) { $message = sprintf('Hexadecimal value of color \'%s\' is invalid. Is there everything ok?', $color); - parent::__construct($message); + + return new static($message); } } diff --git a/src/Exception/Regex/InvalidHtmlAttributesException.php b/src/Exception/Regex/InvalidHtmlAttributesException.php index 3b625da..cac3480 100644 --- a/src/Exception/Regex/InvalidHtmlAttributesException.php +++ b/src/Exception/Regex/InvalidHtmlAttributesException.php @@ -17,13 +17,15 @@ namespace Meritoo\Common\Exception\Regex; class InvalidHtmlAttributesException extends \Exception { /** - * Class constructor + * Creates exception * * @param string $htmlAttributes Invalid html attributes + * @return InvalidHtmlAttributesException */ - public function __construct($htmlAttributes) + public static function create($htmlAttributes) { $message = sprintf('HTML attributes \'%s\' are invalid. Is there everything ok?', $htmlAttributes); - parent::__construct($message); + + return new static($message); } } diff --git a/src/Exception/Regex/InvalidUrlException.php b/src/Exception/Regex/InvalidUrlException.php index 69310ec..080fcf7 100644 --- a/src/Exception/Regex/InvalidUrlException.php +++ b/src/Exception/Regex/InvalidUrlException.php @@ -1,5 +1,11 @@ 12) { - throw new UnknownDatePartTypeException(DatePartType::MONTH, $month); + throw UnknownDatePartTypeException::createException(DatePartType::MONTH, $month); } /* * Oops, incorrect day */ if ($day < 1 || $day > 31) { - throw new UnknownDatePartTypeException(DatePartType::DAY, $day); + throw UnknownDatePartTypeException::createException(DatePartType::DAY, $day); } if ($month < 3) { diff --git a/src/Utilities/Reflection.php b/src/Utilities/Reflection.php index 16489bc..9f80b5c 100644 --- a/src/Utilities/Reflection.php +++ b/src/Utilities/Reflection.php @@ -524,7 +524,7 @@ class Reflection * Oops, cannot resolve class */ if (null === $className) { - throw new CannotResolveClassNameException($class); + throw CannotResolveClassNameException::create($class); } $childClasses = []; @@ -558,7 +558,6 @@ class Reflection * * @param array|object|string $parentClass Class who child class should be returned. An array of objects, * namespaces, object or namespace. - * @throws CannotResolveClassNameException * @throws MissingChildClassesException * @throws TooManyChildClassesException * @return mixed @@ -572,7 +571,7 @@ class Reflection * Oops, the base / parent class hasn't child class */ if (empty($childClasses)) { - throw new MissingChildClassesException($parentClass); + throw MissingChildClassesException::create($parentClass); } /* @@ -580,7 +579,7 @@ class Reflection * Oops, the base / parent class has too many child classes */ if (count($childClasses) > 1) { - throw new TooManyChildClassesException($parentClass, $childClasses); + throw TooManyChildClassesException::create($parentClass, $childClasses); } return trim($childClasses[0]); @@ -621,7 +620,6 @@ class Reflection * @param bool $verifyParents If is set to true, parent classes are verified if they use given * trait. Otherwise - not. * @throws CannotResolveClassNameException - * @throws ReflectionException * @return bool|null */ public static function usesTrait($class, $trait, $verifyParents = false) @@ -633,7 +631,7 @@ class Reflection * Oops, cannot resolve class */ if (empty($className)) { - throw new CannotResolveClassNameException($class); + throw CannotResolveClassNameException::create($class); } /* diff --git a/tests/Exception/Base/UnknownTypeExceptionTest.php b/tests/Exception/Base/UnknownTypeExceptionTest.php index e031c2b..c453db6 100644 --- a/tests/Exception/Base/UnknownTypeExceptionTest.php +++ b/tests/Exception/Base/UnknownTypeExceptionTest.php @@ -23,7 +23,7 @@ class UnknownTypeExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(UnknownTestTypeException::class, OopVisibilityType::IS_PUBLIC, 1, 1); + static::assertConstructorVisibilityAndArguments(UnknownTestTypeException::class, OopVisibilityType::IS_PUBLIC, 3); } public function testWithoutException() @@ -60,13 +60,17 @@ class TestType extends BaseType class UnknownTestTypeException extends UnknownTypeException { /** - * Class constructor + * Creates exception * - * @param int|string $unknownType The unknown type of something (for testing purposes) + * @param string $unknownType The unknown type of something (for testing purposes) + * @return UnknownTestTypeException */ - public function __construct($unknownType) + public static function createException($unknownType) { - parent::__construct($unknownType, new TestType(), 'type of something used for testing'); + /* @var UnknownTestTypeException $exception */ + $exception = parent::create($unknownType, new TestType(), 'type of something used for testing'); + + return $exception; } } diff --git a/tests/Exception/Date/UnknownDatePartTypeExceptionTest.php b/tests/Exception/Date/UnknownDatePartTypeExceptionTest.php index 57c6e41..745c481 100644 --- a/tests/Exception/Date/UnknownDatePartTypeExceptionTest.php +++ b/tests/Exception/Date/UnknownDatePartTypeExceptionTest.php @@ -9,7 +9,7 @@ namespace Meritoo\Common\Test\Exception\Date; use Generator; -use Meritoo\Common\Exception\Date\UnknownDatePartTypeException; +use Meritoo\Common\Exception\Type\UnknownDatePartTypeException; use Meritoo\Common\Test\Base\BaseTestCase; use Meritoo\Common\Type\DatePartType; use Meritoo\Common\Type\OopVisibilityType; @@ -24,7 +24,7 @@ class UnknownDatePartTypeExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(UnknownDatePartTypeException::class, OopVisibilityType::IS_PUBLIC, 2, 2); + static::assertConstructorVisibilityAndArguments(UnknownDatePartTypeException::class, OopVisibilityType::IS_PUBLIC, 3); } /** @@ -34,9 +34,9 @@ class UnknownDatePartTypeExceptionTest extends BaseTestCase * * @dataProvider provideDatePartAndValue */ - public function testConstructorMessage($unknownDatePart, $value, $expectedMessage) + public function testMessage($unknownDatePart, $value, $expectedMessage) { - $exception = new UnknownDatePartTypeException($unknownDatePart, $value); + $exception = UnknownDatePartTypeException::createException($unknownDatePart, $value); static::assertEquals($expectedMessage, $exception->getMessage()); } diff --git a/tests/Exception/File/EmptyFileExceptionTest.php b/tests/Exception/File/EmptyFileExceptionTest.php index f3f577f..88aae84 100644 --- a/tests/Exception/File/EmptyFileExceptionTest.php +++ b/tests/Exception/File/EmptyFileExceptionTest.php @@ -23,7 +23,7 @@ class EmptyFileExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(EmptyFileException::class, OopVisibilityType::IS_PUBLIC, 1, 1); + static::assertConstructorVisibilityAndArguments(EmptyFileException::class, OopVisibilityType::IS_PUBLIC, 3); } /** @@ -32,9 +32,9 @@ class EmptyFileExceptionTest extends BaseTestCase * * @dataProvider providePathOfFile */ - public function testConstructorMessage($emptyFilePath, $expectedMessage) + public function testMessage($emptyFilePath, $expectedMessage) { - $exception = new EmptyFileException($emptyFilePath); + $exception = EmptyFileException::create($emptyFilePath); static::assertEquals($expectedMessage, $exception->getMessage()); } diff --git a/tests/Exception/File/EmptyFilePathExceptionTest.php b/tests/Exception/File/EmptyFilePathExceptionTest.php index 7c1bfd2..93cd7ee 100644 --- a/tests/Exception/File/EmptyFilePathExceptionTest.php +++ b/tests/Exception/File/EmptyFilePathExceptionTest.php @@ -22,12 +22,12 @@ class EmptyFilePathExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibilityType::IS_PUBLIC); + static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibilityType::IS_PUBLIC, 3); } public function testConstructorMessage() { - $exception = new EmptyFilePathException(); + $exception = EmptyFilePathException::create(); static::assertEquals('Path of the file is empty. Did you provide path of proper file?', $exception->getMessage()); } } diff --git a/tests/Exception/File/NotExistingFileExceptionTest.php b/tests/Exception/File/NotExistingFileExceptionTest.php index 2c66881..21d7999 100644 --- a/tests/Exception/File/NotExistingFileExceptionTest.php +++ b/tests/Exception/File/NotExistingFileExceptionTest.php @@ -23,7 +23,7 @@ class NotExistingFileExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibilityType::IS_PUBLIC, 1, 1); + static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibilityType::IS_PUBLIC, 3); } /** @@ -34,7 +34,7 @@ class NotExistingFileExceptionTest extends BaseTestCase */ public function testConstructorMessage($notExistingFilePath, $expectedMessage) { - $exception = new NotExistingFileException($notExistingFilePath); + $exception = NotExistingFileException::create($notExistingFilePath); static::assertEquals($expectedMessage, $exception->getMessage()); } diff --git a/tests/Exception/Method/DisabledMethodExceptionTest.php b/tests/Exception/Method/DisabledMethodExceptionTest.php index 042bc42..81854ce 100644 --- a/tests/Exception/Method/DisabledMethodExceptionTest.php +++ b/tests/Exception/Method/DisabledMethodExceptionTest.php @@ -23,7 +23,7 @@ class DisabledMethodExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibilityType::IS_PUBLIC, 2, 1); + static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibilityType::IS_PUBLIC, 3); } /** @@ -36,7 +36,7 @@ class DisabledMethodExceptionTest extends BaseTestCase */ public function testConstructorMessage($disabledMethod, $alternativeMethod, $expectedMessage) { - $exception = new DisabledMethodException($disabledMethod, $alternativeMethod); + $exception = DisabledMethodException::create($disabledMethod, $alternativeMethod); static::assertEquals($expectedMessage, $exception->getMessage()); } diff --git a/tests/Exception/Reflection/CannotResolveClassNameExceptionTest.php b/tests/Exception/Reflection/CannotResolveClassNameExceptionTest.php index 3a99739..880f09e 100644 --- a/tests/Exception/Reflection/CannotResolveClassNameExceptionTest.php +++ b/tests/Exception/Reflection/CannotResolveClassNameExceptionTest.php @@ -23,7 +23,7 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(CannotResolveClassNameException::class, OopVisibilityType::IS_PUBLIC, 2, 1); + static::assertConstructorVisibilityAndArguments(CannotResolveClassNameException::class, OopVisibilityType::IS_PUBLIC, 3); } /** @@ -37,7 +37,7 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase */ public function testConstructorMessage($source, $forClass, $expectedMessage) { - $exception = new CannotResolveClassNameException($source, $forClass); + $exception = CannotResolveClassNameException::create($source, $forClass); static::assertEquals($expectedMessage, $exception->getMessage()); } diff --git a/tests/Exception/Reflection/MissingChildClassesExceptionTest.php b/tests/Exception/Reflection/MissingChildClassesExceptionTest.php index eccf7c1..3ec9f3a 100644 --- a/tests/Exception/Reflection/MissingChildClassesExceptionTest.php +++ b/tests/Exception/Reflection/MissingChildClassesExceptionTest.php @@ -23,7 +23,7 @@ class MissingChildClassesExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(MissingChildClassesException::class, OopVisibilityType::IS_PUBLIC, 1, 1); + static::assertConstructorVisibilityAndArguments(MissingChildClassesException::class, OopVisibilityType::IS_PUBLIC, 3); } /** @@ -35,7 +35,7 @@ class MissingChildClassesExceptionTest extends BaseTestCase */ public function testConstructorMessage($parentClass, $expectedMessage) { - $exception = new MissingChildClassesException($parentClass); + $exception = MissingChildClassesException::create($parentClass); static::assertEquals($expectedMessage, $exception->getMessage()); } diff --git a/tests/Exception/Reflection/TooManyChildClassesExceptionTest.php b/tests/Exception/Reflection/TooManyChildClassesExceptionTest.php index 4448256..3360c4c 100644 --- a/tests/Exception/Reflection/TooManyChildClassesExceptionTest.php +++ b/tests/Exception/Reflection/TooManyChildClassesExceptionTest.php @@ -23,7 +23,7 @@ class TooManyChildClassesExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(TooManyChildClassesException::class, OopVisibilityType::IS_PUBLIC, 2, 2); + static::assertConstructorVisibilityAndArguments(TooManyChildClassesException::class, OopVisibilityType::IS_PUBLIC, 3); } /** @@ -36,7 +36,7 @@ class TooManyChildClassesExceptionTest extends BaseTestCase */ public function testConstructorMessage($parentClass, array $childClasses, $expectedMessage) { - $exception = new TooManyChildClassesException($parentClass, $childClasses); + $exception = TooManyChildClassesException::create($parentClass, $childClasses); static::assertEquals($expectedMessage, $exception->getMessage()); } diff --git a/tests/Exception/Regex/IncorrectColorHexLengthExceptionTest.php b/tests/Exception/Regex/IncorrectColorHexLengthExceptionTest.php index bdf1ea1..1200995 100644 --- a/tests/Exception/Regex/IncorrectColorHexLengthExceptionTest.php +++ b/tests/Exception/Regex/IncorrectColorHexLengthExceptionTest.php @@ -23,7 +23,7 @@ class IncorrectColorHexLengthExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(IncorrectColorHexLengthException::class, OopVisibilityType::IS_PUBLIC, 1, 1); + static::assertConstructorVisibilityAndArguments(IncorrectColorHexLengthException::class, OopVisibilityType::IS_PUBLIC, 3); } /** @@ -34,7 +34,7 @@ class IncorrectColorHexLengthExceptionTest extends BaseTestCase */ public function testConstructorMessage($color, $expectedMessage) { - $exception = new IncorrectColorHexLengthException($color); + $exception = IncorrectColorHexLengthException::create($color); static::assertEquals($expectedMessage, $exception->getMessage()); } diff --git a/tests/Exception/Regex/InvalidColorHexValueExceptionTest.php b/tests/Exception/Regex/InvalidColorHexValueExceptionTest.php index 23d95de..6153f0d 100644 --- a/tests/Exception/Regex/InvalidColorHexValueExceptionTest.php +++ b/tests/Exception/Regex/InvalidColorHexValueExceptionTest.php @@ -10,7 +10,6 @@ namespace Meritoo\Common\Test\Exception\Regex; use Generator; use Meritoo\Common\Exception\Regex\InvalidColorHexValueException; -use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException; use Meritoo\Common\Test\Base\BaseTestCase; use Meritoo\Common\Type\OopVisibilityType; @@ -22,12 +21,9 @@ use Meritoo\Common\Type\OopVisibilityType; */ class InvalidColorHexValueExceptionTest extends BaseTestCase { - /** - * @throws UnknownOopVisibilityTypeException - */ public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 1, 1); + static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 3); } /** @@ -38,7 +34,7 @@ class InvalidColorHexValueExceptionTest extends BaseTestCase */ public function testConstructorMessage($color, $expectedMessage) { - $exception = new InvalidColorHexValueException($color); + $exception = InvalidColorHexValueException::create($color); static::assertEquals($expectedMessage, $exception->getMessage()); } diff --git a/tests/Exception/Regex/InvalidHtmlAttributesExceptionTest.php b/tests/Exception/Regex/InvalidHtmlAttributesExceptionTest.php index 2906fd4..f343830 100644 --- a/tests/Exception/Regex/InvalidHtmlAttributesExceptionTest.php +++ b/tests/Exception/Regex/InvalidHtmlAttributesExceptionTest.php @@ -10,7 +10,6 @@ namespace Meritoo\Common\Test\Exception\Regex; use Generator; use Meritoo\Common\Exception\Regex\InvalidHtmlAttributesException; -use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException; use Meritoo\Common\Test\Base\BaseTestCase; use Meritoo\Common\Type\OopVisibilityType; @@ -22,12 +21,9 @@ use Meritoo\Common\Type\OopVisibilityType; */ class InvalidHtmlAttributesExceptionTest extends BaseTestCase { - /** - * @throws UnknownOopVisibilityTypeException - */ public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(InvalidHtmlAttributesException::class, OopVisibilityType::IS_PUBLIC, 1, 1); + static::assertConstructorVisibilityAndArguments(InvalidHtmlAttributesException::class, OopVisibilityType::IS_PUBLIC, 3); } /** @@ -38,7 +34,7 @@ class InvalidHtmlAttributesExceptionTest extends BaseTestCase */ public function testConstructorMessage($htmlAttributes, $expectedMessage) { - $exception = new InvalidHtmlAttributesException($htmlAttributes); + $exception = InvalidHtmlAttributesException::create($htmlAttributes); static::assertEquals($expectedMessage, $exception->getMessage()); } diff --git a/tests/Exception/Regex/InvalidUrlExceptionTest.php b/tests/Exception/Regex/InvalidUrlExceptionTest.php index 71ab580..1670aca 100644 --- a/tests/Exception/Regex/InvalidUrlExceptionTest.php +++ b/tests/Exception/Regex/InvalidUrlExceptionTest.php @@ -23,7 +23,7 @@ class InvalidUrlExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibilityType::IS_PUBLIC, 1, 1); + static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibilityType::IS_PUBLIC, 3); } /** @@ -34,7 +34,7 @@ class InvalidUrlExceptionTest extends BaseTestCase */ public function testConstructorMessage($url, $expectedMessage) { - $exception = new InvalidUrlException($url); + $exception = InvalidUrlException::create($url); static::assertEquals($expectedMessage, $exception->getMessage()); } diff --git a/tests/Exception/Type/UnknownOopVisibilityTypeExceptionTest.php b/tests/Exception/Type/UnknownOopVisibilityTypeExceptionTest.php index 1231a58..e958a97 100644 --- a/tests/Exception/Type/UnknownOopVisibilityTypeExceptionTest.php +++ b/tests/Exception/Type/UnknownOopVisibilityTypeExceptionTest.php @@ -24,7 +24,7 @@ class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(UnknownOopVisibilityTypeException::class, OopVisibilityType::IS_PUBLIC, 1, 1); + static::assertConstructorVisibilityAndArguments(UnknownOopVisibilityTypeException::class, OopVisibilityType::IS_PUBLIC, 3); } /** @@ -35,7 +35,7 @@ class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase */ public function testConstructorMessage($unknownType, $expectedMessage) { - $exception = new UnknownOopVisibilityTypeException($unknownType); + $exception = UnknownOopVisibilityTypeException::createException($unknownType); static::assertEquals($expectedMessage, $exception->getMessage()); } diff --git a/tests/Utilities/BundleTest.php b/tests/Utilities/BundleTest.php index 099c732..a8fe474 100644 --- a/tests/Utilities/BundleTest.php +++ b/tests/Utilities/BundleTest.php @@ -42,7 +42,6 @@ class BundleTest extends BaseTestCase * @param string $viewPath Path of the view / template, e.g. "MyDirectory/my-template" * @param string $bundleName Full name of the bundle, e.g. "MyExtraBundle" * - * @throws IncorrectBundleNameException * @dataProvider provideViewPathAndIncorrectBundleName */ public function testGetBundleViewPathUsingIncorrectBundleName($viewPath, $bundleName) diff --git a/tests/Utilities/DateTest.php b/tests/Utilities/DateTest.php index 3323161..bcf9cd6 100644 --- a/tests/Utilities/DateTest.php +++ b/tests/Utilities/DateTest.php @@ -11,7 +11,7 @@ namespace Meritoo\Common\Test\Utilities; use DateInterval; use DateTime; use Generator; -use Meritoo\Common\Exception\Date\UnknownDatePartTypeException; +use Meritoo\Common\Exception\Type\UnknownDatePartTypeException; use Meritoo\Common\Test\Base\BaseTestCase; use Meritoo\Common\Type\DatePeriod; use Meritoo\Common\Utilities\Date;