2018-01-28 17:17:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Abraham\TwitterOAuth\Tests;
|
|
|
|
|
2021-09-13 18:51:12 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2018-01-28 17:17:19 +00:00
|
|
|
use Abraham\TwitterOAuth\Util\JsonDecoder;
|
|
|
|
|
2021-09-13 18:51:12 +00:00
|
|
|
class JsonDecoderTest extends TestCase
|
2018-01-28 17:17:19 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider jsonProvider
|
|
|
|
*/
|
|
|
|
public function testDecode($input, $asArray, $expected)
|
|
|
|
{
|
|
|
|
$this->assertEquals($expected, JsonDecoder::decode($input, $asArray));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function jsonProvider()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
['[]', true, []],
|
|
|
|
['[1,2,3]', true, [1, 2, 3]],
|
2021-09-13 18:51:12 +00:00
|
|
|
[
|
|
|
|
'[{"id": 556179961825226750}]',
|
|
|
|
true,
|
|
|
|
[['id' => 556179961825226750]],
|
|
|
|
],
|
2018-01-28 17:17:19 +00:00
|
|
|
['[]', false, []],
|
|
|
|
['[1,2,3]', false, [1, 2, 3]],
|
|
|
|
[
|
|
|
|
'[{"id": 556179961825226750}]',
|
|
|
|
false,
|
|
|
|
[
|
|
|
|
$this->getClass(function ($object) {
|
|
|
|
$object->id = 556179961825226750;
|
|
|
|
return $object;
|
2021-09-13 18:51:12 +00:00
|
|
|
}),
|
|
|
|
],
|
2018-01-28 17:17:19 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param callable $callable
|
|
|
|
*
|
|
|
|
* @return stdClass
|
|
|
|
*/
|
|
|
|
private function getClass(\Closure $callable)
|
|
|
|
{
|
|
|
|
$object = new \stdClass();
|
|
|
|
|
|
|
|
return $callable($object);
|
|
|
|
}
|
|
|
|
}
|