Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Events/InjectedXrayBar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace BeyondCode\ViewXray\Events;

use Illuminate\Http\Response;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;

class InjectedXrayBar
{
use SerializesModels;

/** @var Response */
private $response;

public function __construct(Response $response)
{
$this->response = $response;
}

/**
* @return Response
*/
public function getResponse()
{
return $this->response;
}
}
3 changes: 3 additions & 0 deletions src/XrayMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace BeyondCode\ViewXray;

use BeyondCode\ViewXray\Events\InjectedXrayBar;
use Closure;

class XrayMiddleware
Expand Down Expand Up @@ -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));
}
}
34 changes: 34 additions & 0 deletions tests/XrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Route;
use Spatie\Snapshots\MatchesSnapshots;
use BeyondCode\ViewXray\Events\InjectedXrayBar;
use Illuminate\Support\Facades\Event;

class XrayTest extends TestCase
{
Expand Down Expand Up @@ -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);
}
}