Skip to content

Commit

Permalink
Added type hint for Debug::getRefCount() which only support object.…
Browse files Browse the repository at this point in the history
… (#4429)

* Added type hint for `Debug::getRefCount()` which only support object.

* Update CHANGELOG-2.2.md
  • Loading branch information
limingxinleo authored Jan 4, 2022
1 parent b279d33 commit 1786dcc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

class Debug
{
public static function getRefCount($object): string
/**
* Get object's ref count.
*/
public static function getRefCount(object $object): string
{
ob_start();
debug_zval_dump($object);
Expand Down
36 changes: 36 additions & 0 deletions tests/DebugTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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\Testing;

use Hyperf\Testing\Debug;
use PHPUnit\Framework\TestCase;

/**
* @internal
* @coversNothing
*/
class DebugTest extends TestCase
{
public function testGetRefCount()
{
$this->assertSame('1', Debug::getRefCount(new \stdClass()));
$obj = new \stdClass();
$this->assertSame('2', Debug::getRefCount($obj));
$obj2 = new \stdClass();
$obj2->obj = $obj;
$this->assertSame('2', Debug::getRefCount($obj2));
$this->assertSame('3', Debug::getRefCount($obj));
$fun = static function () {};
$this->assertSame('2', Debug::getRefCount($fun));
$this->assertSame('1', Debug::getRefCount(function () {}));
}
}

0 comments on commit 1786dcc

Please sign in to comment.