diff --git a/src/Illuminate/Support/Facades/Facade.php b/src/Illuminate/Support/Facades/Facade.php index c53180ccf8bf..578a86ca390f 100755 --- a/src/Illuminate/Support/Facades/Facade.php +++ b/src/Illuminate/Support/Facades/Facade.php @@ -25,14 +25,18 @@ abstract class Facade /** * Convert the facade into a Mockery spy. * - * @return void + * @return MockInterface */ public static function spy() { if (! static::isMock()) { $class = static::getMockableClass(); - static::swap($class ? Mockery::spy($class) : Mockery::spy()); + $spy = $class ? Mockery::spy($class) : Mockery::spy(); + + static::swap($spy); + + return $spy; } } diff --git a/tests/Support/SupportFacadeTest.php b/tests/Support/SupportFacadeTest.php index 1e55644fe747..609521cb9048 100755 --- a/tests/Support/SupportFacadeTest.php +++ b/tests/Support/SupportFacadeTest.php @@ -39,6 +39,18 @@ public function testShouldReceiveReturnsAMockeryMock() $this->assertEquals('baz', $app['foo']->foo('bar')); } + public function testSpyReturnsAMockerySpy() + { + $app = new ApplicationStub; + $app->setAttributes(['foo' => new stdClass]); + FacadeStub::setFacadeApplication($app); + + $this->assertInstanceOf(m\MockInterface::class, $spy = FacadeStub::spy()); + + FacadeStub::foo(); + $spy->shouldHaveReceived('foo'); + } + public function testShouldReceiveCanBeCalledTwice() { $app = new ApplicationStub;