forward bad TestCase method calls to global functions

This commit is contained in:
Félix Dorn
2020-08-25 13:45:55 +02:00
parent fe885fbfb6
commit 278af4b835
4 changed files with 16 additions and 1 deletions

View File

@ -6,6 +6,7 @@ namespace Pest\Support;
use Closure;
use Pest\Exceptions\ShouldNotHappen;
use Pest\TestSuite;
use ReflectionClass;
use ReflectionException;
use ReflectionFunction;
@ -40,6 +41,12 @@ final class Reflection
return $object->__call($method, $args);
}
if (is_callable($method)) {
return Closure::fromCallable($method)->bindTo(
TestSuite::getInstance()->test
)(...$args);
}
throw $exception;
}
}

View File

@ -244,6 +244,7 @@
✓ it throws error if property do not exist
✓ it allows to call underlying protected/private methods
✓ it throws error if method do not exist
✓ it can forward unexpected calls to any global function
PASS Tests\Features\HigherOrderTests
✓ it proxies calls to object
@ -352,5 +353,5 @@
✓ depends with defined arguments
✓ depends run test only once
Tests: 6 skipped, 207 passed
Tests: 6 skipped, 208 passed

View File

@ -22,3 +22,8 @@ trait SecondPluginTrait
Pest\Plugin::uses(PluginTrait::class);
Pest\Plugin::uses(SecondPluginTrait::class);
function _assertThat()
{
expect(true)->toBeTrue();
}

View File

@ -40,3 +40,5 @@ it('allows to call underlying protected/private methods', function () {
it('throws error if method do not exist', function () {
test()->name();
})->throws(\ReflectionException::class, 'Call to undefined method PHPUnit\Framework\TestCase::name()');
it('can forward unexpected calls to any global function')->_assertThat();