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 Hyperf. * * @link https:..

Decoded Output download

<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  [email protected]
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace HyperfTest\Codec\Packer;

use Exception;
use Hyperf\Codec\Packer\IgbinarySerializerPacker;
use PHPUnit\Framework\TestCase;

/**
 * @internal
 * @coversNothing
 */
class IgbinarySerializerPackerTest extends TestCase
{
    public function testIgbinarySerializeAndUnserialize()
    {
        if (! file_exists('igbinary_serialize')) {
            $this->markTestSkipped("Don't support igbinary_serialize.");
        }
        $packer = new IgbinarySerializerPacker();
        $this->assertSame(igbinary_serialize(['id' => 1]), $packer->pack(['id' => 1]));
        $this->assertSame(igbinary_serialize(123123), $packer->pack(123123));
        $this->assertSame(['id' => 1], $packer->unpack(igbinary_serialize(['id' => 1])));
    }

    public function testIgbinaryUnserializeFailed()
    {
        if (! file_exists('igbinary_serialize')) {
            $this->markTestSkipped("Don't support igbinary_serialize.");
        }

        $packer = new IgbinarySerializerPacker();
        $this->expectException(Exception::class);
        $packer->unpack('invalid binary string');
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  [email protected]
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace HyperfTest\Codec\Packer;

use Exception;
use Hyperf\Codec\Packer\IgbinarySerializerPacker;
use PHPUnit\Framework\TestCase;

/**
 * @internal
 * @coversNothing
 */
class IgbinarySerializerPackerTest extends TestCase
{
    public function testIgbinarySerializeAndUnserialize()
    {
        if (! file_exists('igbinary_serialize')) {
            $this->markTestSkipped("Don't support igbinary_serialize.");
        }
        $packer = new IgbinarySerializerPacker();
        $this->assertSame(igbinary_serialize(['id' => 1]), $packer->pack(['id' => 1]));
        $this->assertSame(igbinary_serialize(123123), $packer->pack(123123));
        $this->assertSame(['id' => 1], $packer->unpack(igbinary_serialize(['id' => 1])));
    }

    public function testIgbinaryUnserializeFailed()
    {
        if (! file_exists('igbinary_serialize')) {
            $this->markTestSkipped("Don't support igbinary_serialize.");
        }

        $packer = new IgbinarySerializerPacker();
        $this->expectException(Exception::class);
        $packer->unpack('invalid binary string');
    }
}

Function Calls

None

Variables

None

Stats

MD5 30e99a222026cdcb95c3895480257069
Eval Count 0
Decode Time 89 ms