Commit 97ab718e authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-79: Add __debugInfo() handlers for info classes

parent 87932a56
...@@ -76,4 +76,15 @@ class CollectionInfo ...@@ -76,4 +76,15 @@ class CollectionInfo
{ {
return isset($this->info['options']['size']) ? (integer) $this->info['options']['size'] : null; return isset($this->info['options']['size']) ? (integer) $this->info['options']['size'] : null;
} }
/**
* Return the collection info as an array.
*
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
* @return array
*/
public function __debugInfo()
{
return $this->info;
}
} }
...@@ -55,4 +55,15 @@ class DatabaseInfo ...@@ -55,4 +55,15 @@ class DatabaseInfo
{ {
return (boolean) $this->info['empty']; return (boolean) $this->info['empty'];
} }
/**
* Return the collection info as an array.
*
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
* @return array
*/
public function __debugInfo()
{
return $this->info;
}
} }
...@@ -157,4 +157,15 @@ class IndexInfo implements ArrayAccess ...@@ -157,4 +157,15 @@ class IndexInfo implements ArrayAccess
{ {
throw new BadMethodCallException('IndexInfo is immutable'); throw new BadMethodCallException('IndexInfo is immutable');
} }
/**
* Return the collection info as an array.
*
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
* @return array
*/
public function __debugInfo()
{
return $this->info;
}
} }
...@@ -39,4 +39,15 @@ class CollectionInfoTest extends TestCase ...@@ -39,4 +39,15 @@ class CollectionInfoTest extends TestCase
$this->assertSame(100, $info->getCappedMax()); $this->assertSame(100, $info->getCappedMax());
$this->assertSame(1048576, $info->getCappedSize()); $this->assertSame(1048576, $info->getCappedSize());
} }
public function testDebugInfo()
{
$expectedInfo = array(
'name' => 'foo',
'options' => array('capped' => true, 'size' => 1048576),
);
$info = new CollectionInfo($expectedInfo);
$this->assertSame($expectedInfo, $info->__debugInfo());
}
} }
...@@ -15,7 +15,7 @@ class DatabaseInfoTest extends TestCase ...@@ -15,7 +15,7 @@ class DatabaseInfoTest extends TestCase
public function testGetSizeOnDisk() public function testGetSizeOnDisk()
{ {
$info = new DatabaseInfo(array('sizeOnDisk' => '1048576')); $info = new DatabaseInfo(array('sizeOnDisk' => 1048576));
$this->assertSame(1048576, $info->getSizeOnDisk()); $this->assertSame(1048576, $info->getSizeOnDisk());
} }
...@@ -27,4 +27,16 @@ class DatabaseInfoTest extends TestCase ...@@ -27,4 +27,16 @@ class DatabaseInfoTest extends TestCase
$info = new DatabaseInfo(array('empty' => true)); $info = new DatabaseInfo(array('empty' => true));
$this->assertTrue($info->isEmpty()); $this->assertTrue($info->isEmpty());
} }
public function testDebugInfo()
{
$expectedInfo = array(
'name' => 'foo',
'sizeOnDisk' => 1048576,
'empty' => false,
);
$info = new DatabaseInfo($expectedInfo);
$this->assertSame($expectedInfo, $info->__debugInfo());
}
} }
...@@ -83,4 +83,17 @@ class IndexInfoTest extends TestCase ...@@ -83,4 +83,17 @@ class IndexInfoTest extends TestCase
$this->assertTrue(isset($info['expireAfterSeconds'])); $this->assertTrue(isset($info['expireAfterSeconds']));
$this->assertSame(100, $info['expireAfterSeconds']); $this->assertSame(100, $info['expireAfterSeconds']);
} }
public function testDebugInfo()
{
$expectedInfo = array(
'v' => 1,
'key' => array('x' => 1),
'name' => 'x_1',
'ns' => 'foo.bar',
);
$info = new IndexInfo($expectedInfo);
$this->assertSame($expectedInfo, $info->__debugInfo());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment