Skip to content

Commit 3fd1b61

Browse files
authored
Forward calls to engine (#8)
1 parent 53d72e3 commit 3fd1b61

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/DebugEngine.php

+8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
namespace Pixelfear\ViewDebug;
44

55
use Illuminate\Contracts\View\Engine;
6+
use Illuminate\Support\Traits\ForwardsCalls;
67

78
class DebugEngine implements Engine
89
{
10+
use ForwardsCalls;
11+
912
protected $engine;
1013

1114
public function __construct($engine)
@@ -21,4 +24,9 @@ public function get($path, $data = [])
2124
$path
2225
]);
2326
}
27+
28+
public function __call($method, $parameters)
29+
{
30+
return $this->forwardDecoratedCallTo($this->engine, $method, $parameters);
31+
}
2432
}

tests/DebugEngineTest.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use BadMethodCallException;
6+
use Illuminate\Contracts\View\Engine;
7+
use Mockery;
8+
use Pixelfear\ViewDebug\DebugEngine;
9+
10+
class DebugEngineTest extends TestCase
11+
{
12+
/** @test */
13+
public function it_forwards_calls_to_engine()
14+
{
15+
$mock = Mockery::mock(Engine::class);
16+
$mock->shouldReceive('foo')->with('bar')->andReturn('baz');
17+
18+
$engine = new DebugEngine($mock);
19+
20+
$this->assertEquals('baz', $engine->foo('bar'));
21+
}
22+
23+
/** @test */
24+
public function it_forwards_calls_to_engine_and_allows_fluency()
25+
{
26+
$mock = Mockery::mock(Engine::class);
27+
$mock->shouldReceive('foo')->with('bar')->andReturnSelf();
28+
29+
$engine = new DebugEngine($mock);
30+
31+
$this->assertSame($engine, $engine->foo('bar'));
32+
}
33+
34+
/** @test */
35+
public function it_throw_bad_method_call_exception()
36+
{
37+
$this->expectException(BadMethodCallException::class);
38+
$this->expectExceptionMessage('Call to undefined method Pixelfear\\ViewDebug\\DebugEngine::foo()');
39+
40+
$mock = Mockery::mock(Engine::class);
41+
$mock->shouldReceive('foo')->with('bar')->andThrow(
42+
BadMethodCallException::class,
43+
'Call to undefined method '.get_class($mock).'::foo()'
44+
);
45+
46+
$engine = new DebugEngine($mock);
47+
48+
$engine->foo('bar');
49+
}
50+
}

0 commit comments

Comments
 (0)