1
0
mirror of https://github.com/danog/amp.git synced 2024-12-11 08:59:46 +01:00
amp/test/InvalidYieldErrorTest.php
Niklas Keller c12828081f Fix exceptions bubbling from Coroutine::__destruct
This has been an edge case potentially hiding some exceptions. The tests have been refactored to error if the loop has watchers leaking from one test to another test.
2019-05-31 11:38:02 -05:00

39 lines
939 B
PHP

<?php
namespace Amp\Test;
use Amp\InvalidYieldError;
class InvalidYieldErrorTest extends BaseTest
{
public function testWithInvalidGenerator()
{
/** @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());
}
public function testSubgenerator()
{
$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());
}
}