Skip to content

Commit bcf394b

Browse files
committed
Add tests for Recoil::some() with zero required strands.
1 parent 408e485 commit bcf394b

1 file changed

Lines changed: 57 additions & 18 deletions

File tree

test-kernel/api/functional.some.spec.php

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,6 @@ function () {
5252
$strand->terminate();
5353
});
5454

55-
it('throws when the count is zero', function () {
56-
try {
57-
yield Recoil::some(
58-
0,
59-
function () {
60-
},
61-
function () {
62-
}
63-
);
64-
} catch (InvalidArgumentException $e) {
65-
expect($e->getMessage())->to->equal(
66-
'Can not wait for 0 coroutines, count must be between 1 and 2, inclusive.'
67-
);
68-
}
69-
});
70-
7155
it('throws when the count is negative', function () {
7256
try {
7357
yield Recoil::some(
@@ -79,7 +63,7 @@ function () {
7963
);
8064
} catch (InvalidArgumentException $e) {
8165
expect($e->getMessage())->to->equal(
82-
'Can not wait for -1 coroutines, count must be between 1 and 2, inclusive.'
66+
'Can not wait for -1 coroutines, count must be between 0 and 2, inclusive.'
8367
);
8468
}
8569
});
@@ -95,7 +79,7 @@ function () {
9579
);
9680
} catch (InvalidArgumentException $e) {
9781
expect($e->getMessage())->to->equal(
98-
'Can not wait for 3 coroutines, count must be between 1 and 2, inclusive.'
82+
'Can not wait for 3 coroutines, count must be between 0 and 2, inclusive.'
9983
);
10084
}
10185
});
@@ -186,6 +170,61 @@ function () {
186170
});
187171
});
188172

173+
context('when the count is zero', function () {
174+
it('returns an empty array', function () {
175+
expect(yield Recoil::some(
176+
0,
177+
function () {
178+
yield;
179+
180+
return 'a';
181+
},
182+
function () {
183+
return 'b';
184+
yield;
185+
},
186+
function () {
187+
return 'c';
188+
yield;
189+
}
190+
))->to->equal([]);
191+
});
192+
193+
it('terminates all strands', function () {
194+
yield Recoil::some(
195+
0,
196+
function () {
197+
yield;
198+
expect(false)->to->be->ok('strand was not terminated');
199+
},
200+
function () {
201+
yield;
202+
expect(false)->to->be->ok('strand was not terminated');
203+
}
204+
);
205+
});
206+
207+
it('yields control to another strand', function () {
208+
ob_start();
209+
210+
yield Recoil::execute(function () {
211+
echo 'b';
212+
213+
return;
214+
yield;
215+
});
216+
217+
echo 'a';
218+
yield Recoil::some(0, function () {
219+
yield;
220+
expect(false)->to->be->ok('strand was not terminated');
221+
});
222+
echo 'c';
223+
224+
expect(ob_get_clean())->to->equal('abc');
225+
});
226+
});
227+
189228
context('when no coroutines are provided', function () {
190229
it('yields control to another strand', function () {
191230
ob_start();

0 commit comments

Comments
 (0)