Reformat code automatically

This commit is contained in:
Meritoo
2022-02-12 14:46:47 +01:00
parent a3af138f0c
commit a3adae50b8
116 changed files with 19152 additions and 19091 deletions

View File

@@ -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());
}
}

View File

@@ -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),
];
}
}

View File

@@ -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),
];
}
}

View File

@@ -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())),
];
}
}

View File

@@ -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),
];
}
}