diff --git a/src/Events/InjectedXrayBar.php b/src/Events/InjectedXrayBar.php new file mode 100644 index 0000000..8210051 --- /dev/null +++ b/src/Events/InjectedXrayBar.php @@ -0,0 +1,28 @@ +response = $response; + } + + /** + * @return Response + */ + public function getResponse() + { + return $this->response; + } +} diff --git a/src/XrayMiddleware.php b/src/XrayMiddleware.php index 5f76b55..8d4275e 100644 --- a/src/XrayMiddleware.php +++ b/src/XrayMiddleware.php @@ -2,6 +2,7 @@ namespace BeyondCode\ViewXray; +use BeyondCode\ViewXray\Events\InjectedXrayBar; use Closure; class XrayMiddleware @@ -114,5 +115,7 @@ protected function injectXrayBar($response) // Update the new content and reset the content length $response->setContent($content); $response->headers->remove('Content-Length'); + + event(new InjectedXrayBar($response)); } } \ No newline at end of file diff --git a/tests/XrayTest.php b/tests/XrayTest.php index c6a66b4..c98501d 100644 --- a/tests/XrayTest.php +++ b/tests/XrayTest.php @@ -4,6 +4,8 @@ use Route; use Spatie\Snapshots\MatchesSnapshots; +use BeyondCode\ViewXray\Events\InjectedXrayBar; +use Illuminate\Support\Facades\Event; class XrayTest extends TestCase { @@ -46,4 +48,36 @@ public function it_adds_xray_when_using_parenthesis_on_sections() $this->assertMatchesSnapshot($response->getContent()); } + + /** @test */ + public function it_fires_an_event_if_injected_xray_bar() + { + Event::fake(); + + Route::get('/', function () { + return view('example'); + }); + + $this->get('/'); + + Event::assertDispatched(InjectedXrayBar::class); + } + + /** @test */ + public function it_does_not_fire_an_event_if_injected_xray_bar() + { + Event::fake(); + + $data = [ + 'foo' => 'bar' + ]; + + Route::get('/', function () use ($data) { + return $data; + }); + + $this->get('/'); + + Event::assertNotDispatched(InjectedXrayBar::class); + } }