Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagof committed Sep 11, 2024
2 parents 17832e9 + d75fa4a commit 8947e10
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/Traits/HasVolition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function rule(string|Rule $rule): ?Rule
*
* @return Collection<\Squarebit\Volition\Contracts\IsAction>
*/
public function actions(string|Rule $forRule = null): Collection
public function actions(string|Rule|null $forRule = null): Collection
{
$actions = $forRule
? $this->rule($forRule)?->actions
Expand All @@ -62,7 +62,7 @@ public function actions(string|Rule $forRule = null): Collection
* @param class-string<TActionClass> $ofClass
* @return TActionClass|null
*/
public function action(string $ofClass, string $forRule = null, bool $throw = false): ?IsAction
public function action(string $ofClass, ?string $forRule = null, bool $throw = false): ?IsAction
{
$action = $this->actions($forRule)->firstWhere(fn (IsAction $action) => $action instanceof $ofClass);

Expand All @@ -78,7 +78,7 @@ public function action(string $ofClass, string $forRule = null, bool $throw = fa
/**
* @param class-string<\Squarebit\Volition\Contracts\IsAction> $actionClass
*/
public function executeAction(string $actionClass, string $forRule = null, bool $throw = false): mixed
public function executeAction(string $actionClass, ?string $forRule = null, bool $throw = false): mixed
{
return $this->action($actionClass, $forRule, $throw)?->execute($this);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Volition.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Volition
protected array $actions = [];

/**
* @return class-string<IsCondition|IsAction>|null
* @return class-string<IsCondition|IsAction>|null
*/
public function getElement(string $elementType, bool $throw = false): ?string
{
Expand All @@ -32,15 +32,15 @@ public function getElement(string $elementType, bool $throw = false): ?string
}

/**
* @return array<int, class-string<IsCondition>>
* @return array<int, class-string<IsCondition>>
*/
public function getConditions(): array
{
return $this->conditions;
}

/**
* @return array<int, class-string<IsAction>>
* @return array<int, class-string<IsAction>>
*/
public function getActions(): array
{
Expand Down
9 changes: 3 additions & 6 deletions tests/Feature/PayloadCastTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<?php

use Squarebit\Volition\Database\Factories\ActionFactory;
use Squarebit\Volition\Database\Factories\ConditionFactory;
use Squarebit\Volition\Database\Factories\RuleFactory;
use Squarebit\Volition\Facades\Volition;
use Squarebit\Volition\Models\Action;
use Squarebit\Volition\Models\Condition;
use Squarebit\Volition\Models\Rule;
use Squarebit\Volition\Tests\Support\ObjectPropertyCondition;
use Squarebit\Volition\Tests\Support\PrefixAction;
use Squarebit\Volition\Tests\Support\SuffixAction;
use Squarebit\Volition\Tests\Support\TestObject;

use function Pest\Laravel\artisan;

beforeEach(function () {
Expand All @@ -21,12 +18,12 @@
Condition::insert([
'rule_id' => $rule->id,
'enabled' => 1,
'payload' => serialize(new ObjectPropertyCondition('some_property', 'some_value'))
'payload' => serialize(new ObjectPropertyCondition('some_property', 'some_value')),
]);
Action::insert([
'rule_id' => $rule->id,
'enabled' => 1,
'payload' => serialize(new PrefixAction('some_value'))
'payload' => serialize(new PrefixAction('some_value')),
]);
});

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/VolitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
});

test('fails to registers Actions as Conditions or vice-versa', function () {
expect(fn() => Volition::registerConditions([
expect(fn () => Volition::registerConditions([
PrefixAction::class,
SuffixAction::class,
]))->toThrow(Exception::class);

expect(fn() => Volition::registerActions([
expect(fn () => Volition::registerActions([
ObjectPropertyCondition::class,
]))->toThrow(Exception::class);
});

0 comments on commit 8947e10

Please sign in to comment.