/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/JsonStreamer/Tests/Read/DecoderTest.php
62 строки
2 KB
Mathias Arlaud
[JsonStreamer] Rename the component
26 фев 2025, 14:49
Не верифицирован
26 фев 2025, 14:49
924a01d
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\JsonStreamer\Tests\Read; use PHPUnit\Framework\TestCase; use Symfony\Component\JsonStreamer\Exception\UnexpectedValueException; use Symfony\Component\JsonStreamer\Read\Decoder; class DecoderTest extends TestCase { public function testDecode() { $this->assertDecoded('foo', '"foo"'); } public function testDecodeSubset() { $this->assertDecoded('bar', '["foo","bar","baz"]', 7, 5); } public function testDecodeThrowOnInvalidJsonString() { $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage('JSON is not valid: Syntax error'); Decoder::decodeString('foo"'); } public function testDecodeThrowOnInvalidJsonStream() { $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage('JSON is not valid: Syntax error'); $resource = fopen('php://temp', 'w'); fwrite($resource, 'foo"'); rewind($resource); Decoder::decodeStream($resource); } private function assertDecoded(mixed $decoded, string $encoded, int $offset = 0, ?int $length = null): void { if (0 === $offset && null === $length) { $this->assertEquals($decoded, Decoder::decodeString($encoded)); } $resource = fopen('php://temp', 'w'); fwrite($resource, $encoded); rewind($resource); $this->assertEquals($decoded, Decoder::decodeStream($resource, $offset, $length)); } }