Skip to content

Commit

Permalink
Return instance of spy when swapping facade for a Mockery spy
Browse files Browse the repository at this point in the history
  • Loading branch information
dallincoons committed Jul 21, 2018
1 parent 3bf6296 commit 0878503
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Illuminate/Support/Facades/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Support/SupportFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0878503

Please sign in to comment.