mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 17:41:50 +01:00
Reformat code automatically
This commit is contained in:
@@ -29,16 +29,16 @@ class UnknownTypeExceptionTest extends BaseTestCase
|
||||
static::assertConstructorVisibilityAndArguments(UnknownTypeException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
|
||||
public function testWithoutException()
|
||||
{
|
||||
self::assertEquals('Test 2', (new TestService())->getTranslatedType('test_2'));
|
||||
}
|
||||
|
||||
public function testTheException()
|
||||
{
|
||||
$this->expectException(UnknownTestTypeException::class);
|
||||
self::assertEmpty((new TestService())->getTranslatedType('test_3'));
|
||||
}
|
||||
|
||||
public function testWithoutException()
|
||||
{
|
||||
self::assertEquals('Test 2', (new TestService())->getTranslatedType('test_2'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,8 +89,8 @@ class TestService
|
||||
* Returns translated type (for testing purposes)
|
||||
*
|
||||
* @param string $type Type of something (for testing purposes)
|
||||
* @throws UnknownTestTypeException
|
||||
* @return string
|
||||
* @throws UnknownTestTypeException
|
||||
*/
|
||||
public function getTranslatedType(string $type): string
|
||||
{
|
||||
|
||||
@@ -20,10 +20,34 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Bundle\IncorrectBundleNameException
|
||||
* @covers \Meritoo\Common\Exception\Bundle\IncorrectBundleNameException
|
||||
*/
|
||||
class IncorrectBundleNameExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideBundleNameAndMessage(): Generator
|
||||
{
|
||||
$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 [
|
||||
'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'),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -45,28 +69,4 @@ class IncorrectBundleNameExceptionTest extends BaseTestCase
|
||||
$exception = IncorrectBundleNameException::create($bundleName);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideBundleNameAndMessage(): Generator
|
||||
{
|
||||
$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[
|
||||
'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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,39 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Type\UnknownDatePartTypeException
|
||||
* @covers \Meritoo\Common\Exception\Type\UnknownDatePartTypeException
|
||||
*/
|
||||
class UnknownDatePartTypeExceptionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides type of date part, incorrect value and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePartAndValue()
|
||||
{
|
||||
$template = 'The \'%s\' type of date part (with value %s) is unknown. Probably doesn\'t exist or there is a'
|
||||
.' typo. You should use one of these types: day, hour, minute, month, second, year.';
|
||||
|
||||
yield [
|
||||
DatePartType::DAY,
|
||||
'44',
|
||||
sprintf($template, DatePartType::DAY, '44'),
|
||||
];
|
||||
|
||||
yield [
|
||||
DatePartType::MONTH,
|
||||
'22',
|
||||
sprintf($template, DatePartType::MONTH, '22'),
|
||||
];
|
||||
|
||||
yield [
|
||||
DatePartType::MINUTE,
|
||||
'77',
|
||||
sprintf($template, DatePartType::MINUTE, '77'),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(UnknownDatePartTypeException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
@@ -42,33 +71,4 @@ class UnknownDatePartTypeExceptionTest extends BaseTestCase
|
||||
$exception = UnknownDatePartTypeException::createException($unknownDatePart, $value);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides type of date part, incorrect value and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePartAndValue()
|
||||
{
|
||||
$template = 'The \'%s\' type of date part (with value %s) is unknown. Probably doesn\'t exist or there is a'
|
||||
. ' typo. You should use one of these types: day, hour, minute, month, second, year.';
|
||||
|
||||
yield[
|
||||
DatePartType::DAY,
|
||||
'44',
|
||||
sprintf($template, DatePartType::DAY, '44'),
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePartType::MONTH,
|
||||
'22',
|
||||
sprintf($template, DatePartType::MONTH, '22'),
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePartType::MINUTE,
|
||||
'77',
|
||||
sprintf($template, DatePartType::MINUTE, '77'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,30 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\File\EmptyFileException
|
||||
* @covers \Meritoo\Common\Exception\File\EmptyFileException
|
||||
*/
|
||||
class EmptyFileExceptionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides path of the empty file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function providePathOfFile()
|
||||
{
|
||||
$template = 'File with path \'%s\' is empty (has no content). Did you provide path of proper file?';
|
||||
|
||||
yield [
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'images/show/car.jpg',
|
||||
sprintf($template, 'images/show/car.jpg'),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(EmptyFileException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
@@ -40,24 +60,4 @@ class EmptyFileExceptionTest extends BaseTestCase
|
||||
$exception = EmptyFileException::create($emptyFilePath);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the empty file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function providePathOfFile()
|
||||
{
|
||||
$template = 'File with path \'%s\' is empty (has no content). Did you provide path of proper file?';
|
||||
|
||||
yield[
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'images/show/car.jpg',
|
||||
sprintf($template, 'images/show/car.jpg'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,18 +19,18 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\File\EmptyFilePathException
|
||||
* @covers \Meritoo\Common\Exception\File\EmptyFilePathException
|
||||
*/
|
||||
class EmptyFilePathExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
|
||||
public function testConstructorMessage()
|
||||
{
|
||||
$exception = EmptyFilePathException::create();
|
||||
static::assertSame('Path of the file is empty. Did you provide path of proper file?', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,28 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\File\NotExistingFileException
|
||||
* @covers \Meritoo\Common\Exception\File\NotExistingFileException
|
||||
*/
|
||||
class NotExistingFileExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
/**
|
||||
* Provides path of not existing file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function providePathOfFile()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
$template = 'File with path \'%s\' does not exist (or is not readable). Did you provide path of proper file?';
|
||||
|
||||
yield [
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'images/show/car.jpg',
|
||||
sprintf($template, 'images/show/car.jpg'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,23 +56,8 @@ class NotExistingFileExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of not existing file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function providePathOfFile()
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$template = 'File with path \'%s\' does not exist (or is not readable). Did you provide path of proper file?';
|
||||
|
||||
yield[
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'images/show/car.jpg',
|
||||
sprintf($template, 'images/show/car.jpg'),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,31 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Method\DisabledMethodException
|
||||
* @covers \Meritoo\Common\Exception\Method\DisabledMethodException
|
||||
*/
|
||||
class DisabledMethodExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
/**
|
||||
* Provides name of the disabled method, name of the alternative method and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMethodsNames()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
$templateShort = 'Method %s() cannot be called, because is disabled.';
|
||||
$templateLong = $templateShort.' Use %s() instead.';
|
||||
|
||||
yield [
|
||||
'FooBar::loremIpsum',
|
||||
'',
|
||||
sprintf($templateShort, 'FooBar::loremIpsum'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'FooBar::loremIpsum',
|
||||
'AnotherClass::alternativeMethod',
|
||||
sprintf($templateLong, 'FooBar::loremIpsum', 'AnotherClass::alternativeMethod'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,26 +61,8 @@ class DisabledMethodExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of the disabled method, name of the alternative method and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideMethodsNames()
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$templateShort = 'Method %s() cannot be called, because is disabled.';
|
||||
$templateLong = $templateShort . ' Use %s() instead.';
|
||||
|
||||
yield[
|
||||
'FooBar::loremIpsum',
|
||||
'',
|
||||
sprintf($templateShort, 'FooBar::loremIpsum'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'FooBar::loremIpsum',
|
||||
'AnotherClass::alternativeMethod',
|
||||
sprintf($templateLong, 'FooBar::loremIpsum', 'AnotherClass::alternativeMethod'),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,33 @@ use stdClass;
|
||||
*/
|
||||
class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides source of the class's / trait's name, information if message of this exception should be prepared for
|
||||
* class and the expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideClassName(): Generator
|
||||
{
|
||||
yield [
|
||||
'Not\Existing\Class',
|
||||
true,
|
||||
'Name of class from given \'string\' Not\Existing\Class cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
|
||||
yield [
|
||||
'Not\Existing\Trait',
|
||||
false,
|
||||
'Name of trait from given \'string\' Not\Existing\Trait cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
|
||||
yield [
|
||||
stdClass::class,
|
||||
true,
|
||||
'Name of class from given \'string\' stdClass cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -34,14 +61,6 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateUsingDefaults(): void
|
||||
{
|
||||
$exception = CannotResolveClassNameException::create(stdClass::class);
|
||||
$expectedMessage = 'Name of class from given \'string\' stdClass cannot be resolved. Is there everything ok?';
|
||||
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source Source of name of the class or trait
|
||||
* @param bool $forClass (optional) If is set to true, message of this exception for class is prepared.
|
||||
@@ -56,30 +75,11 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides source of the class's / trait's name, information if message of this exception should be prepared for
|
||||
* class and the expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideClassName(): Generator
|
||||
public function testCreateUsingDefaults(): void
|
||||
{
|
||||
yield[
|
||||
'Not\Existing\Class',
|
||||
true,
|
||||
'Name of class from given \'string\' Not\Existing\Class cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
$exception = CannotResolveClassNameException::create(stdClass::class);
|
||||
$expectedMessage = 'Name of class from given \'string\' stdClass cannot be resolved. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
'Not\Existing\Trait',
|
||||
false,
|
||||
'Name of trait from given \'string\' Not\Existing\Trait cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
|
||||
yield[
|
||||
stdClass::class,
|
||||
true,
|
||||
'Name of class from given \'string\' stdClass cannot be resolved. Is there everything ok?',
|
||||
];
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,23 @@ use Meritoo\Common\Utilities\Arrays;
|
||||
*/
|
||||
class ClassWithoutConstructorExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideClassName(): Generator
|
||||
{
|
||||
$template = 'Oops, class \'%s\' hasn\'t constructor. Did you use proper class?';
|
||||
|
||||
yield [
|
||||
'An empty name of class',
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield [
|
||||
'The Arrays class',
|
||||
Arrays::class,
|
||||
sprintf($template, Arrays::class),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -46,21 +63,4 @@ class ClassWithoutConstructorExceptionTest extends BaseTestCase
|
||||
$exception = ClassWithoutConstructorException::create($className);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideClassName(): Generator
|
||||
{
|
||||
$template = 'Oops, class \'%s\' hasn\'t constructor. Did you use proper class?';
|
||||
|
||||
yield[
|
||||
'An empty name of class',
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
'The Arrays class',
|
||||
Arrays::class,
|
||||
sprintf($template, Arrays::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\MissingChildClassesException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while given class has no child classes
|
||||
@@ -24,6 +25,30 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class MissingChildClassesExceptionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides name of class that hasn't child classes, but it should, and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentClass(): ?Generator
|
||||
{
|
||||
$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?';
|
||||
|
||||
yield [
|
||||
MissingChildClassesException::class,
|
||||
sprintf($template, MissingChildClassesException::class),
|
||||
];
|
||||
|
||||
yield [
|
||||
[
|
||||
new stdClass(),
|
||||
new stdClass(),
|
||||
],
|
||||
sprintf($template, stdClass::class),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -45,28 +70,4 @@ class MissingChildClassesExceptionTest extends BaseTestCase
|
||||
$exception = MissingChildClassesException::create($parentClass);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of class that hasn't child classes, but it should, and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentClass(): ?Generator
|
||||
{
|
||||
$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?';
|
||||
|
||||
yield[
|
||||
MissingChildClassesException::class,
|
||||
sprintf($template, MissingChildClassesException::class),
|
||||
];
|
||||
|
||||
yield[
|
||||
[
|
||||
new \stdClass(),
|
||||
new \stdClass(),
|
||||
],
|
||||
sprintf($template, \stdClass::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@
|
||||
|
||||
namespace Meritoo\Test\Common\Exception\Reflection;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\NotExistingPropertyException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class NotExistingPropertyExceptionTest
|
||||
@@ -23,6 +25,39 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class NotExistingPropertyExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideObjectPropertyAndMessage(): ?Generator
|
||||
{
|
||||
$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())),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -45,37 +80,4 @@ class NotExistingPropertyExceptionTest extends BaseTestCase
|
||||
$exception = NotExistingPropertyException::create($object, $property);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideObjectPropertyAndMessage(): ?\Generator
|
||||
{
|
||||
$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())),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\TooManyChildClassesException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while given class has more than one child class
|
||||
@@ -24,6 +25,38 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class TooManyChildClassesExceptionTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Provides name of class that has more than one child class, but it shouldn't, child classes, and expected
|
||||
* exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentAndChildClasses(): ?Generator
|
||||
{
|
||||
$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?";
|
||||
|
||||
yield [
|
||||
BaseTestCase::class,
|
||||
[
|
||||
stdClass::class,
|
||||
OopVisibilityType::class,
|
||||
],
|
||||
sprintf($template, BaseTestCase::class, implode("\n- ", [
|
||||
stdClass::class,
|
||||
OopVisibilityType::class,
|
||||
]), BaseTestCase::class),
|
||||
];
|
||||
|
||||
yield [
|
||||
TooManyChildClassesException::class,
|
||||
[
|
||||
stdClass::class,
|
||||
],
|
||||
sprintf($template, TooManyChildClassesException::class, implode("\n- ", [stdClass::class]), TooManyChildClassesException::class),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -46,36 +79,4 @@ class TooManyChildClassesExceptionTest extends BaseTestCase
|
||||
$exception = TooManyChildClassesException::create($parentClass, $childClasses);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides name of class that has more than one child class, but it shouldn't, child classes, and expected
|
||||
* exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentAndChildClasses(): ?Generator
|
||||
{
|
||||
$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?";
|
||||
|
||||
yield[
|
||||
BaseTestCase::class,
|
||||
[
|
||||
\stdClass::class,
|
||||
OopVisibilityType::class,
|
||||
],
|
||||
sprintf($template, BaseTestCase::class, implode("\n- ", [
|
||||
\stdClass::class,
|
||||
OopVisibilityType::class,
|
||||
]), BaseTestCase::class),
|
||||
];
|
||||
|
||||
yield[
|
||||
TooManyChildClassesException::class,
|
||||
[
|
||||
\stdClass::class,
|
||||
],
|
||||
sprintf($template, TooManyChildClassesException::class, implode("\n- ", [\stdClass::class]), TooManyChildClassesException::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,28 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Regex\IncorrectColorHexLengthException
|
||||
* @covers \Meritoo\Common\Exception\Regex\IncorrectColorHexLengthException
|
||||
*/
|
||||
class IncorrectColorHexLengthExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
/**
|
||||
* Provides incorrect hexadecimal value of color and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideColor()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(IncorrectColorHexLengthException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
$template = 'Length of hexadecimal value of color \'%s\' is incorrect. It\'s %d, but it should be 3 or 6. Is there everything ok?';
|
||||
|
||||
yield [
|
||||
'',
|
||||
sprintf($template, '', strlen('')),
|
||||
];
|
||||
|
||||
yield [
|
||||
'aa-bb-cc',
|
||||
sprintf($template, 'aa-bb-cc', strlen('aa-bb-cc')),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,23 +56,8 @@ class IncorrectColorHexLengthExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides incorrect hexadecimal value of color and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideColor()
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$template = 'Length of hexadecimal value of color \'%s\' is incorrect. It\'s %d, but it should be 3 or 6. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
'',
|
||||
sprintf($template, '', strlen('')),
|
||||
];
|
||||
|
||||
yield[
|
||||
'aa-bb-cc',
|
||||
sprintf($template, 'aa-bb-cc', strlen('aa-bb-cc')),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(IncorrectColorHexLengthException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,28 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Regex\InvalidColorHexValueException
|
||||
* @covers \Meritoo\Common\Exception\Regex\InvalidColorHexValueException
|
||||
*/
|
||||
class InvalidColorHexValueExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
/**
|
||||
* Provides invalid hexadecimal value of color and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideColor()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
$template = 'Hexadecimal value of color \'%s\' is invalid. Is there everything ok?';
|
||||
|
||||
yield [
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield [
|
||||
'aa-bb-cc',
|
||||
sprintf($template, 'aa-bb-cc'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,23 +56,8 @@ class InvalidColorHexValueExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides invalid hexadecimal value of color and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideColor()
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$template = 'Hexadecimal value of color \'%s\' is invalid. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
'aa-bb-cc',
|
||||
sprintf($template, 'aa-bb-cc'),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,33 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Regex\InvalidHtmlAttributesException
|
||||
* @covers \Meritoo\Common\Exception\Regex\InvalidHtmlAttributesException
|
||||
*/
|
||||
class InvalidHtmlAttributesExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
/**
|
||||
* Provides html attributes
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideHtmlAttributes()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(InvalidHtmlAttributesException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
$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'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,28 +61,8 @@ class InvalidHtmlAttributesExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides html attributes
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideHtmlAttributes()
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$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'),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(InvalidHtmlAttributesException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,28 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Regex\InvalidUrlException
|
||||
* @covers \Meritoo\Common\Exception\Regex\InvalidUrlException
|
||||
*/
|
||||
class InvalidUrlExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
/**
|
||||
* Provides invalid url and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUrl()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
$template = 'Url \'%s\' is invalid. Is there everything ok?';
|
||||
|
||||
yield [
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'http:/images\show\car.jpg',
|
||||
sprintf($template, 'http:/images\show\car.jpg'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,23 +56,8 @@ class InvalidUrlExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides invalid url and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUrl()
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
$template = 'Url \'%s\' is invalid. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
'aa/bb/cc',
|
||||
sprintf($template, 'aa/bb/cc'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'http:/images\show\car.jpg',
|
||||
sprintf($template, 'http:/images\show\car.jpg'),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,13 +25,27 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
/**
|
||||
* Provides path of the empty file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUnknownType(): Generator
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
UnknownOopVisibilityTypeException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
$allTypes = (new OopVisibilityType())->getAll();
|
||||
|
||||
$template = 'The \'%s\' type of OOP-related visibility is unknown. Probably doesn\'t exist or there is a typo.'
|
||||
.' You should use one of these types: %s.';
|
||||
|
||||
yield [
|
||||
'',
|
||||
sprintf($template, '', implode(', ', $allTypes)),
|
||||
];
|
||||
|
||||
yield [
|
||||
123,
|
||||
sprintf($template, 123, implode(', ', $allTypes)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,26 +60,12 @@ class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides path of the empty file and expected exception's message
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUnknownType(): Generator
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
$allTypes = (new OopVisibilityType())->getAll();
|
||||
|
||||
$template = 'The \'%s\' type of OOP-related visibility is unknown. Probably doesn\'t exist or there is a typo.'
|
||||
. ' You should use one of these types: %s.';
|
||||
|
||||
yield[
|
||||
'',
|
||||
sprintf($template, '', implode(', ', $allTypes)),
|
||||
];
|
||||
|
||||
yield[
|
||||
123,
|
||||
sprintf($template, 123, implode(', ', $allTypes)),
|
||||
];
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
UnknownOopVisibilityTypeException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,33 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\ValueObject\InvalidSizeDimensionsException
|
||||
* @covers \Meritoo\Common\Exception\ValueObject\InvalidSizeDimensionsException
|
||||
*/
|
||||
class InvalidSizeDimensionsExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideWidthAndHeight()
|
||||
{
|
||||
$template = 'Dimensions of size should be positive, but they are not: %d, %d. Is there everything ok?';
|
||||
|
||||
yield [
|
||||
0,
|
||||
0,
|
||||
sprintf($template, 0, 0),
|
||||
];
|
||||
|
||||
yield [
|
||||
-1,
|
||||
-1,
|
||||
sprintf($template, -1, -1),
|
||||
];
|
||||
|
||||
yield [
|
||||
200,
|
||||
100,
|
||||
sprintf($template, 200, 100),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -44,27 +67,4 @@ class InvalidSizeDimensionsExceptionTest extends BaseTestCase
|
||||
$exception = InvalidSizeDimensionsException::create($width, $height);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
}
|
||||
|
||||
public function provideWidthAndHeight()
|
||||
{
|
||||
$template = 'Dimensions of size should be positive, but they are not: %d, %d. Is there everything ok?';
|
||||
|
||||
yield[
|
||||
0,
|
||||
0,
|
||||
sprintf($template, 0, 0),
|
||||
];
|
||||
|
||||
yield[
|
||||
-1,
|
||||
-1,
|
||||
sprintf($template, -1, -1),
|
||||
];
|
||||
|
||||
yield[
|
||||
200,
|
||||
100,
|
||||
sprintf($template, 200, 100),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,29 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class InvalidContentExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideContent(): ?Generator
|
||||
{
|
||||
$template = 'Content of template \'%s\' is invalid. Did you use string with 1 placeholder at least?';
|
||||
|
||||
yield [
|
||||
'An empty string',
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield [
|
||||
'Simple string',
|
||||
'Lorem ipsum',
|
||||
sprintf($template, 'Lorem ipsum'),
|
||||
];
|
||||
|
||||
yield [
|
||||
'One sentence',
|
||||
'Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.',
|
||||
sprintf($template, 'Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.'),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -45,27 +68,4 @@ class InvalidContentExceptionTest extends BaseTestCase
|
||||
$exception = InvalidContentException::create($content);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideContent(): ?Generator
|
||||
{
|
||||
$template = 'Content of template \'%s\' is invalid. Did you use string with 1 placeholder at least?';
|
||||
|
||||
yield[
|
||||
'An empty string',
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Simple string',
|
||||
'Lorem ipsum',
|
||||
sprintf($template, 'Lorem ipsum'),
|
||||
];
|
||||
|
||||
yield[
|
||||
'One sentence',
|
||||
'Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.',
|
||||
sprintf($template, 'Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
namespace Meritoo\Test\Common\Exception\ValueObject\Template;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\ValueObject\Template\MissingPlaceholdersInValuesException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
@@ -23,6 +24,39 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class MissingPlaceholdersInValuesExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideContentAndMissingPlaceholders(): ?Generator
|
||||
{
|
||||
$template = 'Cannot fill template \'%s\', because of missing values for placeholder(s): %s. Did you provide all'
|
||||
.' required values?';
|
||||
|
||||
yield [
|
||||
'Missing 2nd placeholder',
|
||||
'%test1% - %test2%',
|
||||
[
|
||||
'test2',
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% - %test2%',
|
||||
'test2'
|
||||
),
|
||||
];
|
||||
|
||||
yield [
|
||||
'Missing 2nd and 3rd placeholder',
|
||||
'%test1% / %test2% / %test3%',
|
||||
[
|
||||
'test2',
|
||||
'test3',
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% / %test2% / %test3%',
|
||||
'test2, test3'
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -49,37 +83,4 @@ class MissingPlaceholdersInValuesExceptionTest extends BaseTestCase
|
||||
$exception = MissingPlaceholdersInValuesException::create($content, $missingPlaceholders);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideContentAndMissingPlaceholders(): ?\Generator
|
||||
{
|
||||
$template = 'Cannot fill template \'%s\', because of missing values for placeholder(s): %s. Did you provide all'
|
||||
. ' required values?';
|
||||
|
||||
yield[
|
||||
'Missing 2nd placeholder',
|
||||
'%test1% - %test2%',
|
||||
[
|
||||
'test2',
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% - %test2%',
|
||||
'test2'
|
||||
),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Missing 2nd and 3rd placeholder',
|
||||
'%test1% / %test2% / %test3%',
|
||||
[
|
||||
'test2',
|
||||
'test3',
|
||||
],
|
||||
sprintf(
|
||||
$template,
|
||||
'%test1% / %test2% / %test3%',
|
||||
'test2, test3'
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,29 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class TemplateNotFoundExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function provideIndexAndException(): ?Generator
|
||||
{
|
||||
$template = 'Template with \'%s\' index was not found. Did you provide all required templates?';
|
||||
|
||||
yield [
|
||||
'An empty string',
|
||||
'',
|
||||
new TemplateNotFoundException(sprintf($template, '')),
|
||||
];
|
||||
|
||||
yield [
|
||||
'Non-empty string',
|
||||
'test',
|
||||
new TemplateNotFoundException(sprintf($template, 'test')),
|
||||
];
|
||||
|
||||
yield [
|
||||
'Integer',
|
||||
'2',
|
||||
new TemplateNotFoundException(sprintf($template, 2)),
|
||||
];
|
||||
}
|
||||
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
@@ -45,27 +68,4 @@ class TemplateNotFoundExceptionTest extends BaseTestCase
|
||||
$created = TemplateNotFoundException::create($index);
|
||||
static::assertEquals($expected, $created, $description);
|
||||
}
|
||||
|
||||
public function provideIndexAndException(): ?Generator
|
||||
{
|
||||
$template = 'Template with \'%s\' index was not found. Did you provide all required templates?';
|
||||
|
||||
yield[
|
||||
'An empty string',
|
||||
'',
|
||||
new TemplateNotFoundException(sprintf($template, '')),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Non-empty string',
|
||||
'test',
|
||||
new TemplateNotFoundException(sprintf($template, 'test')),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Integer',
|
||||
'2',
|
||||
new TemplateNotFoundException(sprintf($template, 2)),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user