-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeferTest.php
More file actions
44 lines (29 loc) · 930 Bytes
/
DeferTest.php
File metadata and controls
44 lines (29 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php declare(strict_types=1);
namespace Versary\EffectSystem;
use PHPUnit\Framework\TestCase;
use Versary\EffectSystem\Tests\DeferTest\{Defer, DeferHandler};
class DeferTest extends TestCase
{
public int $v = 0;
function program() {
$this->v = 1;
yield new Defer(fn () => $this->v = 3);
$this->assertEquals(1, $this->v);
}
public function test_basic() {
Effect::run(Effect::handle($this->program(), new DeferHandler));
$this->assertEquals(3, $this->v);
}
}
namespace Versary\EffectSystem\Tests\DeferTest;
use Versary\EffectSystem\{Effect, Handler};
class Defer extends Effect {
public function __construct(public \Closure $closure) {}
}
class DeferHandler extends Handler {
public static $effect = Defer::class;
public function handle(mixed $effect, \Closure $resume) {
yield from $resume(null);
($effect->closure)();
}
}