Skip to content

Commit

Permalink
tests: improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 21, 2016
1 parent 5f73db6 commit 1884774
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
38 changes: 28 additions & 10 deletions tests/DI/PhpReflection.getReturnType.php7.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Test: Nette\DI\PhpReflection::getReturnType
* @phpversion >= 7
* @phpversion 7
*/

namespace NS
Expand All @@ -14,22 +14,34 @@ namespace NS
function noType()
{}

function classType(): B
{}

function nativeType(): string
{}

function selfType(): self
{}

/** @return B */
function annotationSingle()
function annotationClassType()
{}

/** @return B|string */
function annotationComplex()
function annotationUnionType()
{}

function nativeType(): string
/** @return String */
function annotationNativeType()
{}

function selfType(): self
/** @return self */
function annotationSelfType()
{}
}

function classType(): B
/** @return B */
function annotationClassType()
{}
}

Expand All @@ -44,14 +56,20 @@ namespace

Assert::null(PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'noType')));

Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationSingle')));

Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationComplex')));
Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'classType')));

Assert::same('string', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'nativeType')));

Assert::same('NS\A', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'selfType')));

Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationClassType')));

Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationUnionType')));

Assert::same('string', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationNativeType')));

Assert::same('NS\A', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationSelfType')));

// class name expanding is NOT supported for global functions
Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionFunction(NS\classType::class)));
Assert::same('B', PhpReflection::getReturnType(new \ReflectionFunction('NS\annotationClassType')));
}
22 changes: 14 additions & 8 deletions tests/DI/PhpReflection.getReturnType.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ namespace NS
{}

/** @return B */
function annotationSingle()
function annotationClassType()
{}

/** @return B|string */
function annotationComplex()
function annotationUnionType()
{}

/** @return String */
function nativeType()
function annotationNativeType()
{}

/** @return self */
function annotationSelfType()
{}
}

/** @return B */
function classType()
function annotationClassType()
{}
}

Expand All @@ -42,12 +46,14 @@ namespace

Assert::null(PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'noType')));

Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationSingle')));
Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationClassType')));

Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationUnionType')));

Assert::same('Test\B', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationComplex')));
Assert::same('string', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationNativeType')));

Assert::same('string', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'nativeType')));
Assert::same('NS\A', PhpReflection::getReturnType(new \ReflectionMethod(NS\A::class, 'annotationSelfType')));

// class name expanding is NOT supported for global functions
Assert::same('B', PhpReflection::getReturnType(new \ReflectionFunction(NS\classType::class)));
Assert::same('B', PhpReflection::getReturnType(new \ReflectionFunction('NS\annotationClassType')));
}

0 comments on commit 1884774

Please sign in to comment.