Skip to content

Commit e9306a7

Browse files
authored
Merge pull request #8 from soap/develop
Bug fixed: wrong configuration file loading
2 parents 6947ea4 + ca96e56 commit e9306a7

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

src/GuardEvaluator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(ExpressionLanguage $expressionLanguage)
1717

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

2222
foreach ($customFunctions as $name => $definition) {
2323
if (is_string($definition) && class_exists($definition)) {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Auth;
4+
use Mockery;
5+
use Soap\LaravelWorkflowProcess\GuardFunctions\Authenticated;
6+
7+
afterEach(function () {
8+
// Ensure that all mock expectations are met and clean up
9+
Mockery::close();
10+
});
11+
12+
test('compile returns authenticated("web") when no guard argument is provided', function () {
13+
$guardFunction = new Authenticated;
14+
$compiled = $guardFunction->compile();
15+
expect($compiled)->toBe('authenticated("web")');
16+
});
17+
18+
test('compile returns authenticated("custom") when a custom guard is provided', function () {
19+
$guardFunction = new Authenticated;
20+
$compiled = $guardFunction->compile('custom');
21+
expect($compiled)->toBe('authenticated("custom")');
22+
});
23+
24+
test('evaluate returns true when the default guard is authenticated', function () {
25+
$guardFunction = new Authenticated;
26+
27+
// Create a mock for the default "web" guard that returns true for check().
28+
$guardMock = Mockery::mock();
29+
$guardMock->shouldReceive('check')->once()->andReturn(true);
30+
31+
// Expect the default guard to be used.
32+
Auth::shouldReceive('guard')
33+
->once()
34+
->with('web')
35+
->andReturn($guardMock);
36+
37+
$result = $guardFunction->evaluate([]);
38+
expect($result)->toBeTrue();
39+
});
40+
41+
test('evaluate returns false when the custom guard is not authenticated', function () {
42+
$guardFunction = new Authenticated;
43+
44+
// Create a mock for the "custom" guard that returns false for check().
45+
$guardMock = Mockery::mock();
46+
$guardMock->shouldReceive('check')->once()->andReturn(false);
47+
48+
// Expect the custom guard to be used.
49+
Auth::shouldReceive('guard')
50+
->once()
51+
->with('custom')
52+
->andReturn($guardMock);
53+
54+
$result = $guardFunction->evaluate([], 'custom');
55+
expect($result)->toBeFalse();
56+
});

tests/GuardEvaluatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
it('evaluates a custom closure guard function correctly', function () {
88
// Set a test configuration for custom guard functions.
99
// Here we define a function named "checkFlag" that returns the value of a 'flag' variable.
10-
config()->set('workflow.custom_functions', [
10+
config()->set('workflow-process.custom_functions', [
1111
'checkFlag' => [
1212
'compiler' => function () {
1313
// The compiler returns a placeholder expression.
@@ -35,7 +35,7 @@
3535

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

0 commit comments

Comments
 (0)