public function __construct($taskId, Generator $coroutine) { $this->taskId = $taskId; $this->coroutine = stackedCoroutine($coroutine); }
/** * @dataProvider testThrowProvider */ public function testThrow($coroutineFactory, $throwAtKeys, $expectedArray, $shouldThrow) { $coroutine = stackedCoroutine($coroutineFactory()); $throwAtKeys = array_flip($throwAtKeys); $hasThrown = false; $resultArray = []; try { foreach ($coroutine as $key => $value) { $resultArray[] = $value; if (isset($throwAtKeys[$key])) { $resultArray[] = $coroutine->throw(new \Exception()); } } } catch (\Exception $e) { $hasThrown = true; } if ($shouldThrow !== $hasThrown) { $this->fail('Throwiness does not match'); } $this->assertEquals($expectedArray, $resultArray); }