Skip to content

Commit

Permalink
Improve AdapterCompatibilityTest
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Nov 10, 2024
1 parent 9f18d3c commit b720d53
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions tests/Internal/NativeAdapter/AdapterCompatibilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private static function assertClassEquals(\ReflectionClass $native, \ReflectionC
self::assertSame($native->__toString(), $typhoon->__toString(), 'class.__toString()');
self::assertGetAttributes($native, $typhoon, 'c');
self::assertSame($native->getConstructor()?->name, $typhoon->getConstructor()?->name, 'class.getConstructor().name');
self::assertSame($native->getDefaultProperties(), $typhoon->getDefaultProperties(), 'class.getDefaultProperties()');
self::assertArraysSameNoOrder($native->getDefaultProperties(), $typhoon->getDefaultProperties(), 'class.getDefaultProperties()');
self::assertSame($native->getDocComment(), $typhoon->getDocComment(), 'class.getDocComment()');
self::assertSame($native->getEndLine(), $typhoon->getEndLine(), 'class.getEndLine()');
self::assertEquals($native->getExtension(), $typhoon->getExtension(), 'class.getExtension()');
Expand Down Expand Up @@ -222,9 +222,12 @@ private static function assertClassEquals(\ReflectionClass $native, \ReflectionC

// CONSTANTS

self::assertSame($native->getConstants(), $typhoon->getConstants(), 'class.getConstants().name');

self::assertReflectionsEqualNoOrder($native->getReflectionConstants(), $typhoon->getReflectionConstants(), 'class.getReflectionConstants()');
self::assertArraysSameNoOrder($native->getConstants(), $typhoon->getConstants(), 'class.getConstants().name');
self::assertArraysSameNoOrder($native->getConstants(0), $typhoon->getConstants(0), 'class.getConstants(0).name');
self::assertArraysSameNoOrder($native->getConstants(\ReflectionClassConstant::IS_PUBLIC), $typhoon->getConstants(\ReflectionClassConstant::IS_PUBLIC), 'class.getConstants(IS_PUBLIC).name');
self::assertArraysSameNoOrder($native->getConstants(\ReflectionClassConstant::IS_PROTECTED), $typhoon->getConstants(\ReflectionClassConstant::IS_PROTECTED), 'class.getConstants(IS_PROTECTED).name');
self::assertArraysSameNoOrder($native->getConstants(\ReflectionClassConstant::IS_PRIVATE), $typhoon->getConstants(\ReflectionClassConstant::IS_PRIVATE), 'class.getConstants(IS_PRIVATE).name');
self::assertArraysSameNoOrder($native->getConstants(\ReflectionClassConstant::IS_FINAL), $typhoon->getConstants(\ReflectionClassConstant::IS_FINAL), 'class.getConstants(IS_FINAL).name');

foreach ($native->getReflectionConstants() as $nativeConstant) {
self::assertTrue($typhoon->hasConstant($nativeConstant->name), "class.hasConstant({$nativeConstant->name})");
Expand All @@ -234,12 +237,7 @@ private static function assertClassEquals(\ReflectionClass $native, \ReflectionC
self::assertConstantEquals($nativeConstant, $typhoonConstant, "class.getReflectionConstant({$nativeConstant->name})");
}

self::assertSame($native->getConstants(0), $typhoon->getConstants(0), 'class.getConstants(0).name');
self::assertSame($native->getConstants(\ReflectionClassConstant::IS_PUBLIC), $typhoon->getConstants(\ReflectionClassConstant::IS_PUBLIC), 'class.getConstants(IS_PUBLIC).name');
self::assertSame($native->getConstants(\ReflectionClassConstant::IS_PROTECTED), $typhoon->getConstants(\ReflectionClassConstant::IS_PROTECTED), 'class.getConstants(IS_PROTECTED).name');
self::assertSame($native->getConstants(\ReflectionClassConstant::IS_PRIVATE), $typhoon->getConstants(\ReflectionClassConstant::IS_PRIVATE), 'class.getConstants(IS_PRIVATE).name');
self::assertSame($native->getConstants(\ReflectionClassConstant::IS_FINAL), $typhoon->getConstants(\ReflectionClassConstant::IS_FINAL), 'class.getConstants(IS_FINAL).name');

self::assertReflectionsEqualNoOrder($native->getReflectionConstants(), $typhoon->getReflectionConstants(), 'class.getReflectionConstants()');
self::assertReflectionsEqualNoOrder($native->getReflectionConstants(0), $typhoon->getReflectionConstants(0), 'class.getReflectionConstants(0)');
self::assertReflectionsEqualNoOrder($native->getReflectionConstants(\ReflectionClassConstant::IS_PUBLIC), $typhoon->getReflectionConstants(\ReflectionClassConstant::IS_PUBLIC), 'class.getReflectionConstants(IS_PUBLIC)');
self::assertReflectionsEqualNoOrder($native->getReflectionConstants(\ReflectionClassConstant::IS_PROTECTED), $typhoon->getReflectionConstants(\ReflectionClassConstant::IS_PROTECTED), 'class.getReflectionConstants(IS_PROTECTED)');
Expand All @@ -249,35 +247,33 @@ private static function assertClassEquals(\ReflectionClass $native, \ReflectionC
// PROPERTIES

self::assertReflectionsEqualNoOrder($native->getProperties(), $typhoon->getProperties(), 'class.getProperties()');

foreach ($native->getProperties() as $nativeProperty) {
self::assertTrue($typhoon->hasProperty($nativeProperty->name), "class.hasProperty({$nativeProperty->name})");
self::assertPropertyEquals($nativeProperty, $typhoon->getProperty($nativeProperty->name), "class.getProperty({$nativeProperty->name})");
}

self::assertReflectionsEqualNoOrder($native->getProperties(0), $typhoon->getProperties(0), 'class.getProperties(0)');
self::assertReflectionsEqualNoOrder($native->getProperties(\ReflectionProperty::IS_PUBLIC), $typhoon->getProperties(\ReflectionProperty::IS_PUBLIC), 'class.getProperties(IS_PUBLIC)');
self::assertReflectionsEqualNoOrder($native->getProperties(\ReflectionProperty::IS_PROTECTED), $typhoon->getProperties(\ReflectionProperty::IS_PROTECTED), 'class.getProperties(IS_PROTECTED)');
self::assertReflectionsEqualNoOrder($native->getProperties(\ReflectionProperty::IS_PRIVATE), $typhoon->getProperties(\ReflectionProperty::IS_PRIVATE), 'class.getProperties(IS_PRIVATE)');
self::assertReflectionsEqualNoOrder($native->getProperties(\ReflectionProperty::IS_STATIC), $typhoon->getProperties(\ReflectionProperty::IS_STATIC), 'class.getProperties(IS_STATIC)');
self::assertReflectionsEqualNoOrder($native->getProperties(\ReflectionProperty::IS_READONLY), $typhoon->getProperties(\ReflectionProperty::IS_READONLY), 'class.getProperties(IS_READONLY)');

foreach ($native->getProperties() as $nativeProperty) {
self::assertTrue($typhoon->hasProperty($nativeProperty->name), "class.hasProperty({$nativeProperty->name})");
self::assertPropertyEquals($nativeProperty, $typhoon->getProperty($nativeProperty->name), "class.getProperty({$nativeProperty->name})");
}

// METHODS

self::assertReflectionsEqualNoOrder($native->getMethods(), $typhoon->getMethods(), 'class.getMethods()');

foreach ($native->getMethods() as $nativeMethod) {
self::assertTrue($typhoon->hasMethod($nativeMethod->name), "hasMethod({$nativeMethod->name})");
self::assertMethodEquals($nativeMethod, $typhoon->getMethod($nativeMethod->name), "getMethod({$nativeMethod->name})");
}

self::assertReflectionsEqualNoOrder($native->getMethods(0), $typhoon->getMethods(0), 'class.getMethods(0)');
self::assertReflectionsEqualNoOrder($native->getMethods(\ReflectionMethod::IS_FINAL), $typhoon->getMethods(\ReflectionMethod::IS_FINAL), 'class.getMethods(IS_FINAL)');
self::assertReflectionsEqualNoOrder($native->getMethods(\ReflectionMethod::IS_ABSTRACT), $typhoon->getMethods(\ReflectionMethod::IS_ABSTRACT), 'class.getMethods(IS_ABSTRACT)');
self::assertReflectionsEqualNoOrder($native->getMethods(\ReflectionMethod::IS_PUBLIC), $typhoon->getMethods(\ReflectionMethod::IS_PUBLIC), 'class.getMethods(IS_PUBLIC)');
self::assertReflectionsEqualNoOrder($native->getMethods(\ReflectionMethod::IS_PROTECTED), $typhoon->getMethods(\ReflectionMethod::IS_PROTECTED), 'class.getMethods(IS_PROTECTED)');
self::assertReflectionsEqualNoOrder($native->getMethods(\ReflectionMethod::IS_PRIVATE), $typhoon->getMethods(\ReflectionMethod::IS_PRIVATE), 'class.getMethods(IS_PRIVATE)');
self::assertReflectionsEqualNoOrder($native->getMethods(\ReflectionMethod::IS_STATIC), $typhoon->getMethods(\ReflectionMethod::IS_STATIC), 'class.getMethods(IS_STATIC)');

foreach ($native->getMethods() as $nativeMethod) {
self::assertTrue($typhoon->hasMethod($nativeMethod->name), "hasMethod({$nativeMethod->name})");
self::assertMethodEquals($nativeMethod, $typhoon->getMethod($nativeMethod->name), "getMethod({$nativeMethod->name})");
}
}

private static function assertConstantEquals(\ReflectionClassConstant $native, \ReflectionClassConstant $typhoon, string $messagePrefix): void
Expand Down Expand Up @@ -522,6 +518,13 @@ private static function assertReflectionsEqual(array $nativeReflections, array $
);
}

private static function assertArraysSameNoOrder(array $expected, array $actual, string $message = ''): void
{
ksort($expected);
ksort($actual);
self::assertSame($expected, $actual, $message);
}

/**
* @param array<\ReflectionFunctionAbstract|\ReflectionClass|\ReflectionClassConstant|\ReflectionProperty|\ReflectionParameter> $nativeReflections
* @param array<\ReflectionFunctionAbstract|\ReflectionClass|\ReflectionClassConstant|\ReflectionProperty|\ReflectionParameter> $typhoonReflections
Expand Down

0 comments on commit b720d53

Please sign in to comment.