11<?php
22
3+ use Mockery as m ;
4+
35class SupportFacadeTest extends PHPUnit_Framework_TestCase {
46
7+ public function setUp ()
8+ {
9+ Illuminate \Support \Facades \Facade::clearResolvedInstances ();
10+ }
11+
12+
13+ public function tearDown ()
14+ {
15+ m::close ();
16+ }
17+
18+
519 public function testFacadeCallsUnderlyingApplication ()
620 {
7- FacadeStub::setFacadeApplication (array ('foo ' => new ApplicationStub ));
21+ $ app = new ApplicationStub ;
22+ $ app ->setAttributes (array ('foo ' => $ mock = m::mock ('StdClass ' )));
23+ $ mock ->shouldReceive ('bar ' )->once ()->andReturn ('baz ' );
24+ FacadeStub::setFacadeApplication ($ app );
825 $ this ->assertEquals ('baz ' , FacadeStub::bar ());
926 }
1027
28+
29+ public function testShouldReceiveReturnsAMockeryMock ()
30+ {
31+ $ app = new ApplicationStub ;
32+ $ app ->setAttributes (array ('foo ' => new StdClass ));
33+ FacadeStub::setFacadeApplication ($ app );
34+
35+ $ this ->assertInstanceOf ('Mockery\MockInterface ' , $ mock = FacadeStub::shouldReceive ('foo ' )->once ()->with ('bar ' )->andReturn ('baz ' )->getMock ());
36+ $ this ->assertEquals ('baz ' , $ app ['foo ' ]->foo ('bar ' ));
37+ }
38+
1139}
1240
1341class FacadeStub extends Illuminate \Support \Facades \Facade {
1442
15- /**
16- * Get the registered name of the component.
17- *
18- * @return string
19- */
2043 protected static function getFacadeAccessor ()
2144 {
2245 return 'foo ' ;
2346 }
2447
2548}
2649
27- class ApplicationStub {
50+ class ApplicationStub implements ArrayAccess {
2851
29- public function bar ()
30- {
31- return 'baz ' ;
32- }
52+ protected $ attributes = array ();
53+
54+ public function setAttributes ($ attributes ) { $ this ->attributes = $ attributes ; }
55+ public function instance ($ key , $ instance ) { $ this ->attributes [$ key ] = $ instance ; }
56+ public function offsetExists ($ offset ) { isset ($ this ->attributes [$ offset ]); }
57+ public function offsetGet ($ key ) { return $ this ->attributes [$ key ]; }
58+ public function offsetSet ($ key , $ value ) { $ this ->attributes [$ key ] = $ value ; }
59+ public function offsetUnset ($ key ) { unset($ this ->attributes [$ key ]); }
3360
3461}
0 commit comments