Skip to content

Commit 1786dcc

Browse files
authored
Added type hint for Debug::getRefCount() which only support object. (#4429)
* Added type hint for `Debug::getRefCount()` which only support object. * Update CHANGELOG-2.2.md
1 parent b279d33 commit 1786dcc

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/Debug.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
class Debug
1515
{
16-
public static function getRefCount($object): string
16+
/**
17+
* Get object's ref count.
18+
*/
19+
public static function getRefCount(object $object): string
1720
{
1821
ob_start();
1922
debug_zval_dump($object);

tests/DebugTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
namespace HyperfTest\Testing;
13+
14+
use Hyperf\Testing\Debug;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* @internal
19+
* @coversNothing
20+
*/
21+
class DebugTest extends TestCase
22+
{
23+
public function testGetRefCount()
24+
{
25+
$this->assertSame('1', Debug::getRefCount(new \stdClass()));
26+
$obj = new \stdClass();
27+
$this->assertSame('2', Debug::getRefCount($obj));
28+
$obj2 = new \stdClass();
29+
$obj2->obj = $obj;
30+
$this->assertSame('2', Debug::getRefCount($obj2));
31+
$this->assertSame('3', Debug::getRefCount($obj));
32+
$fun = static function () {};
33+
$this->assertSame('2', Debug::getRefCount($fun));
34+
$this->assertSame('1', Debug::getRefCount(function () {}));
35+
}
36+
}

0 commit comments

Comments
 (0)