Skip to content

Commit

Permalink
Merge branch 'main' of github.com:spatie/laravel-ray
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed May 2, 2024
2 parents 1f07805 + 5043df8 commit 96675b2
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.6.0
uses: dependabot/fetch-metadata@v2.1.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
compat-lookup: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/[email protected].1
uses: shivammathur/[email protected].4
with:
php-version: 8.3

- name: Install composer dependencies
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3

- name: Run PHPStan
run: vendor/bin/phpstan --error-format=github
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/[email protected].1
uses: shivammathur/[email protected].4
with:
php-version: ${{ matrix.php }}
extensions: fileinfo, dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@

All notable changes to `laravel-ray` will be documented in this file

## 1.36.1 - 2024-04-12

### What's Changed

* Bump shivammathur/setup-php from 2.30.1 to 2.30.2 by @dependabot in https://github.com/spatie/laravel-ray/pull/338
* Make implicit nullable param to explicit (PHP 8.4 compatibility) by @GromNaN in https://github.com/spatie/laravel-ray/pull/340
* Update branch alias for version 1.x by @GromNaN in https://github.com/spatie/laravel-ray/pull/341

### New Contributors

* @GromNaN made their first contribution in https://github.com/spatie/laravel-ray/pull/340

**Full Changelog**: https://github.com/spatie/laravel-ray/compare/1.36.0...1.36.1

## 1.36.0 - 2024-03-29

### What's Changed

* Bump shivammathur/setup-php from 2.29.0 to 2.30.0 by @dependabot in https://github.com/spatie/laravel-ray/pull/334
* Bump shivammathur/setup-php from 2.30.0 to 2.30.1 by @dependabot in https://github.com/spatie/laravel-ray/pull/335
* Bump dependabot/fetch-metadata from 1.6.0 to 2.0.0 by @dependabot in https://github.com/spatie/laravel-ray/pull/336
* Bump ramsey/composer-install from 2 to 3 by @dependabot in https://github.com/spatie/laravel-ray/pull/333
* Support context by @freekmurze in https://github.com/spatie/laravel-ray/pull/337

**Full Changelog**: https://github.com/spatie/laravel-ray/compare/1.35.1...1.36.0

## 1.35.1 - 2024-02-13

**Full Changelog**: https://github.com/spatie/laravel-ray/compare/1.35.0...1.35.1
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "1.29.x-dev"
"dev-main": "1.x-dev"
},
"laravel": {
"providers": [
Expand Down
2 changes: 1 addition & 1 deletion src/DumpRecorder/MultiDumpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function dump($value)
}
}

