generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #337 from spatie/support-context
Support context
- Loading branch information
Showing
5 changed files
with
165 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ docs | |
phpunit.xml | ||
psalm.xml | ||
vendor | ||
.phpunit.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Spatie Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
<logging> | ||
<junit outputFile="build/report.junit.xml"/> | ||
</logging> | ||
<php> | ||
<env name="APP_DEBUG" value="true" /> | ||
<env name="CACHE_DRIVER" value="array" /> | ||
<env name="CACHE_STORE" value="array" /> | ||
</php> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false"> | ||
<testsuites> | ||
<testsuite name="Spatie Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging> | ||
<junit outputFile="build/report.junit.xml"/> | ||
</logging> | ||
<php> | ||
<env name="APP_DEBUG" value="true"/> | ||
<env name="CACHE_DRIVER" value="array"/> | ||
<env name="CACHE_STORE" value="array"/> | ||
</php> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |