Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php /** * This file is part of PhpRedisJSON library * * @project phpredis-json * @..

Decoded Output download

<?php
/**
 * This file is part of PhpRedisJSON library
 *
 * @project   phpredis-json
 * @author    Rafael Campoy <[email protected]>
 * @copyright 2019 Rafael Campoy <[email protected]>
 * @license   MIT
 * @link      https://github.com/averias/phpredis-json
 *
 * Copyright and license information, is included in
 * the LICENSE file that is distributed with this source code.
 */

namespace Averias\RedisJson\Tests\Unit\Parser\Response;

use Averias\RedisJson\Parser\Response\DecodeFromJson;
use PHPUnit\Framework\TestCase;

class DecodeFromJsonTest extends TestCase
{
    public function testNoDecodeIfFalse()
    {
        $parser = new DecodeFromJson();
        $result = $parser->parse(false);
        $this->assertNull($result);
    }

    /**
     * @dataProvider getDecodeJsonDataProvider
     * @param string $response
     */
    public function testDecode(string $response)
    {
        $parser = new DecodeFromJson();
        $result = $parser->parse($response);
        $this->assertSame(json_decode($response, true), $result);
    }

    public function getDecodeJsonDataProvider()
    {
        return [
            ['{"key1":"value1","key2":false,"key3":18,"key4":11.2,"key5":["array-value1","array-value2"]}'],
            ['1.79'],
            ['34'],
            ['"Peter"'],
            ["false"]
        ];
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php
/**
 * This file is part of PhpRedisJSON library
 *
 * @project   phpredis-json
 * @author    Rafael Campoy <[email protected]>
 * @copyright 2019 Rafael Campoy <[email protected]>
 * @license   MIT
 * @link      https://github.com/averias/phpredis-json
 *
 * Copyright and license information, is included in
 * the LICENSE file that is distributed with this source code.
 */

namespace Averias\RedisJson\Tests\Unit\Parser\Response;

use Averias\RedisJson\Parser\Response\DecodeFromJson;
use PHPUnit\Framework\TestCase;

class DecodeFromJsonTest extends TestCase
{
    public function testNoDecodeIfFalse()
    {
        $parser = new DecodeFromJson();
        $result = $parser->parse(false);
        $this->assertNull($result);
    }

    /**
     * @dataProvider getDecodeJsonDataProvider
     * @param string $response
     */
    public function testDecode(string $response)
    {
        $parser = new DecodeFromJson();
        $result = $parser->parse($response);
        $this->assertSame(json_decode($response, true), $result);
    }

    public function getDecodeJsonDataProvider()
    {
        return [
            ['{"key1":"value1","key2":false,"key3":18,"key4":11.2,"key5":["array-value1","array-value2"]}'],
            ['1.79'],
            ['34'],
            ['"Peter"'],
            ["false"]
        ];
    }
}

Function Calls

None

Variables

None

Stats

MD5 0dbc688ee16a33671e9f1d216625b820
Eval Count 0
Decode Time 101 ms