File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Loki \Components \Test \Unit \Mock ;
4+
5+ use BadMethodCallException ;
6+ use Loki \Components \Component \AbstractComponentContext ;
7+
8+ trait ComponentContextMock
9+ {
10+ protected function getComponentContextMock (array $ contextDependencies = []): AbstractComponentContext
11+ {
12+ $ context = $ this ->getMockBuilder (AbstractComponentContext::class)
13+ ->disableOriginalConstructor ()
14+ ->onlyMethods (['__call ' ])
15+ ->getMock ();
16+
17+ $ context ->method ('__call ' )
18+ ->willReturnCallback (function (string $ name , array $ args ) use ($ contextDependencies ) {
19+ if ($ args !== []) {
20+ throw new BadMethodCallException ("Unexpected args for $ name " );
21+ }
22+
23+ if (array_key_exists ($ name , $ contextDependencies )) {
24+ return $ contextDependencies [$ name ];
25+ }
26+
27+ throw new BadMethodCallException ("Unexpected method: $ name " );
28+ });
29+
30+ return $ context ;
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments