This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Serializer/Tests/Encoder/JsonEncodeTest.php

64 lines
1.6 KiB
PHP
Raw Normal View History

<?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\Serializer\Tests\Encoder;
2017-02-18 17:42:54 +00:00
use PHPUnit\Framework\TestCase;
2019-07-31 20:19:25 +01:00
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
use Symfony\Component\Serializer\Encoder\JsonEncode;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
2017-02-18 17:42:54 +00:00
class JsonEncodeTest extends TestCase
{
2019-07-31 20:19:25 +01:00
use ForwardCompatTestTrait;
private $encoder;
2019-07-31 20:19:25 +01:00
private function doSetUp()
{
$this->encode = new JsonEncode();
}
public function testSupportsEncoding()
{
$this->assertTrue($this->encode->supportsEncoding(JsonEncoder::FORMAT));
$this->assertFalse($this->encode->supportsEncoding('foobar'));
}
/**
* @dataProvider encodeProvider
*/
public function testEncode($toEncode, $expected, $context)
{
$this->assertEquals(
$expected,
$this->encode->encode($toEncode, JsonEncoder::FORMAT, $context)
);
}
public function encodeProvider()
{
2019-01-16 09:39:14 +00:00
return [
[[], '[]', []],
[[], '{}', ['json_encode_options' => JSON_FORCE_OBJECT]],
];
}
/**
* @requires function json_last_error_msg
*/
public function testEncodeWithError()
{
2019-08-01 23:48:42 +01:00
$this->expectException('Symfony\Component\Serializer\Exception\UnexpectedValueException');
2017-01-21 16:59:38 +00:00
$this->encode->encode("\xB1\x31", JsonEncoder::FORMAT);
}
}