mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
forward bad TestCase method calls to global functions
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -22,3 +22,8 @@ trait SecondPluginTrait
|
||||
|
||||
Pest\Plugin::uses(PluginTrait::class);
|
||||
Pest\Plugin::uses(SecondPluginTrait::class);
|
||||
|
||||
function _assertThat()
|
||||
{
|
||||
expect(true)->toBeTrue();
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
Reference in New Issue
Block a user