From 6a188385e938be16099fabadd18918d20ffe40be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=89=E1=85=AE=E1=84=92?= =?UTF-8?q?=E1=85=A7=E1=86=AB?= <54769955+xharpenParksuhyeon@users.noreply.github.com> Date: Sat, 25 Feb 2023 03:44:09 +0900 Subject: [PATCH 1/3] Defined an InjectedXrayBar event. --- src/Events/InjectedXrayBar.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/Events/InjectedXrayBar.php 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; + } +} From 3a4f7a220f3b76a64589695a08c85c41da577f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=89=E1=85=AE=E1=84=92?= =?UTF-8?q?=E1=85=A7=E1=86=AB?= <54769955+xharpenParksuhyeon@users.noreply.github.com> Date: Sat, 25 Feb 2023 03:45:24 +0900 Subject: [PATCH 2/3] Dispatched an InjectedXrayBar event. --- src/XrayMiddleware.php | 3 +++ 1 file changed, 3 insertions(+) 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 From 4df81fae738ecd1e84400e9692ad8a72411d29ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=89=E1=85=AE=E1=84=92?= =?UTF-8?q?=E1=85=A7=E1=86=AB?= <54769955+xharpenParksuhyeon@users.noreply.github.com> Date: Sat, 25 Feb 2023 04:12:16 +0900 Subject: [PATCH 3/3] Adding code to test the InjectedXrayBar event. --- tests/XrayTest.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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); + } }