mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 01:31:45 +01:00
Tests > refactoring
This commit is contained in:
@@ -14,7 +14,6 @@ use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException;
|
|||||||
use Meritoo\Common\Type\OopVisibilityType;
|
use Meritoo\Common\Type\OopVisibilityType;
|
||||||
use Meritoo\Common\Utilities\Miscellaneous;
|
use Meritoo\Common\Utilities\Miscellaneous;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use ReflectionException;
|
|
||||||
use ReflectionMethod;
|
use ReflectionMethod;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
@@ -172,7 +171,6 @@ trait BaseTestCaseTrait
|
|||||||
* @param int $requiredArgumentsCount (optional) Expected count/amount of required arguments
|
* @param int $requiredArgumentsCount (optional) Expected count/amount of required arguments
|
||||||
* of the verified method
|
* of the verified method
|
||||||
* @throws UnknownOopVisibilityTypeException
|
* @throws UnknownOopVisibilityTypeException
|
||||||
* @throws ReflectionException
|
|
||||||
*
|
*
|
||||||
* Attention. 2nd argument, the $method, may be:
|
* Attention. 2nd argument, the $method, may be:
|
||||||
* - string - name of the method
|
* - string - name of the method
|
||||||
@@ -229,8 +227,6 @@ trait BaseTestCaseTrait
|
|||||||
* @param int $argumentsCount (optional) Expected count/amount of arguments of the verified method
|
* @param int $argumentsCount (optional) Expected count/amount of arguments of the verified method
|
||||||
* @param int $requiredArgumentsCount (optional) Expected count/amount of required arguments of the verified
|
* @param int $requiredArgumentsCount (optional) Expected count/amount of required arguments of the verified
|
||||||
* method
|
* method
|
||||||
* @throws ReflectionException
|
|
||||||
* @throws UnknownOopVisibilityTypeException
|
|
||||||
*/
|
*/
|
||||||
protected static function assertConstructorVisibilityAndArguments(
|
protected static function assertConstructorVisibilityAndArguments(
|
||||||
$classNamespace,
|
$classNamespace,
|
||||||
@@ -244,14 +240,19 @@ trait BaseTestCaseTrait
|
|||||||
$reflection = new ReflectionClass($classNamespace);
|
$reflection = new ReflectionClass($classNamespace);
|
||||||
$method = $reflection->getConstructor();
|
$method = $reflection->getConstructor();
|
||||||
|
|
||||||
static::assertMethodVisibilityAndArguments($classNamespace, $method, $visibilityType, $argumentsCount, $requiredArgumentsCount);
|
static::assertMethodVisibilityAndArguments(
|
||||||
|
$classNamespace,
|
||||||
|
$method,
|
||||||
|
$visibilityType,
|
||||||
|
$argumentsCount,
|
||||||
|
$requiredArgumentsCount
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that class with given namespace has no constructor
|
* Asserts that class with given namespace has no constructor
|
||||||
*
|
*
|
||||||
* @param string $classNamespace Namespace of class that contains constructor to verify
|
* @param string $classNamespace Namespace of class that contains constructor to verify
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
*/
|
||||||
protected static function assertHasNoConstructor($classNamespace)
|
protected static function assertHasNoConstructor($classNamespace)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -82,8 +82,15 @@ class ReflectionTest extends BaseTestCase
|
|||||||
* Class with namespace containing name of class (duplicated string)
|
* Class with namespace containing name of class (duplicated string)
|
||||||
*/
|
*/
|
||||||
if (class_exists('Symfony\Bundle\SecurityBundle\SecurityBundle')) {
|
if (class_exists('Symfony\Bundle\SecurityBundle\SecurityBundle')) {
|
||||||
self::assertEquals('Symfony\Bundle\SecurityBundle\SecurityBundle', Reflection::getClassName('Symfony\Bundle\SecurityBundle\SecurityBundle'));
|
self::assertEquals(
|
||||||
self::assertEquals('SecurityBundle', Reflection::getClassName('Symfony\Bundle\SecurityBundle\SecurityBundle', true));
|
'Symfony\Bundle\SecurityBundle\SecurityBundle',
|
||||||
|
Reflection::getClassName('Symfony\Bundle\SecurityBundle\SecurityBundle')
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
'SecurityBundle',
|
||||||
|
Reflection::getClassName('Symfony\Bundle\SecurityBundle\SecurityBundle', true)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +122,10 @@ class ReflectionTest extends BaseTestCase
|
|||||||
* Class with namespace containing name of class (duplicated string)
|
* Class with namespace containing name of class (duplicated string)
|
||||||
*/
|
*/
|
||||||
if (class_exists('Symfony\Bundle\SecurityBundle\SecurityBundle')) {
|
if (class_exists('Symfony\Bundle\SecurityBundle\SecurityBundle')) {
|
||||||
self::assertEquals('Symfony\Bundle\SecurityBundle', Reflection::getClassNamespace('Symfony\Bundle\SecurityBundle\SecurityBundle'));
|
self::assertEquals(
|
||||||
|
'Symfony\Bundle\SecurityBundle',
|
||||||
|
Reflection::getClassNamespace('Symfony\Bundle\SecurityBundle\SecurityBundle')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,11 +193,11 @@ class ReflectionTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testGetMethods()
|
public function testGetMethods()
|
||||||
{
|
{
|
||||||
self::assertEquals(1, count(Reflection::getMethods(B::class, true)));
|
self::assertCount(1, Reflection::getMethods(B::class, true));
|
||||||
self::assertEquals(3, count(Reflection::getMethods(B::class)));
|
self::assertCount(3, Reflection::getMethods(B::class));
|
||||||
self::assertEquals(2, count(Reflection::getMethods(A::class)));
|
self::assertCount(2, Reflection::getMethods(A::class));
|
||||||
self::assertEquals(2, count(Reflection::getMethods(C::class, true)));
|
self::assertCount(2, Reflection::getMethods(C::class, true));
|
||||||
self::assertEquals(5, count(Reflection::getMethods(C::class)));
|
self::assertCount(5, Reflection::getMethods(C::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -235,9 +245,20 @@ class ReflectionTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testGetPropertiesUsingFilter()
|
public function testGetPropertiesUsingFilter()
|
||||||
{
|
{
|
||||||
self::assertCount(1, Reflection::getProperties(B::class, ReflectionProperty::IS_PROTECTED));
|
self::assertCount(
|
||||||
self::assertCount(0, Reflection::getProperties(B::class, ReflectionProperty::IS_PRIVATE));
|
1,
|
||||||
self::assertCount(1, Reflection::getProperties(B::class, ReflectionProperty::IS_PRIVATE, true));
|
Reflection::getProperties(B::class, ReflectionProperty::IS_PROTECTED)
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertCount(
|
||||||
|
0,
|
||||||
|
Reflection::getProperties(B::class, ReflectionProperty::IS_PRIVATE)
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertCount(
|
||||||
|
1,
|
||||||
|
Reflection::getProperties(B::class, ReflectionProperty::IS_PRIVATE, true)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetPropertiesWithParents()
|
public function testGetPropertiesWithParents()
|
||||||
|
|||||||
Reference in New Issue
Block a user