mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Minor refactoring
This commit is contained in:
@@ -23,7 +23,7 @@ use Meritoo\Common\Type\Base\BaseType;
|
|||||||
*/
|
*/
|
||||||
class BaseTypeTest extends BaseTestCase
|
class BaseTypeTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testConstructor()
|
public function testConstructor(): void
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(BaseType::class);
|
static::assertHasNoConstructor(BaseType::class);
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ class BaseTypeTest extends BaseTestCase
|
|||||||
*
|
*
|
||||||
* @dataProvider provideType
|
* @dataProvider provideType
|
||||||
*/
|
*/
|
||||||
public function testGetAll(BaseType $type, array $expectedTypes)
|
public function testGetAll(BaseType $type, array $expectedTypes): void
|
||||||
{
|
{
|
||||||
$all = $type->getAll();
|
$all = $type->getAll();
|
||||||
self::assertEquals($expectedTypes, $all);
|
self::assertEquals($expectedTypes, $all);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class DatePeriodTest extends BaseTypeTestCase
|
|||||||
*
|
*
|
||||||
* @dataProvider provideDatePeriodAndIncorrectDateFormat
|
* @dataProvider provideDatePeriodAndIncorrectDateFormat
|
||||||
*/
|
*/
|
||||||
public function testGetFormattedDateIncorrectDateFormat(DatePeriod $period, $format): void
|
public function testGetFormattedDateUsingIncorrectDateFormat(DatePeriod $period, $format): void
|
||||||
{
|
{
|
||||||
self::assertEquals('', $period->getFormattedDate($format));
|
self::assertEquals('', $period->getFormattedDate($format));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use Meritoo\Test\Common\Utilities\Reflection\H;
|
|||||||
use Meritoo\Test\Common\Utilities\Reflection\I;
|
use Meritoo\Test\Common\Utilities\Reflection\I;
|
||||||
use Meritoo\Test\Common\Utilities\Reflection\J;
|
use Meritoo\Test\Common\Utilities\Reflection\J;
|
||||||
use ReflectionProperty;
|
use ReflectionProperty;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case of the useful reflection methods
|
* Test case of the useful reflection methods
|
||||||
@@ -40,7 +41,7 @@ use ReflectionProperty;
|
|||||||
*/
|
*/
|
||||||
class ReflectionTest extends BaseTestCase
|
class ReflectionTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testConstructor()
|
public function testConstructor(): void
|
||||||
{
|
{
|
||||||
static::assertHasNoConstructor(Reflection::class);
|
static::assertHasNoConstructor(Reflection::class);
|
||||||
}
|
}
|
||||||
@@ -82,7 +83,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
public function testGetClassWhileNamespaceContainsClassName(): void
|
public function testGetClassWhileNamespaceContainsClassName(): void
|
||||||
{
|
{
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
'Meritoo\Common\Collection\Collection',
|
Collection::class,
|
||||||
Reflection::getClassName(Collection::class)
|
Reflection::getClassName(Collection::class)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
/**
|
/**
|
||||||
* A case when namespace of class contains name of class (name of class is duplicated, occurs twice)
|
* A case when namespace of class contains name of class (name of class is duplicated, occurs twice)
|
||||||
*/
|
*/
|
||||||
public function testGetClassNamespaceWhileNamespaceContainsClassName()
|
public function testGetClassNamespaceWhileNamespaceContainsClassName(): void
|
||||||
{
|
{
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
'Meritoo\Common\Collection',
|
'Meritoo\Common\Collection',
|
||||||
@@ -133,13 +134,13 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertNull(Reflection::getChildClasses(123));
|
self::assertNull(Reflection::getChildClasses(123));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetChildClassesNotExistingClass()
|
public function testGetChildClassesNotExistingClass(): void
|
||||||
{
|
{
|
||||||
$this->expectException(CannotResolveClassNameException::class);
|
$this->expectException(CannotResolveClassNameException::class);
|
||||||
self::assertEquals('', Reflection::getChildClasses('xyz'));
|
self::assertEquals('', Reflection::getChildClasses('xyz'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetChildClassesExistingClass()
|
public function testGetChildClassesExistingClass(): void
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Attention. I have to create instances of these classes to load them and be available while using
|
* Attention. I have to create instances of these classes to load them and be available while using
|
||||||
@@ -164,13 +165,13 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertEquals($effect, Reflection::getChildClasses(A::class));
|
self::assertEquals($effect, Reflection::getChildClasses(A::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetOneChildClassWithMissingChildClasses()
|
public function testGetOneChildClassWithMissingChildClasses(): void
|
||||||
{
|
{
|
||||||
$this->expectException(MissingChildClassesException::class);
|
$this->expectException(MissingChildClassesException::class);
|
||||||
self::assertEquals('LoremIpsum', Reflection::getOneChildClass(C::class));
|
self::assertEquals('LoremIpsum', Reflection::getOneChildClass(C::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetOneChildClassWithTooManyChildClasses()
|
public function testGetOneChildClassWithTooManyChildClasses(): void
|
||||||
{
|
{
|
||||||
// Required to get all classes by get_declared_classes() function and avoid failure:
|
// Required to get all classes by get_declared_classes() function and avoid failure:
|
||||||
//
|
//
|
||||||
@@ -182,7 +183,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
Reflection::getOneChildClass(A::class);
|
Reflection::getOneChildClass(A::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetOneChildClass()
|
public function testGetOneChildClass(): void
|
||||||
{
|
{
|
||||||
// Required to get all classes by get_declared_classes() function and avoid throw of
|
// Required to get all classes by get_declared_classes() function and avoid throw of
|
||||||
// Meritoo\Common\Exception\Reflection\MissingChildClassesException exception
|
// Meritoo\Common\Exception\Reflection\MissingChildClassesException exception
|
||||||
@@ -191,7 +192,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertEquals(C::class, Reflection::getOneChildClass(B::class));
|
self::assertEquals(C::class, Reflection::getOneChildClass(B::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetMethods()
|
public function testGetMethods(): void
|
||||||
{
|
{
|
||||||
self::assertCount(1, Reflection::getMethods(B::class, true));
|
self::assertCount(1, Reflection::getMethods(B::class, true));
|
||||||
self::assertCount(3, Reflection::getMethods(B::class));
|
self::assertCount(3, Reflection::getMethods(B::class));
|
||||||
@@ -216,13 +217,13 @@ class ReflectionTest extends BaseTestCase
|
|||||||
* @param mixed $trait Empty value, e.g. ""
|
* @param mixed $trait Empty value, e.g. ""
|
||||||
* @dataProvider provideEmptyValue
|
* @dataProvider provideEmptyValue
|
||||||
*/
|
*/
|
||||||
public function testUsesTraitInvalidTrait($trait)
|
public function testUsesTraitInvalidTrait($trait): void
|
||||||
{
|
{
|
||||||
$this->expectException(CannotResolveClassNameException::class);
|
$this->expectException(CannotResolveClassNameException::class);
|
||||||
self::assertNull(Reflection::usesTrait(DateTime::class, $trait));
|
self::assertNull(Reflection::usesTrait(DateTime::class, $trait));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUsesTraitExistingClass()
|
public function testUsesTraitExistingClass(): void
|
||||||
{
|
{
|
||||||
self::assertTrue(Reflection::usesTrait(A::class, E::class));
|
self::assertTrue(Reflection::usesTrait(A::class, E::class));
|
||||||
self::assertFalse(Reflection::usesTrait(B::class, E::class));
|
self::assertFalse(Reflection::usesTrait(B::class, E::class));
|
||||||
@@ -230,7 +231,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertFalse(Reflection::usesTrait(D::class, E::class));
|
self::assertFalse(Reflection::usesTrait(D::class, E::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUsesTraitExistingClassAndVerifyParents()
|
public function testUsesTraitExistingClassAndVerifyParents(): void
|
||||||
{
|
{
|
||||||
self::assertTrue(Reflection::usesTrait(A::class, E::class, true));
|
self::assertTrue(Reflection::usesTrait(A::class, E::class, true));
|
||||||
self::assertTrue(Reflection::usesTrait(B::class, E::class, true));
|
self::assertTrue(Reflection::usesTrait(B::class, E::class, true));
|
||||||
@@ -238,12 +239,12 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertFalse(Reflection::usesTrait(D::class, E::class, true));
|
self::assertFalse(Reflection::usesTrait(D::class, E::class, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetProperties()
|
public function testGetProperties(): void
|
||||||
{
|
{
|
||||||
self::assertCount(1, Reflection::getProperties(B::class));
|
self::assertCount(1, Reflection::getProperties(B::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertiesUsingFilter()
|
public function testGetPropertiesUsingFilter(): void
|
||||||
{
|
{
|
||||||
self::assertCount(
|
self::assertCount(
|
||||||
1,
|
1,
|
||||||
@@ -261,24 +262,24 @@ class ReflectionTest extends BaseTestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertiesWithParents()
|
public function testGetPropertiesWithParents(): void
|
||||||
{
|
{
|
||||||
self::assertCount(2, Reflection::getProperties(B::class, null, true));
|
self::assertCount(2, Reflection::getProperties(B::class, null, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValueOfNotExistingProperty()
|
public function testGetPropertyValueOfNotExistingProperty(): void
|
||||||
{
|
{
|
||||||
self::assertNull(Reflection::getPropertyValue(new D(), 'something'));
|
self::assertNull(Reflection::getPropertyValue(new D(), 'something'));
|
||||||
self::assertNull(Reflection::getPropertyValue(new D(), 'something', true));
|
self::assertNull(Reflection::getPropertyValue(new D(), 'something', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValueFromChain()
|
public function testGetPropertyValueFromChain(): void
|
||||||
{
|
{
|
||||||
$f = new F(1000, 'New York', 'USA', 'john.scott');
|
$f = new F(1000, 'New York', 'USA', 'john.scott');
|
||||||
self::assertEquals('John', Reflection::getPropertyValue($f, 'g.firstName'));
|
self::assertEquals('John', Reflection::getPropertyValue($f, 'g.firstName'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValueWithPublicGetter()
|
public function testGetPropertyValueWithPublicGetter(): void
|
||||||
{
|
{
|
||||||
$country = 'USA';
|
$country = 'USA';
|
||||||
$f = new F(1000, 'New York', $country, 'john.scott');
|
$f = new F(1000, 'New York', $country, 'john.scott');
|
||||||
@@ -286,7 +287,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertEquals($country, Reflection::getPropertyValue($f, 'country'));
|
self::assertEquals($country, Reflection::getPropertyValue($f, 'country'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValueWithProtectedGetter()
|
public function testGetPropertyValueWithProtectedGetter(): void
|
||||||
{
|
{
|
||||||
$city = 'New York';
|
$city = 'New York';
|
||||||
$f = new F(1000, $city, 'USA', 'john.scott');
|
$f = new F(1000, $city, 'USA', 'john.scott');
|
||||||
@@ -294,7 +295,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertEquals($city, Reflection::getPropertyValue($f, 'city'));
|
self::assertEquals($city, Reflection::getPropertyValue($f, 'city'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValueWithPrivateGetter()
|
public function testGetPropertyValueWithPrivateGetter(): void
|
||||||
{
|
{
|
||||||
$accountBalance = 1000;
|
$accountBalance = 1000;
|
||||||
$f = new F($accountBalance, 'New York', 'USA', 'john.scott');
|
$f = new F($accountBalance, 'New York', 'USA', 'john.scott');
|
||||||
@@ -302,7 +303,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertEquals($accountBalance, Reflection::getPropertyValue($f, 'accountBalance'));
|
self::assertEquals($accountBalance, Reflection::getPropertyValue($f, 'accountBalance'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValueWithoutGetter()
|
public function testGetPropertyValueWithoutGetter(): void
|
||||||
{
|
{
|
||||||
$username = 'john.scott';
|
$username = 'john.scott';
|
||||||
$f = new F(1000, 'New York', 'USA', $username);
|
$f = new F(1000, 'New York', 'USA', $username);
|
||||||
@@ -316,19 +317,19 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertEquals(1, Reflection::getPropertyValue($c, 'count', true));
|
self::assertEquals(1, Reflection::getPropertyValue($c, 'count', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValuesFromEmptySource()
|
public function testGetPropertyValuesFromEmptySource(): void
|
||||||
{
|
{
|
||||||
self::assertEquals([], Reflection::getPropertyValues([], 'something'));
|
self::assertEquals([], Reflection::getPropertyValues([], 'something'));
|
||||||
self::assertEquals([], Reflection::getPropertyValues(new Collection(), 'something'));
|
self::assertEquals([], Reflection::getPropertyValues(new Collection(), 'something'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValuesOfNotExistingPropertyFromSingleObject()
|
public function testGetPropertyValuesOfNotExistingPropertyFromSingleObject(): void
|
||||||
{
|
{
|
||||||
self::assertEquals([], Reflection::getPropertyValues(new D(), 'something'));
|
self::assertEquals([], Reflection::getPropertyValues(new D(), 'something'));
|
||||||
self::assertEquals([], Reflection::getPropertyValues(new D(), 'something', true));
|
self::assertEquals([], Reflection::getPropertyValues(new D(), 'something', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValuesOfNotExistingPropertyFromMultipleObjects()
|
public function testGetPropertyValuesOfNotExistingPropertyFromMultipleObjects(): void
|
||||||
{
|
{
|
||||||
$objects = [
|
$objects = [
|
||||||
new A(),
|
new A(),
|
||||||
@@ -349,13 +350,13 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertEquals([], Reflection::getPropertyValues($collection, 'something', true));
|
self::assertEquals([], Reflection::getPropertyValues($collection, 'something', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValuesOfExistingPropertyFromSingleObject()
|
public function testGetPropertyValuesOfExistingPropertyFromSingleObject(): void
|
||||||
{
|
{
|
||||||
self::assertEquals(['John'], Reflection::getPropertyValues(new G(), 'firstName'));
|
self::assertEquals(['John'], Reflection::getPropertyValues(new G(), 'firstName'));
|
||||||
self::assertEquals(['John'], Reflection::getPropertyValues(new G(), 'firstName', true));
|
self::assertEquals(['John'], Reflection::getPropertyValues(new G(), 'firstName', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValuesOfExistingPropertyFromMultipleObjects()
|
public function testGetPropertyValuesOfExistingPropertyFromMultipleObjects(): void
|
||||||
{
|
{
|
||||||
$expected = [
|
$expected = [
|
||||||
'New York',
|
'New York',
|
||||||
@@ -378,7 +379,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'city', true));
|
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'city', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValuesFromChainAndSingleObject()
|
public function testGetPropertyValuesFromChainAndSingleObject(): void
|
||||||
{
|
{
|
||||||
$f = new F(1000, 'New York', 'USA', 'john.scott');
|
$f = new F(1000, 'New York', 'USA', 'john.scott');
|
||||||
$j = new J();
|
$j = new J();
|
||||||
@@ -390,7 +391,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertEquals(['John'], Reflection::getPropertyValues($j, 'f.g.firstName', true));
|
self::assertEquals(['John'], Reflection::getPropertyValues($j, 'f.g.firstName', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyValuesFromChainAndMultipleObjects()
|
public function testGetPropertyValuesFromChainAndMultipleObjects(): void
|
||||||
{
|
{
|
||||||
$expected = [
|
$expected = [
|
||||||
'John',
|
'John',
|
||||||
@@ -413,47 +414,47 @@ class ReflectionTest extends BaseTestCase
|
|||||||
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'g.firstName', true));
|
self::assertEquals($expected, Reflection::getPropertyValues($collection, 'g.firstName', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetMaxNumberConstantUsingClassWithoutConstants()
|
public function testGetMaxNumberConstantUsingClassWithoutConstants(): void
|
||||||
{
|
{
|
||||||
static::assertNull(Reflection::getMaxNumberConstant(A::class));
|
static::assertNull(Reflection::getMaxNumberConstant(A::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetMaxNumberConstant()
|
public function testGetMaxNumberConstant(): void
|
||||||
{
|
{
|
||||||
static::assertSame(5, Reflection::getMaxNumberConstant(H::class));
|
static::assertSame(5, Reflection::getMaxNumberConstant(H::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasMethodUsingClassWithoutMethod()
|
public function testHasMethodUsingClassWithoutMethod(): void
|
||||||
{
|
{
|
||||||
static::assertFalse(Reflection::hasMethod(A::class, 'getUser'));
|
static::assertFalse(Reflection::hasMethod(A::class, 'getUser'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasMethod()
|
public function testHasMethod(): void
|
||||||
{
|
{
|
||||||
static::assertTrue(Reflection::hasMethod(A::class, 'getCount'));
|
static::assertTrue(Reflection::hasMethod(A::class, 'getCount'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasPropertyUsingClassWithoutProperty()
|
public function testHasPropertyUsingClassWithoutProperty(): void
|
||||||
{
|
{
|
||||||
static::assertFalse(Reflection::hasProperty(A::class, 'users'));
|
static::assertFalse(Reflection::hasProperty(A::class, 'users'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasProperty()
|
public function testHasProperty(): void
|
||||||
{
|
{
|
||||||
static::assertTrue(Reflection::hasProperty(A::class, 'count'));
|
static::assertTrue(Reflection::hasProperty(A::class, 'count'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasConstantUsingClassWithoutConstant()
|
public function testHasConstantUsingClassWithoutConstant(): void
|
||||||
{
|
{
|
||||||
static::assertFalse(Reflection::hasConstant(H::class, 'users'));
|
static::assertFalse(Reflection::hasConstant(H::class, 'users'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasConstant()
|
public function testHasConstant(): void
|
||||||
{
|
{
|
||||||
static::assertTrue(Reflection::hasConstant(H::class, 'LOREM'));
|
static::assertTrue(Reflection::hasConstant(H::class, 'LOREM'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetConstantValueUsingClassWithoutConstant()
|
public function testGetConstantValueUsingClassWithoutConstant(): void
|
||||||
{
|
{
|
||||||
static::assertNull(Reflection::getConstantValue(H::class, 'users'));
|
static::assertNull(Reflection::getConstantValue(H::class, 'users'));
|
||||||
}
|
}
|
||||||
@@ -469,37 +470,37 @@ class ReflectionTest extends BaseTestCase
|
|||||||
static::assertSame($expected, Reflection::getConstants($class));
|
static::assertSame($expected, Reflection::getConstants($class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetConstantValue()
|
public function testGetConstantValue(): void
|
||||||
{
|
{
|
||||||
static::assertSame(H::LOREM, Reflection::getConstantValue(H::class, 'LOREM'));
|
static::assertSame(H::LOREM, Reflection::getConstantValue(H::class, 'LOREM'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsInterfaceImplementedUsingClassWithoutInterface()
|
public function testIsInterfaceImplementedUsingClassWithoutInterface(): void
|
||||||
{
|
{
|
||||||
static::assertFalse(Reflection::isInterfaceImplemented(A::class, I::class));
|
static::assertFalse(Reflection::isInterfaceImplemented(A::class, I::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsInterfaceImplemented()
|
public function testIsInterfaceImplemented(): void
|
||||||
{
|
{
|
||||||
static::assertTrue(Reflection::isInterfaceImplemented(B::class, I::class));
|
static::assertTrue(Reflection::isInterfaceImplemented(B::class, I::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsChildOfClassUsingClassWithoutChildClass()
|
public function testIsChildOfClassUsingClassWithoutChildClass(): void
|
||||||
{
|
{
|
||||||
static::assertFalse(Reflection::isChildOfClass(A::class, B::class));
|
static::assertFalse(Reflection::isChildOfClass(A::class, B::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsChildOfClass()
|
public function testIsChildOfClass(): void
|
||||||
{
|
{
|
||||||
static::assertTrue(Reflection::isChildOfClass(B::class, A::class));
|
static::assertTrue(Reflection::isChildOfClass(B::class, A::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyUsingClassWithoutProperty()
|
public function testGetPropertyUsingClassWithoutProperty(): void
|
||||||
{
|
{
|
||||||
static::assertNull(Reflection::getProperty(A::class, 'lorem'));
|
static::assertNull(Reflection::getProperty(A::class, 'lorem'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyUsingClassWithPrivateProperty()
|
public function testGetPropertyUsingClassWithPrivateProperty(): void
|
||||||
{
|
{
|
||||||
$property = Reflection::getProperty(A::class, 'count', ReflectionProperty::IS_PRIVATE);
|
$property = Reflection::getProperty(A::class, 'count', ReflectionProperty::IS_PRIVATE);
|
||||||
|
|
||||||
@@ -508,7 +509,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
static::assertSame('count', $property->getName());
|
static::assertSame('count', $property->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertyUsingClassWithProtectedProperty()
|
public function testGetPropertyUsingClassWithProtectedProperty(): void
|
||||||
{
|
{
|
||||||
$property = Reflection::getProperty(B::class, 'name', ReflectionProperty::IS_PROTECTED);
|
$property = Reflection::getProperty(B::class, 'name', ReflectionProperty::IS_PROTECTED);
|
||||||
|
|
||||||
@@ -523,7 +524,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
*
|
*
|
||||||
* @dataProvider provideObjectAndNotExistingProperty
|
* @dataProvider provideObjectAndNotExistingProperty
|
||||||
*/
|
*/
|
||||||
public function testSetPropertyValueUsingNotExistingProperty($object, $property)
|
public function testSetPropertyValueUsingNotExistingProperty($object, $property): void
|
||||||
{
|
{
|
||||||
$this->expectException(NotExistingPropertyException::class);
|
$this->expectException(NotExistingPropertyException::class);
|
||||||
Reflection::setPropertyValue($object, $property, 'test test test');
|
Reflection::setPropertyValue($object, $property, 'test test test');
|
||||||
@@ -536,7 +537,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
*
|
*
|
||||||
* @dataProvider provideObjectPropertyAndValue
|
* @dataProvider provideObjectPropertyAndValue
|
||||||
*/
|
*/
|
||||||
public function testSetPropertyValue($object, $property, $value)
|
public function testSetPropertyValue($object, $property, $value): void
|
||||||
{
|
{
|
||||||
$oldValue = Reflection::getPropertyValue($object, $property);
|
$oldValue = Reflection::getPropertyValue($object, $property);
|
||||||
Reflection::setPropertyValue($object, $property, $value);
|
Reflection::setPropertyValue($object, $property, $value);
|
||||||
@@ -546,7 +547,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
static::assertSame($newValue, $value);
|
static::assertSame($newValue, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetPropertiesValuesWithoutProperties()
|
public function testSetPropertiesValuesWithoutProperties(): void
|
||||||
{
|
{
|
||||||
$object = new G();
|
$object = new G();
|
||||||
Reflection::setPropertiesValues($object, []);
|
Reflection::setPropertiesValues($object, []);
|
||||||
@@ -561,7 +562,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
*
|
*
|
||||||
* @dataProvider provideObjectAndNotExistingProperties
|
* @dataProvider provideObjectAndNotExistingProperties
|
||||||
*/
|
*/
|
||||||
public function testSetPropertiesValuesUsingNotExistingProperties($object, array $propertiesValues)
|
public function testSetPropertiesValuesUsingNotExistingProperties($object, array $propertiesValues): void
|
||||||
{
|
{
|
||||||
$this->expectException(NotExistingPropertyException::class);
|
$this->expectException(NotExistingPropertyException::class);
|
||||||
Reflection::setPropertiesValues($object, $propertiesValues);
|
Reflection::setPropertiesValues($object, $propertiesValues);
|
||||||
@@ -573,7 +574,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
*
|
*
|
||||||
* @dataProvider provideObjectAndPropertiesValues
|
* @dataProvider provideObjectAndPropertiesValues
|
||||||
*/
|
*/
|
||||||
public function testSetPropertiesValues($object, array $propertiesValues)
|
public function testSetPropertiesValues($object, array $propertiesValues): void
|
||||||
{
|
{
|
||||||
Reflection::setPropertiesValues($object, $propertiesValues);
|
Reflection::setPropertiesValues($object, $propertiesValues);
|
||||||
|
|
||||||
@@ -583,11 +584,6 @@ class ReflectionTest extends BaseTestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides invalid class and trait
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public function provideInvalidClassAndTrait(): ?Generator
|
public function provideInvalidClassAndTrait(): ?Generator
|
||||||
{
|
{
|
||||||
yield[
|
yield[
|
||||||
@@ -606,15 +602,10 @@ class ReflectionTest extends BaseTestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function provideObjectAndNotExistingProperty(): ?Generator
|
||||||
* Provides object and name of not existing property
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public function provideObjectAndNotExistingProperty()
|
|
||||||
{
|
{
|
||||||
yield[
|
yield[
|
||||||
new \stdClass(),
|
new stdClass(),
|
||||||
'test',
|
'test',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -629,12 +620,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function provideObjectPropertyAndValue(): ?Generator
|
||||||
* Provides object, name of property and value of the property
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public function provideObjectPropertyAndValue()
|
|
||||||
{
|
{
|
||||||
yield[
|
yield[
|
||||||
new A(),
|
new A(),
|
||||||
@@ -661,15 +647,10 @@ class ReflectionTest extends BaseTestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function provideObjectAndNotExistingProperties(): ?Generator
|
||||||
* Provides object and not existing properties
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public function provideObjectAndNotExistingProperties()
|
|
||||||
{
|
{
|
||||||
yield[
|
yield[
|
||||||
new \stdClass(),
|
new stdClass(),
|
||||||
[
|
[
|
||||||
'test' => 1,
|
'test' => 1,
|
||||||
],
|
],
|
||||||
@@ -690,12 +671,7 @@ class ReflectionTest extends BaseTestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function provideObjectAndPropertiesValues(): ?Generator
|
||||||
* Provides object and its new values of properties
|
|
||||||
*
|
|
||||||
* @return Generator
|
|
||||||
*/
|
|
||||||
public function provideObjectAndPropertiesValues()
|
|
||||||
{
|
{
|
||||||
yield[
|
yield[
|
||||||
new A(),
|
new A(),
|
||||||
@@ -764,12 +740,12 @@ class ReflectionTest extends BaseTestCase
|
|||||||
public function provideClassToGetConstants(): ?Generator
|
public function provideClassToGetConstants(): ?Generator
|
||||||
{
|
{
|
||||||
yield[
|
yield[
|
||||||
new \stdClass(),
|
new stdClass(),
|
||||||
[],
|
[],
|
||||||
];
|
];
|
||||||
|
|
||||||
yield[
|
yield[
|
||||||
\stdClass::class,
|
stdClass::class,
|
||||||
[],
|
[],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user