public function testExternalException() { $gen = (function () { $this->assertInstanceOf(\RuntimeException::class, (yield CoInterface::SAFE => null)); (yield null); })(); $con = new GeneratorContainer($gen); $con->key() === CoInterface::SAFE ? $con->send(new \RuntimeException()) : $con->throw_(new \RuntimeException()); $this->assertTrue($con->valid()); $this->assertFalse($con->thrown()); $gen = (function () { (yield null); (yield null); })(); $con = new GeneratorContainer($gen); $con->key() === CoInterface::SAFE ? $con->send(new \RuntimeException()) : $con->throw_(new \RuntimeException()); $this->assertFalse($con->valid()); $this->assertTrue($con->thrown()); $this->assertInstanceOf(\RuntimeException::class, $con->getReturnOrThrown()); }