1
0
mirror of https://github.com/danog/amp.git synced 2024-11-27 04:24:42 +01:00
amp/test/InvalidYieldErrorTest.php
Niklas Keller fe88413a17 Upgrade to PHPUnit 6
This commit removes Humbug, as it's no longer maintained and not
compatible with PHPUnit 6.
2017-03-11 14:57:03 +01:00

35 lines
949 B
PHP

<?php
namespace Amp\Test;
use Amp\InvalidYieldError;
class InvalidYieldErrorTest extends \PHPUnit\Framework\TestCase {
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());
}
}