Skip to content

Commit 97ab718

Browse files
committed
PHPLIB-79: Add __debugInfo() handlers for info classes
1 parent 87932a5 commit 97ab718

File tree

6 files changed

+70
-1
lines changed

6 files changed

+70
-1
lines changed

src/Model/CollectionInfo.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,15 @@ public function getCappedSize()
7676
{
7777
return isset($this->info['options']['size']) ? (integer) $this->info['options']['size'] : null;
7878
}
79+
80+
/**
81+
* Return the collection info as an array.
82+
*
83+
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
84+
* @return array
85+
*/
86+
public function __debugInfo()
87+
{
88+
return $this->info;
89+
}
7990
}

src/Model/DatabaseInfo.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,15 @@ public function isEmpty()
5555
{
5656
return (boolean) $this->info['empty'];
5757
}
58+
59+
/**
60+
* Return the collection info as an array.
61+
*
62+
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
63+
* @return array
64+
*/
65+
public function __debugInfo()
66+
{
67+
return $this->info;
68+
}
5869
}

src/Model/IndexInfo.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,15 @@ public function offsetUnset($key)
157157
{
158158
throw new BadMethodCallException('IndexInfo is immutable');
159159
}
160+
161+
/**
162+
* Return the collection info as an array.
163+
*
164+
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
165+
* @return array
166+
*/
167+
public function __debugInfo()
168+
{
169+
return $this->info;
170+
}
160171
}

tests/Model/CollectionInfoTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,15 @@ public function testCappedCollectionMethods()
3939
$this->assertSame(100, $info->getCappedMax());
4040
$this->assertSame(1048576, $info->getCappedSize());
4141
}
42+
43+
public function testDebugInfo()
44+
{
45+
$expectedInfo = array(
46+
'name' => 'foo',
47+
'options' => array('capped' => true, 'size' => 1048576),
48+
);
49+
50+
$info = new CollectionInfo($expectedInfo);
51+
$this->assertSame($expectedInfo, $info->__debugInfo());
52+
}
4253
}

tests/Model/DatabaseInfoTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function testGetName()
1515

1616
public function testGetSizeOnDisk()
1717
{
18-
$info = new DatabaseInfo(array('sizeOnDisk' => '1048576'));
18+
$info = new DatabaseInfo(array('sizeOnDisk' => 1048576));
1919
$this->assertSame(1048576, $info->getSizeOnDisk());
2020
}
2121

@@ -27,4 +27,16 @@ public function testIsEmpty()
2727
$info = new DatabaseInfo(array('empty' => true));
2828
$this->assertTrue($info->isEmpty());
2929
}
30+
31+
public function testDebugInfo()
32+
{
33+
$expectedInfo = array(
34+
'name' => 'foo',
35+
'sizeOnDisk' => 1048576,
36+
'empty' => false,
37+
);
38+
39+
$info = new DatabaseInfo($expectedInfo);
40+
$this->assertSame($expectedInfo, $info->__debugInfo());
41+
}
3042
}

tests/Model/IndexInfoTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,17 @@ public function testTtlIndex()
8383
$this->assertTrue(isset($info['expireAfterSeconds']));
8484
$this->assertSame(100, $info['expireAfterSeconds']);
8585
}
86+
87+
public function testDebugInfo()
88+
{
89+
$expectedInfo = array(
90+
'v' => 1,
91+
'key' => array('x' => 1),
92+
'name' => 'x_1',
93+
'ns' => 'foo.bar',
94+
);
95+
96+
$info = new IndexInfo($expectedInfo);
97+
$this->assertSame($expectedInfo, $info->__debugInfo());
98+
}
8699
}

0 commit comments

Comments
 (0)