the whole shebang
This commit is contained in:
150
vendor/filp/whoops/tests/Whoops/Exception/FrameCollectionTest.php
vendored
Normal file
150
vendor/filp/whoops/tests/Whoops/Exception/FrameCollectionTest.php
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* Whoops - php errors for cool kids
|
||||
* @author Filipe Dobreira <http://github.com/filp>
|
||||
*/
|
||||
|
||||
namespace Whoops\Exception;
|
||||
use Whoops\Exception\FrameCollection;
|
||||
use Whoops\TestCase;
|
||||
use Mockery as m;
|
||||
|
||||
class FrameCollectionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Stupid little counter for tagging frames
|
||||
* with a unique but predictable id
|
||||
* @var int
|
||||
*/
|
||||
private $frameIdCounter = 0;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFrameData()
|
||||
{
|
||||
$id = ++$this->frameIdCounter;
|
||||
return array(
|
||||
'file' => __DIR__ . '/../../fixtures/frame.lines-test.php',
|
||||
'line' => $id,
|
||||
'function' => 'test-' . $id,
|
||||
'class' => 'MyClass',
|
||||
'args' => array(true, 'hello')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $total
|
||||
* @return array
|
||||
*/
|
||||
public function getFrameDataList($total)
|
||||
{
|
||||
$total = max((int) $total, 1);
|
||||
$self = $this;
|
||||
$frames = array_map(function() use($self) {
|
||||
return $self->getFrameData();
|
||||
}, range(1, $total));
|
||||
|
||||
return $frames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $frames
|
||||
* @return Whoops\Exception\FrameCollection
|
||||
*/
|
||||
private function getFrameCollectionInstance($frames = null)
|
||||
{
|
||||
if($frames === null) {
|
||||
$frames = $this->getFrameDataList(10);
|
||||
}
|
||||
|
||||
return new FrameCollection($frames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::filter
|
||||
* @covers Whoops\Exception\FrameCollection::count
|
||||
*/
|
||||
public function testFilterFrames()
|
||||
{
|
||||
$frames = $this->getFrameCollectionInstance();
|
||||
|
||||
// Filter out all frames with a line number under 6
|
||||
$frames->filter(function($frame) {
|
||||
return $frame->getLine() <= 5;
|
||||
});
|
||||
|
||||
$this->assertCount(5, $frames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::map
|
||||
*/
|
||||
public function testMapFrames()
|
||||
{
|
||||
$frames = $this->getFrameCollectionInstance();
|
||||
|
||||
// Filter out all frames with a line number under 6
|
||||
$frames->map(function($frame) {
|
||||
$frame->addComment("This is cool", "test");
|
||||
return $frame;
|
||||
});
|
||||
|
||||
$this->assertCount(10, $frames);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::map
|
||||
* @expectedException UnexpectedValueException
|
||||
*/
|
||||
public function testMapFramesEnforceType()
|
||||
{
|
||||
$frames = $this->getFrameCollectionInstance();
|
||||
|
||||
// Filter out all frames with a line number under 6
|
||||
$frames->map(function($frame) {
|
||||
return "bajango";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::getArray
|
||||
*/
|
||||
public function testGetArray()
|
||||
{
|
||||
$frames = $this->getFrameCollectionInstance();
|
||||
$frames = $frames->getArray();
|
||||
|
||||
$this->assertCount(10, $frames);
|
||||
foreach($frames as $frame) {
|
||||
$this->assertInstanceOf('Whoops\\Exception\\Frame', $frame);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::getIterator
|
||||
*/
|
||||
public function testCollectionIsIterable()
|
||||
{
|
||||
$frames = $this->getFrameCollectionInstance();
|
||||
foreach($frames as $frame) {
|
||||
$this->assertInstanceOf('Whoops\\Exception\\Frame', $frame);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::serialize
|
||||
* @covers Whoops\Exception\FrameCollection::unserialize
|
||||
*/
|
||||
public function testCollectionIsSerializable()
|
||||
{
|
||||
$frames = $this->getFrameCollectionInstance();
|
||||
$serializedFrames = serialize($frames);
|
||||
$newFrames = unserialize($serializedFrames);
|
||||
|
||||
foreach($newFrames as $frame) {
|
||||
$this->assertInstanceOf('Whoops\\Exception\\Frame', $frame);
|
||||
}
|
||||
}
|
||||
}
|
209
vendor/filp/whoops/tests/Whoops/Exception/FrameTest.php
vendored
Normal file
209
vendor/filp/whoops/tests/Whoops/Exception/FrameTest.php
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* Whoops - php errors for cool kids
|
||||
* @author Filipe Dobreira <http://github.com/filp>
|
||||
*/
|
||||
|
||||
namespace Whoops\Exception;
|
||||
use Whoops\Exception\Frame;
|
||||
use Whoops\TestCase;
|
||||
use Mockery as m;
|
||||
|
||||
class FrameTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getFrameData()
|
||||
{
|
||||
return array(
|
||||
'file' => __DIR__ . '/../../fixtures/frame.lines-test.php',
|
||||
'line' => 0,
|
||||
'function' => 'test',
|
||||
'class' => 'MyClass',
|
||||
'args' => array(true, 'hello')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return Whoops\Exception\Frame
|
||||
*/
|
||||
private function getFrameInstance($data = null)
|
||||
{
|
||||
if($data === null) {
|
||||
$data = $this->getFrameData();
|
||||
}
|
||||
|
||||
return new Frame($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Frame::getFile
|
||||
*/
|
||||
public function testGetFile()
|
||||
{
|
||||
$data = $this->getFrameData();
|
||||
$frame = $this->getFrameInstance($data);
|
||||
|
||||
$this->assertEquals($frame->getFile(), $data['file']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Frame::getLine
|
||||
*/
|
||||
public function testGetLine()
|
||||
{
|
||||
$data = $this->getFrameData();
|
||||
$frame = $this->getFrameInstance($data);
|
||||
|
||||
$this->assertEquals($frame->getLine(), $data['line']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Frame::getClass
|
||||
*/
|
||||
public function testGetClass()
|
||||
{
|
||||
$data = $this->getFrameData();
|
||||
$frame = $this->getFrameInstance($data);
|
||||
|
||||
$this->assertEquals($frame->getClass(), $data['class']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Frame::getFunction
|
||||
*/
|
||||
public function testGetFunction()
|
||||
{
|
||||
$data = $this->getFrameData();
|
||||
$frame = $this->getFrameInstance($data);
|
||||
|
||||
$this->assertEquals($frame->getFunction(), $data['function']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Frame::getArgs
|
||||
*/
|
||||
public function testGetArgs()
|
||||
{
|
||||
$data = $this->getFrameData();
|
||||
$frame = $this->getFrameInstance($data);
|
||||
|
||||
$this->assertEquals($frame->getArgs(), $data['args']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Frame::getFileContents
|
||||
*/
|
||||
public function testGetFileContents()
|
||||
{
|
||||
$data = $this->getFrameData();
|
||||
$frame = $this->getFrameInstance($data);
|
||||
|
||||
$this->assertEquals($frame->getFileContents(), file_get_contents($data['file']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Frame::getFileLines
|
||||
*/
|
||||
public function testGetFileLines()
|
||||
{
|
||||
$data = $this->getFrameData();
|
||||
$frame = $this->getFrameInstance($data);
|
||||
|
||||
$lines = explode("\n", $frame->getFileContents());
|
||||
$this->assertEquals($frame->getFileLines(), $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Frame::getFileLines
|
||||
*/
|
||||
public function testGetFileLinesRange()
|
||||
{
|
||||
$data = $this->getFrameData();
|
||||
$frame = $this->getFrameInstance($data);
|
||||
|
||||
$lines = $frame->getFileLines(0, 3);
|
||||
|
||||
$this->assertEquals($lines[0], '<?php');
|
||||
$this->assertEquals($lines[1], '// Line 2');
|
||||
$this->assertEquals($lines[2], '// Line 3');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Frame::addComment
|
||||
* @covers Whoops\Exception\Frame::getComments
|
||||
*/
|
||||
public function testGetComments()
|
||||
{
|
||||
$frame = $this->getFrameInstance();
|
||||
$testComments = array(
|
||||
'Dang, yo!',
|
||||
'Errthangs broken!',
|
||||
'Dayumm!'
|
||||
);
|
||||
|
||||
$frame->addComment($testComments[0]);
|
||||
$frame->addComment($testComments[1]);
|
||||
$frame->addComment($testComments[2]);
|
||||
|
||||
$comments = $frame->getComments();
|
||||
|
||||
$this->assertCount(3, $comments);
|
||||
|
||||
$this->assertEquals($comments[0]['comment'], $testComments[0]);
|
||||
$this->assertEquals($comments[1]['comment'], $testComments[1]);
|
||||
$this->assertEquals($comments[2]['comment'], $testComments[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Frame::addComment
|
||||
* @covers Whoops\Exception\Frame::getComments
|
||||
*/
|
||||
public function testGetFilteredComments()
|
||||
{
|
||||
$frame = $this->getFrameInstance();
|
||||
$testComments = array(
|
||||
array('Dang, yo!', 'test'),
|
||||
array('Errthangs broken!', 'test'),
|
||||
'Dayumm!'
|
||||
);
|
||||
|
||||
$frame->addComment($testComments[0][0], $testComments[0][1]);
|
||||
$frame->addComment($testComments[1][0], $testComments[1][1]);
|
||||
$frame->addComment($testComments[2][0], $testComments[2][1]);
|
||||
|
||||
$comments = $frame->getComments('test');
|
||||
|
||||
$this->assertCount(2, $comments);
|
||||
$this->assertEquals($comments[0]['comment'], $testComments[0][0]);
|
||||
$this->assertEquals($comments[1]['comment'], $testComments[1][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Frame::serialize
|
||||
* @covers Whoops\Exception\Frame::unserialize
|
||||
*/
|
||||
public function testFrameIsSerializable()
|
||||
{
|
||||
$data = $this->getFrameData();
|
||||
$frame = $this->getFrameInstance();
|
||||
$commentText = "Gee I hope this works";
|
||||
$commentContext = "test";
|
||||
|
||||
$frame->addComment($commentText, $commentContext);
|
||||
|
||||
$serializedFrame = serialize($frame);
|
||||
$newFrame = unserialize($serializedFrame);
|
||||
|
||||
$this->assertInstanceOf('Whoops\\Exception\\Frame', $newFrame);
|
||||
$this->assertEquals($newFrame->getFile(), $data['file']);
|
||||
$this->assertEquals($newFrame->getLine(), $data['line']);
|
||||
|
||||
$comments = $newFrame->getComments();
|
||||
$this->assertCount(1, $comments);
|
||||
$this->assertEquals($comments[0]["comment"], $commentText);
|
||||
$this->assertEquals($comments[0]["context"], $commentContext);
|
||||
}
|
||||
}
|
67
vendor/filp/whoops/tests/Whoops/Exception/InspectorTest.php
vendored
Normal file
67
vendor/filp/whoops/tests/Whoops/Exception/InspectorTest.php
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Whoops - php errors for cool kids
|
||||
* @author Filipe Dobreira <http://github.com/filp>
|
||||
*/
|
||||
|
||||
namespace Whoops\Exception;
|
||||
use Whoops\Exception\Inspector;
|
||||
use Whoops\TestCase;
|
||||
use RuntimeException;
|
||||
use Exception;
|
||||
use Mockery as m;
|
||||
|
||||
class InspectorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $message
|
||||
* @return Exception
|
||||
*/
|
||||
protected function getException($message = null)
|
||||
{
|
||||
return m::mock('Exception', array($message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Exception $exception|null
|
||||
* @return Whoops\Exception\Inspector
|
||||
*/
|
||||
protected function getInspectorInstance(Exception $exception = null)
|
||||
{
|
||||
return new Inspector($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Inspector::getExceptionName
|
||||
*/
|
||||
public function testReturnsCorrectExceptionName()
|
||||
{
|
||||
$exception = $this->getException();
|
||||
$inspector = $this->getInspectorInstance($exception);
|
||||
|
||||
$this->assertEquals(get_class($exception), $inspector->getExceptionName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Inspector::__construct
|
||||
* @covers Whoops\Exception\Inspector::getException
|
||||
*/
|
||||
public function testExceptionIsStoredAndReturned()
|
||||
{
|
||||
$exception = $this->getException();
|
||||
$inspector = $this->getInspectorInstance($exception);
|
||||
|
||||
$this->assertSame($exception, $inspector->getException());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\Inspector::getFrames
|
||||
*/
|
||||
public function testGetFramesReturnsCollection()
|
||||
{
|
||||
$exception = $this->getException();
|
||||
$inspector = $this->getInspectorInstance($exception);
|
||||
|
||||
$this->assertInstanceOf('Whoops\\Exception\\FrameCollection', $inspector->getFrames());
|
||||
}
|
||||
}
|
96
vendor/filp/whoops/tests/Whoops/Handler/JsonResponseHandlerTest.php
vendored
Normal file
96
vendor/filp/whoops/tests/Whoops/Handler/JsonResponseHandlerTest.php
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Whoops - php errors for cool kids
|
||||
* @author Filipe Dobreira <http://github.com/filp>
|
||||
*/
|
||||
|
||||
namespace Whoops\Handler;
|
||||
use Whoops\TestCase;
|
||||
use Whoops\Handler\JsonResponseHandler;
|
||||
use RuntimeException;
|
||||
|
||||
class JsonResponseHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @return Whoops\Handler\JsonResponseHandler
|
||||
*/
|
||||
private function getHandler()
|
||||
{
|
||||
return new JsonResponseHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RuntimeException
|
||||
*/
|
||||
public function getException($message = 'test message')
|
||||
{
|
||||
return new RuntimeException($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $withTrace
|
||||
* @return array
|
||||
*/
|
||||
private function getJsonResponseFromHandler($withTrace = false)
|
||||
{
|
||||
$handler = $this->getHandler();
|
||||
$handler->addTraceToOutput($withTrace);
|
||||
|
||||
$run = $this->getRunInstance();
|
||||
$run->pushHandler($handler);
|
||||
$run->register();
|
||||
|
||||
$exception = $this->getException();
|
||||
ob_start();
|
||||
$run->handleException($exception);
|
||||
$json = json_decode(ob_get_clean(), true);
|
||||
|
||||
// Check that the json response is parse-able:
|
||||
$this->assertEquals(json_last_error(), JSON_ERROR_NONE);
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Handler\JsonResponseHandler::addTraceToOutput
|
||||
* @covers Whoops\Handler\JsonResponseHandler::handle
|
||||
*/
|
||||
public function testReturnsWithoutFrames()
|
||||
{
|
||||
$json = $this->getJsonResponseFromHandler($withTrace = false);
|
||||
|
||||
// Check that the response has the expected keys:
|
||||
$this->assertArrayHasKey('error', $json);
|
||||
$this->assertArrayHasKey('type', $json['error']);
|
||||
$this->assertArrayHasKey('file', $json['error']);
|
||||
$this->assertArrayHasKey('line', $json['error']);
|
||||
|
||||
// Check the field values:
|
||||
$this->assertEquals($json['error']['file'], __FILE__);
|
||||
$this->assertEquals($json['error']['message'], 'test message');
|
||||
$this->assertEquals($json['error']['type'], get_class($this->getException()));
|
||||
|
||||
// Check that the trace is NOT returned:
|
||||
$this->assertArrayNotHasKey('trace', $json['error']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Handler\JsonResponseHandler::addTraceToOutput
|
||||
* @covers Whoops\Handler\JsonResponseHandler::handle
|
||||
*/
|
||||
public function testReturnsWithFrames()
|
||||
{
|
||||
$json = $this->getJsonResponseFromHandler($withTrace = true);
|
||||
|
||||
// Check that the trace is returned:
|
||||
$this->assertArrayHasKey('trace', $json['error']);
|
||||
|
||||
// Check that a random frame has the expected fields
|
||||
$traceFrame = reset($json['error']['trace']);
|
||||
$this->assertArrayHasKey('file', $traceFrame);
|
||||
$this->assertArrayHasKey('line', $traceFrame);
|
||||
$this->assertArrayHasKey('function', $traceFrame);
|
||||
$this->assertArrayHasKey('class', $traceFrame);
|
||||
$this->assertArrayHasKey('args', $traceFrame);
|
||||
}
|
||||
}
|
268
vendor/filp/whoops/tests/Whoops/Handler/PrettyPageHandlerTest.php
vendored
Normal file
268
vendor/filp/whoops/tests/Whoops/Handler/PrettyPageHandlerTest.php
vendored
Normal file
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
/**
|
||||
* Whoops - php errors for cool kids
|
||||
* @author Filipe Dobreira <http://github.com/filp>
|
||||
*/
|
||||
|
||||
namespace Whoops\Handler;
|
||||
use Whoops\TestCase;
|
||||
use Whoops\Handler\PrettyPageHandler;
|
||||
use RuntimeException;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class PrettyPageHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @return Whoops\Handler\JsonResponseHandler
|
||||
*/
|
||||
private function getHandler()
|
||||
{
|
||||
return new PrettyPageHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RuntimeException
|
||||
*/
|
||||
public function getException()
|
||||
{
|
||||
return new RuntimeException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that PrettyPageHandle handles the template without
|
||||
* any errors.
|
||||
* @covers Whoops\Handler\PrettyPageHandler::handle
|
||||
*/
|
||||
public function testHandleWithoutErrors()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
$handler = $this->getHandler();
|
||||
|
||||
$run->pushHandler($handler);
|
||||
|
||||
ob_start();
|
||||
$run->handleException($this->getException());
|
||||
ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Handler\PrettyPageHandler::setPageTitle
|
||||
* @covers Whoops\Handler\PrettyPageHandler::getPageTitle
|
||||
*/
|
||||
public function testGetSetPageTitle()
|
||||
{
|
||||
$title = 'My Cool Error Handler';
|
||||
$handler = $this->getHandler();
|
||||
$handler->setPageTitle($title);
|
||||
|
||||
$this->assertEquals($title, $handler->getPagetitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Handler\PrettyPageHandler::setResourcesPath
|
||||
* @covers Whoops\Handler\PrettyPageHandler::getResourcesPath
|
||||
*/
|
||||
public function testGetSetResourcesPath()
|
||||
{
|
||||
$path = __DIR__; // guaranteed to be valid!
|
||||
$handler = $this->getHandler();
|
||||
|
||||
$handler->setResourcesPath($path);
|
||||
$this->assertEquals($path, $handler->getResourcesPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Handler\PrettyPageHandler::setResourcesPath
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testSetInvalidResourcesPath()
|
||||
{
|
||||
$path = __DIR__ . '/ZIMBABWE'; // guaranteed to be invalid!
|
||||
$this->getHandler()->setResourcesPath($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Handler\PrettyPageHandler::getDataTables
|
||||
* @covers Whoops\Handler\PrettyPageHandler::addDataTable
|
||||
*/
|
||||
public function testGetSetDataTables()
|
||||
{
|
||||
$handler = $this->getHandler();
|
||||
|
||||
// should have no tables by default:
|
||||
$this->assertEmpty($handler->getDataTables());
|
||||
|
||||
$tableOne = array(
|
||||
'ice' => 'cream',
|
||||
'ice-ice' => 'baby'
|
||||
);
|
||||
|
||||
$tableTwo = array(
|
||||
'dolan' =>'pls',
|
||||
'time' => time()
|
||||
);
|
||||
|
||||
$handler->addDataTable('table 1', $tableOne);
|
||||
$handler->addDataTable('table 2', $tableTwo);
|
||||
|
||||
// should contain both tables:
|
||||
$tables = $handler->getDataTables();
|
||||
$this->assertCount(2, $tables);
|
||||
|
||||
$this->assertEquals($tableOne, $tables['table 1']);
|
||||
$this->assertEquals($tableTwo, $tables['table 2']);
|
||||
|
||||
// should contain only table 1
|
||||
$this->assertEquals($tableOne, $handler->getDataTables('table 1'));
|
||||
|
||||
// should return an empty table:
|
||||
$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
|
||||
*/
|
||||
public function testSetEditorSimple()
|
||||
{
|
||||
$handler = $this->getHandler();
|
||||
$handler->setEditor('sublime');
|
||||
|
||||
$this->assertEquals(
|
||||
$handler->getEditorHref('/foo/bar.php', 10),
|
||||
'subl://open?url=file://%2Ffoo%2Fbar.php&line=10'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$handler->getEditorHref('/foo/with space?.php', 2324),
|
||||
'subl://open?url=file://%2Ffoo%2Fwith%20space%3F.php&line=2324'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$handler->getEditorHref('/foo/bar/with-dash.php', 0),
|
||||
'subl://open?url=file://%2Ffoo%2Fbar%2Fwith-dash.php&line=0'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Handler\PrettyPageHandler::setEditor
|
||||
* @covers Whoops\Handler\PrettyPageHandler::getEditorHref
|
||||
*/
|
||||
public function testSetEditorCallable()
|
||||
{
|
||||
$handler = $this->getHandler();
|
||||
$handler->setEditor(function($file, $line) {
|
||||
$file = rawurlencode($file);
|
||||
$line = rawurlencode($line);
|
||||
return "http://google.com/search/?q=$file:$line";
|
||||
});
|
||||
|
||||
$this->assertEquals(
|
||||
$handler->getEditorHref('/foo/bar.php', 10),
|
||||
'http://google.com/search/?q=%2Ffoo%2Fbar.php:10'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Handler\PrettyPageHandler::setEditor
|
||||
* @covers Whoops\Handler\PrettyPageHandler::addEditor
|
||||
* @covers Whoops\Handler\PrettyPageHandler::getEditorHref
|
||||
*/
|
||||
public function testAddEditor()
|
||||
{
|
||||
$handler = $this->getHandler();
|
||||
$handler->addEditor('test-editor', function($file, $line) {
|
||||
return "cool beans $file:$line";
|
||||
});
|
||||
|
||||
$handler->setEditor('test-editor');
|
||||
|
||||
$this->assertEquals(
|
||||
$handler->getEditorHref('hello', 20),
|
||||
'cool beans hello:20'
|
||||
);
|
||||
}
|
||||
|
||||
public function testEditorXdebug()
|
||||
{
|
||||
if (!extension_loaded('xdebug')) {
|
||||
$this->markTestSkipped('xdebug is not available');
|
||||
}
|
||||
|
||||
$originalValue = ini_get('xdebug.file_link_format');
|
||||
|
||||
$handler = $this->getHandler();
|
||||
$handler->setEditor('xdebug');
|
||||
|
||||
ini_set('xdebug.file_link_format', '%f:%l');
|
||||
|
||||
$this->assertEquals(
|
||||
'/foo/bar.php:10',
|
||||
$handler->getEditorHref('/foo/bar.php', 10)
|
||||
);
|
||||
|
||||
ini_set('xdebug.file_link_format', 'subl://open?url=%f&line=%l');
|
||||
|
||||
// xdebug doesn't do any URL encoded, matching that behaviour.
|
||||
$this->assertEquals(
|
||||
'subl://open?url=/foo/with space?.php&line=2324',
|
||||
$handler->getEditorHref('/foo/with space?.php', 2324)
|
||||
);
|
||||
|
||||
ini_set('xdebug.file_link_format', $originalValue);
|
||||
}
|
||||
}
|
330
vendor/filp/whoops/tests/Whoops/RunTest.php
vendored
Executable file
330
vendor/filp/whoops/tests/Whoops/RunTest.php
vendored
Executable file
@@ -0,0 +1,330 @@
|
||||
<?php
|
||||
/**
|
||||
* Whoops - php errors for cool kids
|
||||
* @author Filipe Dobreira <http://github.com/filp>
|
||||
*/
|
||||
|
||||
namespace Whoops;
|
||||
use Whoops\TestCase;
|
||||
use Whoops\Run;
|
||||
use Whoops\Handler\Handler;
|
||||
use RuntimeException;
|
||||
use ArrayObject;
|
||||
use Mockery as m;
|
||||
|
||||
class RunTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @return Exception
|
||||
*/
|
||||
protected function getException($message = null)
|
||||
{
|
||||
return m::mock('Exception', array($message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whoops\Handler\Handler
|
||||
*/
|
||||
protected function getHandler()
|
||||
{
|
||||
return m::mock('Whoops\\Handler\\Handler')
|
||||
->shouldReceive('setRun')
|
||||
->andReturn(null)
|
||||
->mock()
|
||||
|
||||
->shouldReceive('setInspector')
|
||||
->andReturn(null)
|
||||
->mock()
|
||||
|
||||
->shouldReceive('setException')
|
||||
->andReturn(null)
|
||||
->mock()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::clearHandlers
|
||||
*/
|
||||
public function testClearHandlers()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
$run->clearHandlers();
|
||||
|
||||
$handlers = $run->getHandlers();
|
||||
|
||||
$this->assertEmpty($handlers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::pushHandler
|
||||
*/
|
||||
public function testPushHandler()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
$run->clearHandlers();
|
||||
|
||||
$handlerOne = $this->getHandler();
|
||||
$handlerTwo = $this->getHandler();
|
||||
|
||||
$run->pushHandler($handlerOne);
|
||||
$run->pushHandler($handlerTwo);
|
||||
|
||||
$handlers = $run->getHandlers();
|
||||
|
||||
$this->assertCount(2, $handlers);
|
||||
$this->assertContains($handlerOne, $handlers);
|
||||
$this->assertContains($handlerTwo, $handlers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @covers Whoops\Run::pushHandler
|
||||
*/
|
||||
public function testPushInvalidHandler()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
$run->pushHandler($banana = 'actually turnip');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::pushHandler
|
||||
*/
|
||||
public function testPushClosureBecomesHandler()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
$run->pushHandler(function() {});
|
||||
$this->assertInstanceOf('Whoops\\Handler\\CallbackHandler', $run->popHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::popHandler
|
||||
* @covers Whoops\Run::getHandlers
|
||||
*/
|
||||
public function testPopHandler()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
|
||||
$handlerOne = $this->getHandler();
|
||||
$handlerTwo = $this->getHandler();
|
||||
$handlerThree = $this->getHandler();
|
||||
|
||||
$run->pushHandler($handlerOne);
|
||||
$run->pushHandler($handlerTwo);
|
||||
$run->pushHandler($handlerThree);
|
||||
|
||||
$this->assertSame($handlerThree, $run->popHandler());
|
||||
$this->assertSame($handlerTwo, $run->popHandler());
|
||||
$this->assertSame($handlerOne, $run->popHandler());
|
||||
|
||||
// Should return null if there's nothing else in
|
||||
// the stack
|
||||
$this->assertNull($run->popHandler());
|
||||
|
||||
// Should be empty since we popped everything off
|
||||
// the stack:
|
||||
$this->assertEmpty($run->getHandlers());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::register
|
||||
*/
|
||||
public function testRegisterHandler()
|
||||
{
|
||||
$this->markTestSkipped("Need to test exception handler");
|
||||
|
||||
$run = $this->getRunInstance();
|
||||
$run->register();
|
||||
|
||||
$handler = $this->getHandler();
|
||||
$run->pushHandler($handler);
|
||||
|
||||
throw $this->getException();
|
||||
|
||||
$this->assertCount(2, $handler->exceptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::unregister
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testUnregisterHandler()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
$run->register();
|
||||
|
||||
$handler = $this->getHandler();
|
||||
$run->pushHandler($handler);
|
||||
|
||||
$run->unregister();
|
||||
throw $this->getException("I'm not supposed to be caught!");
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::pushHandler
|
||||
* @covers Whoops\Run::getHandlers
|
||||
*/
|
||||
public function testHandlerHoldsOrder()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
|
||||
$handlerOne = $this->getHandler();
|
||||
$handlerTwo = $this->getHandler();
|
||||
$handlerThree = $this->getHandler();
|
||||
$handlerFour = $this->getHandler();
|
||||
|
||||
$run->pushHandler($handlerOne);
|
||||
$run->pushHandler($handlerTwo);
|
||||
$run->pushHandler($handlerThree);
|
||||
$run->pushHandler($handlerFour);
|
||||
|
||||
$handlers = $run->getHandlers();
|
||||
|
||||
$this->assertSame($handlers[0], $handlerOne);
|
||||
$this->assertSame($handlers[1], $handlerTwo);
|
||||
$this->assertSame($handlers[2], $handlerThree);
|
||||
$this->assertSame($handlers[3], $handlerFour);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo possibly split this up a bit and move
|
||||
* some of this test to Handler unit tests?
|
||||
* @covers Whoops\Run::handleException
|
||||
*/
|
||||
public function testHandlersGonnaHandle()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
$exception = $this->getException();
|
||||
$order = new ArrayObject;
|
||||
|
||||
$handlerOne = $this->getHandler();
|
||||
$handlerTwo = $this->getHandler();
|
||||
$handlerThree = $this->getHandler();
|
||||
|
||||
$handlerOne->shouldReceive('handle')
|
||||
->andReturnUsing(function() use($order) { $order[] = 1; });
|
||||
$handlerTwo->shouldReceive('handle')
|
||||
->andReturnUsing(function() use($order) { $order[] = 2; });
|
||||
$handlerThree->shouldReceive('handle')
|
||||
->andReturnUsing(function() use($order) { $order[] = 3; });
|
||||
|
||||
$run->pushHandler($handlerOne);
|
||||
$run->pushHandler($handlerTwo);
|
||||
$run->pushHandler($handlerThree);
|
||||
|
||||
// Get an exception to be handled, and verify that the handlers
|
||||
// are given the handler, and in the inverse order they were
|
||||
// registered.
|
||||
$run->handleException($exception);
|
||||
$this->assertEquals((array) $order, array(3, 2, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::handleException
|
||||
*/
|
||||
public function testLastHandler()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
|
||||
$handlerOne = $this->getHandler();
|
||||
$handlerTwo = $this->getHandler();
|
||||
|
||||
$run->pushHandler($handlerOne);
|
||||
$run->pushHandler($handlerTwo);
|
||||
|
||||
$test = $this;
|
||||
$handlerOne
|
||||
->shouldReceive('handle')
|
||||
->andReturnUsing(function () use($test) {
|
||||
$test->fail('$handlerOne should not be called');
|
||||
})
|
||||
;
|
||||
|
||||
$handlerTwo
|
||||
->shouldReceive('handle')
|
||||
->andReturn(Handler::LAST_HANDLER)
|
||||
;
|
||||
|
||||
$run->handleException($this->getException());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error suppression using @ operator.
|
||||
*/
|
||||
public function testErrorSuppression()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
$run->register();
|
||||
|
||||
$handler = $this->getHandler();
|
||||
$run->pushHandler($handler);
|
||||
|
||||
$test = $this;
|
||||
$handler
|
||||
->shouldReceive('handle')
|
||||
->andReturnUsing(function () use($test) {
|
||||
$test->fail('$handler should not be called, error not suppressed');
|
||||
})
|
||||
;
|
||||
|
||||
@trigger_error("Test error suppression");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to make sure that error_reporting is respected.
|
||||
*/
|
||||
public function testErrorReporting()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
$run->register();
|
||||
|
||||
$handler = $this->getHandler();
|
||||
$run->pushHandler($handler);
|
||||
|
||||
$test = $this;
|
||||
$handler
|
||||
->shouldReceive('handle')
|
||||
->andReturnUsing(function () use($test) {
|
||||
$test->fail('$handler should not be called, error_reporting not respected');
|
||||
})
|
||||
;
|
||||
|
||||
$oldLevel = error_reporting(E_ALL ^ E_USER_NOTICE);
|
||||
trigger_error("Test error reporting", E_USER_NOTICE);
|
||||
error_reporting($oldLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::handleException
|
||||
* @covers Whoops\Run::writeToOutput
|
||||
*/
|
||||
public function testOutputIsSent()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
$run->pushHandler(function() {
|
||||
echo "hello there";
|
||||
});
|
||||
|
||||
ob_start();
|
||||
$run->handleException(new RuntimeException);
|
||||
$this->assertEquals("hello there", ob_get_clean());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::handleException
|
||||
* @covers Whoops\Run::writeToOutput
|
||||
*/
|
||||
public function testOutputIsNotSent()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
$run->writeToOutput(false);
|
||||
$run->pushHandler(function() {
|
||||
echo "hello there";
|
||||
});
|
||||
|
||||
ob_start();
|
||||
$this->assertEquals("hello there", $run->handleException(new RuntimeException));
|
||||
$this->assertEquals("", ob_get_clean());
|
||||
}
|
||||
}
|
22
vendor/filp/whoops/tests/Whoops/TestCase.php
vendored
Normal file
22
vendor/filp/whoops/tests/Whoops/TestCase.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Whoops - php errors for cool kids
|
||||
* @author Filipe Dobreira <http://github.com/filp>
|
||||
*/
|
||||
|
||||
namespace Whoops;
|
||||
use Whoops\Run;
|
||||
|
||||
class TestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return Whoops\Run
|
||||
*/
|
||||
protected function getRunInstance()
|
||||
{
|
||||
$run = new Run;
|
||||
$run->allowQuit(false);
|
||||
|
||||
return $run;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user