mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 17:41:50 +01:00
Fix code pointed by Psalm
This commit is contained in:
@@ -12,6 +12,7 @@ use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while name of class or trait cannot be resolved
|
||||
@@ -20,13 +21,17 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Reflection\CannotResolveClassNameException
|
||||
* @covers \Meritoo\Common\Exception\Reflection\CannotResolveClassNameException
|
||||
*/
|
||||
class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(CannotResolveClassNameException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
CannotResolveClassNameException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +43,7 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideClassName
|
||||
*/
|
||||
public function testConstructorMessage($source, $forClass, $expectedMessage)
|
||||
public function testCreate($source, bool $forClass, string $expectedMessage): void
|
||||
{
|
||||
$exception = CannotResolveClassNameException::create($source, $forClass);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
@@ -50,7 +55,7 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideClassName()
|
||||
public function provideClassName(): Generator
|
||||
{
|
||||
yield[
|
||||
'Not\Existing\Class',
|
||||
@@ -66,8 +71,8 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
|
||||
yield[
|
||||
[
|
||||
new \stdClass(),
|
||||
new \stdClass(),
|
||||
new stdClass(),
|
||||
new stdClass(),
|
||||
],
|
||||
true,
|
||||
'Name of class from given \'array\' cannot be resolved. Is there everything ok?',
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Test\Common\Exception\Reflection;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\ClassWithoutConstructorException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\Common\Utilities\Arrays;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while given class hasn't constructor
|
||||
*
|
||||
* @author Meritoo <github@meritoo.pl>
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Reflection\ClassWithoutConstructorException
|
||||
*/
|
||||
class ClassWithoutConstructorExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
ClassWithoutConstructorException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description Description of test case
|
||||
* @param string $className Fully-qualified name of class that hasn't constructor
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideClassName
|
||||
*/
|
||||
public function testCreate(string $description, string $className, string $expectedMessage): void
|
||||
{
|
||||
$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),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -20,13 +20,17 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Reflection\MissingChildClassesException
|
||||
* @covers \Meritoo\Common\Exception\Reflection\MissingChildClassesException
|
||||
*/
|
||||
class MissingChildClassesExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(MissingChildClassesException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
MissingChildClassesException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +40,7 @@ class MissingChildClassesExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideParentClass
|
||||
*/
|
||||
public function testConstructorMessage($parentClass, $expectedMessage)
|
||||
public function testCreate($parentClass, string $expectedMessage): void
|
||||
{
|
||||
$exception = MissingChildClassesException::create($parentClass);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
@@ -47,7 +51,7 @@ class MissingChildClassesExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentClass()
|
||||
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?';
|
||||
|
||||
@@ -19,11 +19,11 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Reflection\NotExistingPropertyException
|
||||
* @covers \Meritoo\Common\Exception\Reflection\NotExistingPropertyException
|
||||
*/
|
||||
class NotExistingPropertyExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
NotExistingPropertyException::class,
|
||||
@@ -33,20 +33,20 @@ class NotExistingPropertyExceptionTest extends BaseTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @param string $description Description of test
|
||||
* @param mixed $object Object that should contains given property
|
||||
* @param null|string $property Name of the property
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideObjectPropertyAndMessage
|
||||
*/
|
||||
public function testCreate($description, $object, $property, $expectedMessage)
|
||||
public function testCreate(string $description, $object, ?string $property, string $expectedMessage): void
|
||||
{
|
||||
$exception = NotExistingPropertyException::create($object, $property);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideObjectPropertyAndMessage()
|
||||
public function provideObjectPropertyAndMessage(): ?\Generator
|
||||
{
|
||||
$template = 'Property \'%s\' does not exist in instance of class \'%s\'. Did you use proper name of property?';
|
||||
|
||||
|
||||
@@ -20,13 +20,17 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Reflection\TooManyChildClassesException
|
||||
* @covers \Meritoo\Common\Exception\Reflection\TooManyChildClassesException
|
||||
*/
|
||||
class TooManyChildClassesExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(TooManyChildClassesException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
TooManyChildClassesException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +41,7 @@ class TooManyChildClassesExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideParentAndChildClasses
|
||||
*/
|
||||
public function testConstructorMessage($parentClass, array $childClasses, $expectedMessage)
|
||||
public function testCreate($parentClass, array $childClasses, string $expectedMessage): void
|
||||
{
|
||||
$exception = TooManyChildClassesException::create($parentClass, $childClasses);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
@@ -49,7 +53,7 @@ class TooManyChildClassesExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentAndChildClasses()
|
||||
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?";
|
||||
|
||||
Reference in New Issue
Block a user