2016-12-11 17:08:17 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp\Test;
|
|
|
|
|
|
|
|
use Amp\InvalidYieldError;
|
|
|
|
|
2019-05-14 21:37:08 +02:00
|
|
|
class InvalidYieldErrorTest extends BaseTest
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
|
|
|
public function testWithInvalidGenerator()
|
|
|
|
{
|
2016-12-11 17:08:17 +01:00
|
|
|
/** @var \Generator $gen */
|
|
|
|
$gen = (function () {
|
|
|
|
if (false) {
|
|
|
|
yield;
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
$gen->current();
|
|
|
|
|
|
|
|
$error = new InvalidYieldError($gen, "prefix message");
|
|
|
|
$this->assertSame("prefix message; NULL yielded at key NULL", $error->getMessage());
|
|
|
|
}
|
|
|
|
|
2018-06-18 20:00:01 +02:00
|
|
|
public function testSubgenerator()
|
|
|
|
{
|
2016-12-11 17:08:17 +01:00
|
|
|
$subgen = (function () {
|
|
|
|
yield "foo" => 42;
|
|
|
|
})();
|
|
|
|
|
|
|
|
/** @var \Generator $gen */
|
|
|
|
$gen = (function () use ($subgen) {
|
|
|
|
yield from $subgen;
|
|
|
|
})();
|
|
|
|
|
|
|
|
$error = new InvalidYieldError($gen, "prefix");
|
|
|
|
$this->assertSame("prefix; integer yielded at key 'foo' on line " . (__LINE__ - 8) . " in " . __FILE__, $error->getMessage());
|
|
|
|
}
|
2017-04-24 15:39:08 +02:00
|
|
|
}
|