Merge pull request #109 from Gummibeer/patch-1

pass calls to overloaded method if possible
This commit is contained in:
Nuno Maduro
2020-06-21 18:53:12 +02:00
committed by GitHub
3 changed files with 33 additions and 5 deletions

View File

@ -27,11 +27,19 @@ final class Reflection
{
$reflectionClass = new ReflectionClass($object);
$reflectionMethod = $reflectionClass->getMethod($method);
try {
$reflectionMethod = $reflectionClass->getMethod($method);
$reflectionMethod->setAccessible(true);
$reflectionMethod->setAccessible(true);
return $reflectionMethod->invoke($object, ...$args);
return $reflectionMethod->invoke($object, ...$args);
} catch (ReflectionException $exception) {
if (method_exists($object, '__call')) {
return $object->__call($method, $args);
}
throw $exception;
}
}
/**

View File

@ -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
View 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();