Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 3.1-merge
# Conflicts: # src/service-governance-nacos/src/ClientFactory.php
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of Hyperf. | ||
* | ||
* @link https://www.hyperf.io | ||
* @document https://hyperf.wiki | ||
* @contact group@hyperf.io | ||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE | ||
*/ | ||
namespace Hyperf\Codec\Packer; | ||
|
||
use Hyperf\Contract\PackerInterface; | ||
|
||
class IgbinarySerializerPacker implements PackerInterface | ||
{ | ||
public function pack($data): string | ||
{ | ||
return igbinary_serialize($data); | ||
} | ||
|
||
public function unpack(string $data) | ||
{ | ||
return igbinary_unserialize($data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of Hyperf. | ||
* | ||
* @link https://www.hyperf.io | ||
* @document https://hyperf.wiki | ||
* @contact group@hyperf.io | ||
* @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() | ||
{ | ||
$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() | ||
{ | ||
$packer = new IgbinarySerializerPacker(); | ||
$this->expectException(Exception::class); | ||
$packer->unpack('invalid binary string'); | ||
} | ||
} |