Skip to content

Commit 216ad04

Browse files
committed
wip
1 parent 5d7f2fa commit 216ad04

File tree

5 files changed

+31
-79
lines changed

5 files changed

+31
-79
lines changed

src/FractionBuilder.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
use Fraction\Interpreters\AsQueue;
1616
use Fraction\ValueObjects\Then;
1717
use Illuminate\Contracts\Container\BindingResolutionException;
18+
use Illuminate\Contracts\Support\Arrayable;
1819
use Illuminate\Foundation\Application;
1920
use InvalidArgumentException;
2021
use Laravel\SerializableClosure\SerializableClosure;
2122
use UnitEnum;
2223

23-
final class FractionBuilder
24+
final class FractionBuilder implements Arrayable
2425
{
25-
public array $then = [];
26+
private array $then = [];
2627

27-
public ?QueueUsing $queued = null;
28+
private ?QueueUsing $queued = null;
2829

29-
public ?DeferUsing $deferred = null;
30+
private ?DeferUsing $deferred = null;
3031

3132
public function __construct(
3233
public Application $application,
@@ -59,7 +60,7 @@ public function __invoke(...$arguments): mixed
5960

6061
$instance = $interpreter->then($this->then);
6162

62-
if ($interpreter instanceof Configurable) {
63+
if ($interpreter instanceof Configurable && ($this->queued || $this->deferred)) {
6364
$interpreter->configure($this->queued?->toArray() ?? $this->deferred->toArray());
6465
}
6566

@@ -97,4 +98,15 @@ public function deferred(
9798

9899
return $this;
99100
}
101+
102+
public function toArray(): array
103+
{
104+
return [
105+
'action' => $this->action,
106+
'closure' => $this->closure,
107+
'then' => $this->then,
108+
'queued' => $this->queued,
109+
'deferred' => $this->deferred,
110+
];
111+
}
100112
}

src/FractionManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
final class FractionManager
1515
{
16-
public array $fractions = [];
16+
private array $fractions = [];
1717

1818
public function __construct(public Application $application)
1919
{

tests/Feature/Execution/AsDefaultTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@
7272
return 1;
7373
});
7474

75-
expect($builder->queued)->toBeNull();
75+
expect($builder->toArray()['queued'])->toBeNull();
7676
});
7777

7878
test('not deferred', function () {
7979
$builder = execute('testing', function () {
8080
return 1;
8181
});
8282

83-
expect($builder->deferred)->toBeNull();
83+
expect($builder->toArray()['deferred'])->toBeNull();
8484
});
8585

8686
test('call then', function () {
@@ -159,19 +159,21 @@
159159
->then('tree')
160160
->then('four');
161161

162-
expect($builder->then)
162+
$array = $builder->toArray();
163+
164+
expect($array['then'])
163165
->toHaveCount(3)
164-
->and($builder->then[0])
166+
->and($array['then'][0])
165167
->toBeInstanceOf(Then::class)
166-
->and($builder->then[0]->then)
168+
->and($array['then'][0]->then)
167169
->toBe('two')
168-
->and($builder->then[1])
170+
->and($array['then'][1])
169171
->toBeInstanceOf(Then::class)
170-
->and($builder->then[1]->then)
172+
->and($array['then'][1]->then)
171173
->toBe('tree')
172-
->and($builder->then[2])
174+
->and($array['then'][2])
173175
->toBeInstanceOf(Then::class)
174-
->and($builder->then[2]->then)
176+
->and($array['then'][2]->then)
175177
->toBe('four');
176178
});
177179

tests/Feature/Execution/AsDeferTest.php

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
declare(strict_types=1);
44

5-
use Fraction\ValueObjects\Then;
6-
75
beforeEach(fn () => __delete());
86

97
afterAll(fn () => __delete());
@@ -21,7 +19,7 @@
2119
return 1;
2220
})->deferred();
2321

24-
expect($builder->queued)->toBeNull();
22+
expect($builder->toArray()['queued'])->toBeNull();
2523
});
2624

2725
test('call then', function () {
@@ -38,63 +36,3 @@
3836

3937
expect($test)->toBeTrue();
4038
});
41-
42-
test('call then sequentially', function () {
43-
execute('one', function () {
44-
return 1;
45-
})
46-
->then('two')
47-
->then('tree')
48-
->then('four');
49-
50-
execute('two', function () {
51-
__output('two');
52-
});
53-
54-
execute('tree', function () {
55-
__output('tree');
56-
});
57-
58-
execute('four', function () {
59-
__output('four');
60-
});
61-
62-
$test = run('one');
63-
64-
expect($test)
65-
->toBe(1)
66-
->and(__exists('two'))
67-
->toBeTrue()
68-
->and(__exists('tree'))
69-
->toBeTrue()
70-
->and(__exists('four'))
71-
->toBeTrue();
72-
});
73-
74-
test('ensure then order', function () {
75-
$builder = execute('one', function () {
76-
return 1;
77-
})
78-
->deferred()
79-
->then('two')
80-
->then('tree')
81-
->then('four');
82-
83-
expect($builder->deferred())
84-
->not()
85-
->toBeNull()
86-
->and($builder->then)
87-
->toHaveCount(3)
88-
->and($builder->then[0])
89-
->toBeInstanceOf(Then::class)
90-
->and($builder->then[0]->then)
91-
->toBe('two')
92-
->and($builder->then[1])
93-
->toBeInstanceOf(Then::class)
94-
->and($builder->then[1]->then)
95-
->toBe('tree')
96-
->and($builder->then[2])
97-
->toBeInstanceOf(Then::class)
98-
->and($builder->then[2]->then)
99-
->toBe('four');
100-
});

tests/Feature/Execution/AsQueueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
return 1;
2727
})->deferred();
2828

29-
expect($builder->queued)->toBeNull();
29+
expect($builder->toArray()['queued'])->toBeNull();
3030
});
3131

3232
test('call then', function () {

0 commit comments

Comments
 (0)