Skip to content

Commit d905e96

Browse files
committed
Add tests for clearing resolved facade instances
1 parent 3c6ad27 commit d905e96

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/Support/SupportFacadeTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,40 @@ public function testExpectsReturnsAMockeryMockWithExpectationRequired()
8080
$this->assertInstanceOf(MockInterface::class, $mock = FacadeStub::expects('foo')->with('bar')->andReturn('baz')->getMock());
8181
$this->assertSame('baz', $app['foo']->foo('bar'));
8282
}
83+
84+
public function testFacadeResolvesAgainAfterClearingSpecific()
85+
{
86+
$app = new ApplicationStub;
87+
$app->setAttributes(['foo' => $mock = m::mock(stdClass::class)]);
88+
$mock->shouldReceive('bar')->times(3)->andReturn('baz');
89+
90+
// Resolve for the first time
91+
FacadeStub::setFacadeApplication($app);
92+
$this->assertSame('baz', FacadeStub::bar());
93+
94+
// Clear resolved instance and resolve the second time
95+
FacadeStub::clearResolvedInstance();
96+
$this->assertSame('baz', FacadeStub::bar());
97+
98+
// Clear resolved instance through parent and resolve the third time
99+
Facade::clearResolvedInstance('foo');
100+
$this->assertSame('baz', FacadeStub::bar());
101+
}
102+
103+
public function testFacadeResolvesAgainAfterClearingAll()
104+
{
105+
$app = new ApplicationStub;
106+
$app->setAttributes(['foo' => $mock = m::mock(stdClass::class)]);
107+
$mock->shouldReceive('bar')->times(2)->andReturn('baz');
108+
109+
// Resolve for the first time
110+
FacadeStub::setFacadeApplication($app);
111+
$this->assertSame('baz', FacadeStub::bar());
112+
113+
// Clear all resolved instances and resolve a second time
114+
Facade::clearResolvedInstances();
115+
$this->assertSame('baz', FacadeStub::bar());
116+
}
83117
}
84118

85119
class FacadeStub extends Facade

0 commit comments

Comments
 (0)