From d801e675fc1a0853cd7fb3f281b7bcd9a328a7aa Mon Sep 17 00:00:00 2001 From: Meritoo Date: Sun, 24 Dec 2017 00:03:23 +0100 Subject: [PATCH] Exception - InvalidHtmlAttributesException - an exception used while html attributes are invalid --- .../Regex/InvalidHtmlAttributesException.php | 29 ++++++++ .../InvalidColorHexValueExceptionTest.php | 4 ++ .../InvalidHtmlAttributesExceptionTest.php | 69 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 src/Exception/Regex/InvalidHtmlAttributesException.php create mode 100644 tests/Exception/Regex/InvalidHtmlAttributesExceptionTest.php diff --git a/src/Exception/Regex/InvalidHtmlAttributesException.php b/src/Exception/Regex/InvalidHtmlAttributesException.php new file mode 100644 index 0000000..a09c9ed --- /dev/null +++ b/src/Exception/Regex/InvalidHtmlAttributesException.php @@ -0,0 +1,29 @@ + + * @copyright Meritoo.pl + */ +class InvalidHtmlAttributesException extends \Exception +{ + /** + * Class constructor + * + * @param string $htmlAttributes Invalid html attributes + */ + public function __construct($htmlAttributes) + { + $message = sprintf('HTML attributes \'%s\' are invalid. Is there everything ok?', $htmlAttributes); + parent::__construct($message); + } +} diff --git a/tests/Exception/Regex/InvalidColorHexValueExceptionTest.php b/tests/Exception/Regex/InvalidColorHexValueExceptionTest.php index 7376676..921ccb3 100644 --- a/tests/Exception/Regex/InvalidColorHexValueExceptionTest.php +++ b/tests/Exception/Regex/InvalidColorHexValueExceptionTest.php @@ -10,6 +10,7 @@ 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; @@ -21,6 +22,9 @@ use Meritoo\Common\Type\OopVisibilityType; */ class InvalidColorHexValueExceptionTest extends BaseTestCase { + /** + * @throws UnknownOopVisibilityTypeException + */ public function testConstructorVisibilityAndArguments() { static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 1, 1); diff --git a/tests/Exception/Regex/InvalidHtmlAttributesExceptionTest.php b/tests/Exception/Regex/InvalidHtmlAttributesExceptionTest.php new file mode 100644 index 0000000..8a067fd --- /dev/null +++ b/tests/Exception/Regex/InvalidHtmlAttributesExceptionTest.php @@ -0,0 +1,69 @@ + + * @copyright Meritoo.pl + */ +class InvalidHtmlAttributesExceptionTest extends BaseTestCase +{ + /** + * @throws UnknownOopVisibilityTypeException + */ + public function testConstructorVisibilityAndArguments() + { + static::assertConstructorVisibilityAndArguments(InvalidHtmlAttributesException::class, OopVisibilityType::IS_PUBLIC, 1, 1); + } + + /** + * @param string $htmlAttributes Invalid html attributes + * @param string $expectedMessage Expected exception's message + * + * @dataProvider provideHtmlAttributes + */ + public function testConstructorMessage($htmlAttributes, $expectedMessage) + { + $exception = new InvalidHtmlAttributesException($htmlAttributes); + static::assertEquals($expectedMessage, $exception->getMessage()); + } + + /** + * Provides html attributes + * + * @return Generator + */ + public function provideHtmlAttributes() + { + $template = 'HTML attributes \'%s\' are invalid. Is there everything ok?'; + + yield[ + 'abc = def', + sprintf($template, 'abc = def'), + ]; + + yield[ + 'abc = def ghi = jkl', + sprintf($template, 'abc = def ghi = jkl'), + ]; + + yield[ + 'abc=def ghi=jkl', + sprintf($template, 'abc=def ghi=jkl'), + ]; + } +}