1
0
mirror of https://github.com/halaxa/json-machine.git synced 2025-07-17 04:21:16 +02:00
Files
json-machine/test/ExtTokensTest.php
2023-08-14 12:36:16 +02:00

36 lines
950 B
PHP

<?php
declare(strict_types=1);
use JsonMachine\Exception\JsonMachineException;
use PHPUnit\Framework\TestCase;
/**
* @covers \ExtTokens
*/
class ExtTokensTest extends TestCase
{
public function testExtTokensIterates()
{
if ( ! class_exists(ExtTokens::class)) {
$this->markTestSkipped();
}
$extTokens = new ExtTokens(new ArrayIterator(['1.0', '1', '2', '3', '5', '[]']));
$this->assertInstanceOf(Iterator::class, $extTokens);
$this->assertSame(['1.01235', '[', ']'], iterator_to_array($extTokens));
}
public function testThrowsOnNonStringChunk()
{
if ( ! class_exists(ExtTokens::class)) {
$this->markTestSkipped();
}
$extTokens = new ExtTokens(new ArrayIterator(['true', 10]));
$this->expectException(JsonMachineException::class);
$this->expectExceptionMessage('string');
iterator_to_array($extTokens);
}
}