8000 Add expects to built-in Facade testing methods (#34936) · laravel/framework@7c1fbb3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c1fbb3

Browse files
Add expects to built-in Facade testing methods (#34936)
1 parent 85f62d5 commit 7c1fbb3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Illuminate/Support/Facades/Facade.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ public static function shouldReceive()
9090
return $mock->shouldReceive(...func_get_args());
9191
}
9292

93+
/**
94+
* Initiate a mock expectation on the facade.
95+
*
96+
* @return \Mockery\Expectation
97+
*/
98+
public static function expects()
99+
{
100+
$name = static::getFacadeAccessor();
101+
102+
$mock = static::isMock()
103+
? static::$resolvedInstance[$name]
104+
: static::createFreshMockInstance();
105+
106+
return $mock->expects(...func_get_args());
107+
}
108+
93109
/**
94110
* Create a fresh mock instance for the given class.
95111
*

tests/Support/SupportFacadeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ public function testCanBeMockedWithoutUnderlyingInstance()
7070
FacadeStub::shouldReceive('foo')->once()->andReturn('bar');
7171
$this->assertSame('bar', FacadeStub::foo());
7272
}
73+
74+
public function testExpectsReturnsAMockeryMockWithExpectationRequired()
75+
{
76+
$app = new ApplicationStub;
77+
$app->setAttributes(['foo' => new stdClass]);
78+
FacadeStub::setFacadeApplication($app);
79+
80+
$this->assertInstanceOf(MockInterface::class, $mock = FacadeStub::expects('foo')->with('bar')->andReturn('baz')->getMock());
81+
$this->assertSame('baz', $app['foo']->foo('bar'));
82+
}
7383
}
7484

7585
class FacadeStub extends Facade

0 commit comments

Comments
 (0)
0