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 declare(strict_types=1); /** * This file is part of CodeIgniter 4 framework. * ..

Decoded Output download

<?php

declare(strict_types=1);

/**
 * This file is part of CodeIgniter 4 framework.
 *
 * (c) CodeIgniter Foundation <[email protected]>
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace CodeIgniter\Format;

use CodeIgniter\Test\CIUnitTestCase;
use PHPUnit\Framework\Attributes\Group;
use RuntimeException;

/**
 * @internal
 */
#[Group('Others')]
final class JSONFormatterTest extends CIUnitTestCase
{
    private JSONFormatter $jsonFormatter;

    protected function setUp(): void
    {
        parent::setUp();
        $this->jsonFormatter = new JSONFormatter();
    }

    public function testBasicJSON(): void
    {
        $data = [
            'foo' => 'bar',
        ];

        $expected = '{
    "foo": "bar"
}';

        $this->assertSame($expected, $this->jsonFormatter->format($data));
    }

    public function testUnicodeOutput(): void
    {
        $data = [
            'foo' => '  ',
        ];

        $expected = '{
    "foo": "  "
}';

        $this->assertSame($expected, $this->jsonFormatter->format($data));
    }

    public function testKeepsURLs(): void
    {
        $data = [
            'foo' => 'https://www.example.com/foo/bar',
        ];

        $expected = '{
    "foo": "https://www.example.com/foo/bar"
}';

        $this->assertSame($expected, $this->jsonFormatter->format($data));
    }

    public function testJSONError(): void
    {
        $this->expectException(RuntimeException::class);

        $data     = ["1"];
        $expected = 'Boom';
        $this->assertSame($expected, $this->jsonFormatter->format($data));
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

declare(strict_types=1);

/**
 * This file is part of CodeIgniter 4 framework.
 *
 * (c) CodeIgniter Foundation <[email protected]>
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace CodeIgniter\Format;

use CodeIgniter\Test\CIUnitTestCase;
use PHPUnit\Framework\Attributes\Group;
use RuntimeException;

/**
 * @internal
 */
#[Group('Others')]
final class JSONFormatterTest extends CIUnitTestCase
{
    private JSONFormatter $jsonFormatter;

    protected function setUp(): void
    {
        parent::setUp();
        $this->jsonFormatter = new JSONFormatter();
    }

    public function testBasicJSON(): void
    {
        $data = [
            'foo' => 'bar',
        ];

        $expected = '{
    "foo": "bar"
}';

        $this->assertSame($expected, $this->jsonFormatter->format($data));
    }

    public function testUnicodeOutput(): void
    {
        $data = [
            'foo' => '  ',
        ];

        $expected = '{
    "foo": "  "
}';

        $this->assertSame($expected, $this->jsonFormatter->format($data));
    }

    public function testKeepsURLs(): void
    {
        $data = [
            'foo' => 'https://www.example.com/foo/bar',
        ];

        $expected = '{
    "foo": "https://www.example.com/foo/bar"
}';

        $this->assertSame($expected, $this->jsonFormatter->format($data));
    }

    public function testJSONError(): void
    {
        $this->expectException(RuntimeException::class);

        $data     = ["\xB1\x31"];
        $expected = 'Boom';
        $this->assertSame($expected, $this->jsonFormatter->format($data));
    }
}

Function Calls

None

Variables

None

Stats

MD5 9de498df142c9abaa82600c8cf3c9fa0
Eval Count 0
Decode Time 122 ms