Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Illuminate/Support/Facades/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ public static function shouldReceive()
return $mock->shouldReceive(...func_get_args());
}

/**
* Initiate a mock expectation on the facade.
*
* @return \Mockery\Expectation
*/
public static function expects()
{
$name = static::getFacadeAccessor();

$mock = static::isMock()
? static::$resolvedInstance[$name]
: static::createFreshMockInstance();

return $mock->expects(...func_get_args());
}

/**
* Create a fresh mock instance for the given class.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/Support/SupportFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ public function testCanBeMockedWithoutUnderlyingInstance()
FacadeStub::shouldReceive('foo')->once()->andReturn('bar');
$this->assertSame('bar', FacadeStub::foo());
}

public function testExpectsReturnsAMockeryMockWithExpectationRequired()
{
$app = new ApplicationStub;
$app->setAttributes(['foo' => new stdClass]);
FacadeStub::setFacadeApplication($app);

$this->assertInstanceOf(MockInterface::class, $mock = FacadeStub::expects('foo')->with('bar')->andReturn('baz')->getMock());
$this->assertSame('baz', $app['foo']->foo('bar'));
}
}

class FacadeStub extends Facade
Expand Down