Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Mar 29, 2024
1 parent 571f06a commit eddcb60
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
7 changes: 2 additions & 5 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ function assertMatchesOsSafeSnapshot($data): void
test()->expect($json)->toMatchJsonSnapshot();
}

function onlyIfContextSupported()
function contextSupported(): bool
{

if (!class_exists(Context::class)) {
test()->skip('Context is not supported for this Laravel version');
}
return class_exists(Context::class);
}
24 changes: 20 additions & 4 deletions tests/Unit/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
use Illuminate\Support\Facades\Context;

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

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

ray()->context();
Expand All @@ -16,10 +20,14 @@
$clipboardData = $requests[0]['payloads'][0]['content']['meta']['0']['clipboard_data'];

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


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

Context::add('key1', 'value1');
Context::add('key2', 'value2');
Context::add('key3', 'value3');
Expand All @@ -34,9 +42,13 @@

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

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');
Expand All @@ -51,9 +63,13 @@

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

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

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

Expand All @@ -67,4 +83,4 @@

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

0 comments on commit eddcb60

Please sign in to comment.