diff --git a/tests/Exception/Bundle/IncorrectBundleNameExceptionTest.php b/tests/Exception/Bundle/IncorrectBundleNameExceptionTest.php new file mode 100644 index 0000000..3899331 --- /dev/null +++ b/tests/Exception/Bundle/IncorrectBundleNameExceptionTest.php @@ -0,0 +1,74 @@ + + * @copyright Meritoo + */ +class IncorrectBundleNameExceptionTest extends BaseTestCase +{ + public function testConstructor() + { + static::assertConstructorVisibilityAndArguments( + IncorrectBundleNameException::class, + OopVisibilityType::IS_PUBLIC, + 3 + ); + } + + /** + * @param string $description Description of test + * @param string $bundleName Incorrect name of bundle + * @param string $expectedMessage Expected exception's message + * + * @dataProvider provideBundleNameAndMessage + */ + public function testCreate($description, $bundleName, $expectedMessage) + { + $exception = IncorrectBundleNameException::create($bundleName); + static::assertSame($expectedMessage, $exception->getMessage(), $description); + } + + public function provideBundleNameAndMessage() + { + $template = 'Name of bundle \'%s\' is incorrect. It should start with big letter and end with "Bundle". Is' + . ' there everything ok?'; + + yield[ + 'An empty string as name of bundle', + '', + sprintf($template, ''), + ]; + + yield[ + 'Null as name of bundle', + null, + sprintf($template, ''), + ]; + + yield[ + 'String with spaces as name of bundle', + 'This is test', + sprintf($template, 'This is test'), + ]; + + yield[ + 'String without spaces as name of bundle', + 'ThisIsTest', + sprintf($template, 'ThisIsTest'), + ]; + } +} diff --git a/tests/Exception/Reflection/NotExistingPropertyExceptionTest.php b/tests/Exception/Reflection/NotExistingPropertyExceptionTest.php new file mode 100644 index 0000000..502a248 --- /dev/null +++ b/tests/Exception/Reflection/NotExistingPropertyExceptionTest.php @@ -0,0 +1,78 @@ + + * @copyright Meritoo + */ +class NotExistingPropertyExceptionTest extends BaseTestCase +{ + public function testConstructor() + { + static::assertConstructorVisibilityAndArguments( + NotExistingPropertyException::class, + OopVisibilityType::IS_PUBLIC, + 3 + ); + } + + /** + * @param string $description Description of test + * @param mixed $object Object that should contains given property + * @param string $property Name of the property + * @param string $expectedMessage Expected exception's message + * + * @dataProvider provideObjectPropertyAndMessage + */ + public function testCreate($description, $object, $property, $expectedMessage) + { + $exception = NotExistingPropertyException::create($object, $property); + static::assertSame($expectedMessage, $exception->getMessage(), $description); + } + + public function provideObjectPropertyAndMessage() + { + $template = 'Property \'%s\' does not exist in instance of class \'%s\'. Did you use proper name of property?'; + + yield[ + 'An empty string as name of property', + new \stdClass(), + '', + sprintf($template, '', get_class(new \stdClass())), + ]; + + yield[ + 'Null as name of property', + new \stdClass(), + null, + sprintf($template, '', get_class(new \stdClass())), + ]; + + yield[ + 'String with spaces as name of property', + new \stdClass(), + 'This is test', + sprintf($template, 'This is test', get_class(new \stdClass())), + ]; + + yield[ + 'String without spaces as name of property', + new \stdClass(), + 'ThisIsTest', + sprintf($template, 'ThisIsTest', get_class(new \stdClass())), + ]; + } +}