1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
<?php
namespace Illuminate\Tests\Support;
use BadMethodCallException;
use Error;
use Illuminate\Support\Traits\ForwardsCalls;
use PHPUnit\Framework\TestCase;
class ForwardsCallsTest extends TestCase
{
public function testForwardsCalls()
{
$results = (new ForwardsCallsOne)->forwardedTwo('foo', 'bar');
$this->assertEquals(['foo', 'bar'], $results);
}
public function testNestedForwardCalls()
{
$results = (new ForwardsCallsOne)->forwardedBase('foo', 'bar');
$this->assertEquals(['foo', 'bar'], $results);
}
public function testMissingForwardedCallThrowsCorrectError()
{
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage('Call to undefined method Illuminate\Tests\Support\ForwardsCallsOne::missingMethod()');
(new ForwardsCallsOne)->missingMethod('foo', 'bar');
}
public function testMissingAlphanumericForwardedCallThrowsCorrectError()
{
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage('Call to undefined method Illuminate\Tests\Support\ForwardsCallsOne::this1_shouldWork_too()');
(new ForwardsCallsOne)->this1_shouldWork_too('foo', 'bar');
}
public function testNonForwardedErrorIsNotTamperedWith()
{
$this->expectException(Error::class);
$this->expectExceptionMessage('Call to undefined method Illuminate\Tests\Support\ForwardsCallsBase::missingMethod()');
(new ForwardsCallsOne)->baseError('foo', 'bar');
}
public function testThrowBadMethodCallException()
{
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage('Call to undefined method Illuminate\Tests\Support\ForwardsCallsOne::test()');
(new ForwardsCallsOne)->throwTestException('test');
}
}
class ForwardsCallsOne
{
use ForwardsCalls;
public function __call($method, $parameters)
{
return $this->forwardCallTo(new ForwardsCallsTwo, $method, $parameters);
}
public function throwTestException($method)
{
static::throwBadMethodCallException($method);
}
}
class ForwardsCallsTwo
{
use ForwardsCalls;
public function __call($method, $parameters)
{
return $this->forwardCallTo(new ForwardsCallsBase, $method, $parameters);
}
public function forwardedTwo(...$parameters)
{
return $parameters;
}
}
class ForwardsCallsBase
{
public function forwardedBase(...$parameters)
{
return $parameters;
}
public function baseError()
{
return $this->missingMethod();
}
}
|