mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Merge pull request #109 from Gummibeer/patch-1
pass calls to overloaded method if possible
This commit is contained in:
@ -27,11 +27,19 @@ final class Reflection
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($object);
|
||||
|
||||
try {
|
||||
$reflectionMethod = $reflectionClass->getMethod($method);
|
||||
|
||||
$reflectionMethod->setAccessible(true);
|
||||
|
||||
return $reflectionMethod->invoke($object, ...$args);
|
||||
} catch (ReflectionException $exception) {
|
||||
if (method_exists($object, '__call')) {
|
||||
return $object->__call($method, $args);
|
||||
}
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -75,6 +75,10 @@
|
||||
✓ it is a test
|
||||
✓ it is a higher order message test
|
||||
|
||||
PASS Tests\Features\Macro
|
||||
✓ it can call chained macro method
|
||||
✓ it will throw exception from call if no macro exists
|
||||
|
||||
PASS Tests\Features\Mocks
|
||||
✓ it has bar
|
||||
|
||||
@ -159,5 +163,5 @@
|
||||
WARN Tests\Visual\Success
|
||||
s visual snapshot of test suite on success
|
||||
|
||||
Tests: 6 skipped, 92 passed
|
||||
Time: 3.40s
|
||||
Tests: 6 skipped, 94 passed
|
||||
Time: 3.73s
|
||||
|
||||
16
tests/Features/Macro.php
Normal file
16
tests/Features/Macro.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
uses(Macroable::class);
|
||||
|
||||
beforeEach()->macro('bar', function () {
|
||||
assertInstanceOf(TestCase::class, $this);
|
||||
});
|
||||
|
||||
it('can call chained macro method')->bar();
|
||||
|
||||
it('will throw exception from call if no macro exists')
|
||||
->throws(BadMethodCallException::class)
|
||||
->foo();
|
||||
Reference in New Issue
Block a user