public function addHandler(callable $callable = null): self
public function addHandler(?callable $callable = null): self
{
$this->handlers[] = $callable;

Expand Down
2 changes: 1 addition & 1 deletion src/Payloads/CachePayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CachePayload extends Payload
/** @var int|null */
protected $expirationInSeconds;

public function __construct(string $type, string $key, $tags, $value = null, int $expirationInSeconds = null)
public function __construct(string $type, string $key, $tags, $value = null, ?int $expirationInSeconds = null)
{
$this->type = $type;

Expand Down
2 changes: 1 addition & 1 deletion src/Payloads/MailablePayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function forMailable(Mailable $mailable)
return new self(self::renderMailable($mailable), $mailable);
}

public function __construct(string $html, Mailable $mailable = null)
public function __construct(string $html, ?Mailable $mailable = null)
{
$this->html = $html;

Expand Down
57 changes: 55 additions & 2 deletions src/Ray.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Mail\Mailable;
use Illuminate\Mail\MailManager;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Context;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Testing\Fakes\MailFake;
Expand Down Expand Up @@ -43,7 +44,7 @@

class Ray extends BaseRay
{
public function __construct(Settings $settings, Client $client = null, string $uuid = null)
public function __construct(Settings $settings, ?Client $client = null, ?string $uuid = null)
{
// persist the enabled setting across multiple instantiations
$enabled = static::$enabled;
Expand Down Expand Up @@ -85,6 +86,58 @@ public function mailable(Mailable ...$mailables): self
return $this;
}

/**
* @param array|string ...$keys
*
* @return $this
*/
public function context(...$keys): self
{
if (! class_exists(Context::class)) {
return $this;
}

if (isset($keys[0]) && is_array($keys[0])) {
$keys = $keys[0];
}

$context = count($keys)
? Context::only($keys)
: Context::all();

$this
->send($context)
->label('Context');

return $this;
}

/**
* @param array|string ...$keys
*
* @return $this
*/
public function hiddenContext(...$keys): self
{
if (! class_exists(Context::class)) {
return $this;
}

if (isset($keys[0]) && is_array($keys[0])) {
$keys = $keys[0];
}

$hiddenContext = count($keys)
? Context::onlyHidden($keys)
: Context::allHidden();

$this
->send($hiddenContext)
->label('Hidden Context');

return $this;
}

/**
* @param Model|iterable ...$model
*
Expand Down Expand Up @@ -434,7 +487,7 @@ public function stopShowingHttpClientRequests(): self
return $this;
}

protected function handleWatcherCallable(Watcher $watcher, Closure $callable = null)
protected function handleWatcherCallable(Watcher $watcher, ?Closure $callable = null)
{
$rayProxy = new RayProxy();

Expand Down
6 changes: 6 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
|--------------------------------------------------------------------------
*/

use Illuminate\Support\Facades\Context;
use Spatie\LaravelRay\Tests\TestCase;

uses(TestCase::class)->in('.');
Expand All @@ -32,3 +33,8 @@ function assertMatchesOsSafeSnapshot($data): void

test()->expect($json)->toMatchJsonSnapshot();
}

function contextSupported(): bool
{
return class_exists(Context::class);
}
86 changes: 86 additions & 0 deletions tests/Unit/ContextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Spatie\LaravelRay\Tests\Unit;

use Illuminate\Support\Facades\Context;

it('can send all context', function () {
if (! contextSupported()) {
return;
}

Context::add('key', 'value');

ray()->context();

expect($this->client->sentRequests())->toHaveCount(2);

$requests = $this->client->sentRequests();

$clipboardData = $requests[0]['payloads'][0]['content']['meta']['0']['clipboard_data'];

expect($clipboardData)->toContain('key', 'value');
});


it('can send specific context keys variadic', function () {
if (! contextSupported()) {
return;
}

Context::add('key1', 'value1');
Context::add('key2', 'value2');
Context::add('key3', 'value3');

ray()->context('key1', 'key3');

expect($this->client->sentRequests())->toHaveCount(2);

$requests = $this->client->sentRequests();

$clipboardData = $requests[0]['payloads'][0]['content']['meta']['0']['clipboard_data'];

expect($clipboardData)->toContain('key1', 'key3');
expect($clipboardData)->not()->toContain('key2');
});

it('can send specific context keys using an array', function () {
if (! contextSupported()) {
return;
}

Context::add('key1', 'value1');
Context::add('key2', 'value2');
Context::add('key3', 'value3');

ray()->context(['key1', 'key3']);

expect($this->client->sentRequests())->toHaveCount(2);

$requests = $this->client->sentRequests();

$clipboardData = $requests[0]['payloads'][0]['content']['meta']['0']['clipboard_data'];

expect($clipboardData)->toContain('key1', 'key3');
expect($clipboardData)->not()->toContain('key2');
});

it('can send all hidden context', function () {
if (! contextSupported()) {
return;
}

Context::addHidden('hidden-key', 'hidden-value');
Context::add('visible-key', 'visible-value');

ray()->hiddenContext();

expect($this->client->sentRequests())->toHaveCount(2);

$requests = $this->client->sentRequests();

$clipboardData = $requests[0]['payloads'][0]['content']['meta']['0']['clipboard_data'];

expect($clipboardData)->toContain('hidden-key');
expect($clipboardData)->not()->toContain('visible-key');
});

0 comments on commit 96675b2

Please sign in to comment.