mirror of
https://github.com/filp/whoops.git
synced 2026-08-30 03:58:17 +00:00
Add unit test for callback generated data tables
This commit is contained in:
@@ -119,6 +119,60 @@ class PrettyPageHandlerTest extends TestCase
|
||||
$this->assertEmpty($handler->getDataTables('ZIMBABWE!'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Handler\PrettyPageHandler::getDataTables
|
||||
* @covers Whoops\Handler\PrettyPageHandler::addDataTableCallback
|
||||
*/
|
||||
public function testSetCallbackDataTables()
|
||||
{
|
||||
$handler = $this->getHandler();
|
||||
|
||||
$this->assertEmpty($handler->getDataTables());
|
||||
$table1 = function() {
|
||||
return array(
|
||||
'hammer' => 'time',
|
||||
'foo' => 'bar',
|
||||
);
|
||||
};
|
||||
$expected1 = array('hammer' => 'time', 'foo' => 'bar');
|
||||
|
||||
$table2 = function() use ($expected1) {
|
||||
return array(
|
||||
'another' => 'table',
|
||||
'this' => $expected1,
|
||||
);
|
||||
};
|
||||
$expected2 = array('another' => 'table', 'this' => $expected1);
|
||||
|
||||
$table3 = create_function('', 'return array("oh my" => "how times have changed!");');
|
||||
$expected3 = array('oh my' => 'how times have changed!');
|
||||
|
||||
// Sanity check, make sure expected values really are correct.
|
||||
$this->assertSame($expected1, $table1());
|
||||
$this->assertSame($expected2, $table2());
|
||||
$this->assertSame($expected3, $table3());
|
||||
|
||||
$handler->addDataTableCallback('table1', $table1);
|
||||
$handler->addDataTableCallback('table2', $table2);
|
||||
$handler->addDataTableCallback('table3', $table3);
|
||||
|
||||
$tables = $handler->getDataTables();
|
||||
$this->assertCount(3, $tables);
|
||||
|
||||
// Supplied callable is wrapped in a closure
|
||||
$this->assertInstanceOf('Closure', $tables['table1']);
|
||||
$this->assertInstanceOf('Closure', $tables['table2']);
|
||||
$this->assertInstanceOf('Closure', $tables['table3']);
|
||||
|
||||
// Run each wrapped callable and check results against expected output.
|
||||
$this->assertEquals($expected1, $tables['table1']());
|
||||
$this->assertEquals($expected2, $tables['table2']());
|
||||
$this->assertEquals($expected3, $tables['table3']());
|
||||
|
||||
$this->assertSame($tables['table1'], $handler->getDataTables('table1'));
|
||||
$this->assertSame($expected1, call_user_func($handler->getDataTables('table1')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Handler\PrettyPageHandler::setEditor
|
||||
* @covers Whoops\Handler\PrettyPageHandler::getEditorHref
|
||||
|
||||
Reference in New Issue
Block a user