Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/GuardEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(ExpressionLanguage $expressionLanguage)

protected function registerCustomFunctions()
{
$customFunctions = config('workflow.custom_functions', []);
$customFunctions = config('workflow-process.custom_functions', []);

foreach ($customFunctions as $name => $definition) {
if (is_string($definition) && class_exists($definition)) {
Expand Down
56 changes: 56 additions & 0 deletions tests/Feature/GuardFunctions/AuthenticatedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

use Illuminate\Support\Facades\Auth;
use Mockery;

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.4 - L12.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.4 - L12.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.4 - L11.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.4 - L11.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.4 - L10.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L12.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.4 - L10.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L12.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L10.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L11.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L11.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L11.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L11.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L10.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L10.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 4 in tests/Feature/GuardFunctions/AuthenticatedTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L10.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect
use Soap\LaravelWorkflowProcess\GuardFunctions\Authenticated;

afterEach(function () {
// Ensure that all mock expectations are met and clean up
Mockery::close();
});

test('compile returns authenticated("web") when no guard argument is provided', function () {
$guardFunction = new Authenticated;
$compiled = $guardFunction->compile();
expect($compiled)->toBe('authenticated("web")');
});

test('compile returns authenticated("custom") when a custom guard is provided', function () {
$guardFunction = new Authenticated;
$compiled = $guardFunction->compile('custom');
expect($compiled)->toBe('authenticated("custom")');
});

test('evaluate returns true when the default guard is authenticated', function () {
$guardFunction = new Authenticated;

// Create a mock for the default "web" guard that returns true for check().
$guardMock = Mockery::mock();
$guardMock->shouldReceive('check')->once()->andReturn(true);

// Expect the default guard to be used.
Auth::shouldReceive('guard')
->once()
->with('web')
->andReturn($guardMock);

$result = $guardFunction->evaluate([]);
expect($result)->toBeTrue();
});

test('evaluate returns false when the custom guard is not authenticated', function () {
$guardFunction = new Authenticated;

// Create a mock for the "custom" guard that returns false for check().
$guardMock = Mockery::mock();
$guardMock->shouldReceive('check')->once()->andReturn(false);

// Expect the custom guard to be used.
Auth::shouldReceive('guard')
->once()
->with('custom')
->andReturn($guardMock);

$result = $guardFunction->evaluate([], 'custom');
expect($result)->toBeFalse();
});
4 changes: 2 additions & 2 deletions tests/GuardEvaluatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
it('evaluates a custom closure guard function correctly', function () {
// Set a test configuration for custom guard functions.
// Here we define a function named "checkFlag" that returns the value of a 'flag' variable.
config()->set('workflow.custom_functions', [
config()->set('workflow-process.custom_functions', [
'checkFlag' => [
'compiler' => function () {
// The compiler returns a placeholder expression.
Expand Down Expand Up @@ -35,7 +35,7 @@

it('evaluates a custom guard function defined as a class correctly', function () {
// Set the configuration so that the custom function points to our evaluator class.
config()->set('workflow.custom_functions', [
config()->set('workflow-process.custom_functions', [
'checkFlag' => CheckFlagGuardFunction::class,
]);

Expand Down
Loading