Skip to content

Commit a71e14b

Browse files
committed
Add tests for Action class
1 parent 42a6cee commit a71e14b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/Unit/ActionTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
use Safemood\Workflow\Action;
4+
use Safemood\Workflow\Enums\ActionState;
5+
6+
it('can set and get the state using ActionState', function () {
7+
$action = new class extends Action {
8+
public function handle(array &$context) {}
9+
};
10+
11+
$action->setState(ActionState::PENDING);
12+
13+
expect($action->getState())->toBe(ActionState::PENDING);
14+
15+
$action->setState(ActionState::SUCCESS);
16+
17+
expect($action->getState())->toBe(ActionState::SUCCESS);
18+
});
19+
20+
it('can set and get the exception', function () {
21+
$action = new class extends Action {
22+
public function handle(array &$context) {}
23+
};
24+
25+
$exception = new \Exception('Test Exception');
26+
$action->setException($exception);
27+
28+
expect($action->getException())->toBe($exception);
29+
});
30+
31+
it('should handle the abstract handle method', function () {
32+
$action = new class extends Action {
33+
public function handle(array &$context) {
34+
// Example handle logic
35+
$context['handled'] = true;
36+
}
37+
};
38+
39+
$context = [];
40+
$action->handle($context);
41+
42+
expect($context['handled'])->toBeTrue();
43+
});

0 commit comments

Comments
 (0)