mirror of
https://github.com/filp/whoops.git
synced 2026-08-31 12:38:10 +00:00
Fixed tests
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit bootstrap="tests/bootstrap.php" colors="true">
|
||||
<phpunit backupGlobals="true" beStrictAboutTestsThatDoNotTestAnything="false" bootstrap="tests/bootstrap.php" cacheResult="false" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Whoops Tests Suite">
|
||||
<directory>tests/Whoops/</directory>
|
||||
|
||||
@@ -14,7 +14,7 @@ class FormatterTest extends TestCase
|
||||
{
|
||||
$msg = 'Sample exception message foo';
|
||||
$output = Formatter::formatExceptionPlain(new Inspector(new \Exception($msg)));
|
||||
$this->assertContains($msg, $output);
|
||||
$this->assertContains('Stacktrace', $output);
|
||||
$this->assertStringContains($msg, $output);
|
||||
$this->assertStringContains('Stacktrace', $output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,21 +80,25 @@ class FrameCollectionTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::offsetSet
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testArrayAccessSet()
|
||||
{
|
||||
$collection = $this->getFrameCollectionInstance();
|
||||
|
||||
$this->expectExceptionOfType('Exception');
|
||||
|
||||
$collection[0] = 'foo';
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::offsetUnset
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testArrayAccessUnset()
|
||||
{
|
||||
$collection = $this->getFrameCollectionInstance();
|
||||
|
||||
$this->expectExceptionOfType('Exception');
|
||||
|
||||
unset($collection[0]);
|
||||
}
|
||||
|
||||
@@ -132,12 +136,13 @@ class FrameCollectionTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers Whoops\Exception\FrameCollection::map
|
||||
* @expectedException UnexpectedValueException
|
||||
*/
|
||||
public function testMapFramesEnforceType()
|
||||
{
|
||||
$frames = $this->getFrameCollectionInstance();
|
||||
|
||||
$this->expectExceptionOfType('UnexpectedValueException');
|
||||
|
||||
// Filter out all frames with a line number under 6
|
||||
$frames->map(function ($frame) {
|
||||
return "bajango";
|
||||
|
||||
@@ -6,14 +6,15 @@ use Whoops\TestCase;
|
||||
|
||||
class CallbackHandlerTest extends TestCase
|
||||
{
|
||||
public function testSimplifiedBacktrace() {
|
||||
$handler = new CallbackHandler(function($exception, $inspector, $run) {
|
||||
public function testSimplifiedBacktrace()
|
||||
{
|
||||
$handler = new CallbackHandler(function ($exception, $inspector, $run) {
|
||||
return debug_backtrace();
|
||||
});
|
||||
$backtrace = $handler->handle();
|
||||
|
||||
foreach($backtrace as $frame) {
|
||||
$this->assertNotContains('call_user_func', $frame['function']);
|
||||
foreach ($backtrace as $frame) {
|
||||
$this->assertStringNotContains('call_user_func', $frame['function']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,22 +75,22 @@ class PlainTextHandlerTest extends TestCase
|
||||
/**
|
||||
* @covers Whoops\Handler\PlainTextHandler::__construct
|
||||
* @covers Whoops\Handler\PlainTextHandler::setLogger
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$logger = new StdClass(); // guaranteed to be invalid!
|
||||
$this->getHandler($logger);
|
||||
$this->expectExceptionOfType('InvalidArgumentException');
|
||||
|
||||
$this->getHandler(new StdClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Whoops\Handler\PlainTextHandler::setLogger
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testSetLogger()
|
||||
{
|
||||
$logger = new StdClass(); // guaranteed to be invalid!
|
||||
$this->getHandler()->setLogger($logger);
|
||||
$this->expectExceptionOfType('InvalidArgumentException');
|
||||
|
||||
$this->getHandler()->setLogger(new StdClass());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,7 +239,7 @@ class PlainTextHandlerTest extends TestCase
|
||||
);
|
||||
|
||||
// Check that the response does not contain Inner exception message:
|
||||
$this->assertNotContains(
|
||||
$this->assertStringNotContains(
|
||||
sprintf(
|
||||
"%s: %s in file %s",
|
||||
RuntimeException::class,
|
||||
@@ -295,10 +295,10 @@ class PlainTextHandlerTest extends TestCase
|
||||
);
|
||||
|
||||
// Check that the response has the correct value:
|
||||
$this->assertContains('Stack trace:', $text);
|
||||
$this->assertStringContains('Stack trace:', $text);
|
||||
|
||||
// Check that the trace is returned:
|
||||
$this->assertContains(
|
||||
$this->assertStringContains(
|
||||
sprintf(
|
||||
'%3d. %s->%s() %s:%d',
|
||||
2,
|
||||
@@ -334,10 +334,10 @@ class PlainTextHandlerTest extends TestCase
|
||||
$this->assertGreaterThan(60, count($lines));
|
||||
|
||||
// Check that the response has the correct value:
|
||||
$this->assertContains('Stack trace:', $text);
|
||||
$this->assertStringContains('Stack trace:', $text);
|
||||
|
||||
// Check that the trace is returned:
|
||||
$this->assertContains(
|
||||
$this->assertStringContains(
|
||||
sprintf(
|
||||
'%3d. %s->%s() %s:%d',
|
||||
2,
|
||||
@@ -349,7 +349,7 @@ class PlainTextHandlerTest extends TestCase
|
||||
$text
|
||||
);
|
||||
// Check that the trace arguments are returned:
|
||||
$this->assertContains(sprintf(
|
||||
$this->assertStringContains(sprintf(
|
||||
'%s string(%d) "%s"',
|
||||
PlainTextHandler::VAR_DUMP_PREFIX,
|
||||
strlen('test message'),
|
||||
@@ -376,10 +376,10 @@ class PlainTextHandlerTest extends TestCase
|
||||
);
|
||||
|
||||
// Check that the response has the correct value:
|
||||
$this->assertContains('Stack trace:', $text);
|
||||
$this->assertStringContains('Stack trace:', $text);
|
||||
|
||||
// Check that the trace is returned:
|
||||
$this->assertContains(
|
||||
$this->assertStringContains(
|
||||
sprintf(
|
||||
'%3d. %s->%s() %s:%d',
|
||||
2,
|
||||
@@ -392,7 +392,7 @@ class PlainTextHandlerTest extends TestCase
|
||||
);
|
||||
|
||||
// Check that the trace arguments are returned:
|
||||
$this->assertContains(sprintf(
|
||||
$this->assertStringContains(sprintf(
|
||||
'%s string(%d) "%s"',
|
||||
PlainTextHandler::VAR_DUMP_PREFIX,
|
||||
strlen('test message'),
|
||||
|
||||
@@ -81,12 +81,12 @@ class PrettyPageHandlerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers Whoops\Handler\PrettyPageHandler::addResourcePath
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testSetInvalidResourcesPath()
|
||||
{
|
||||
$path = __DIR__ . '/ZIMBABWE'; // guaranteed to be invalid!
|
||||
$this->getHandler()->addResourcePath($path);
|
||||
$this->expectExceptionOfType('InvalidArgumentException');
|
||||
|
||||
$this->getHandler()->addResourcePath(__DIR__ . '/ZIMBABWE');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -93,13 +93,15 @@ class RunTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
* @covers Whoops\Run::pushHandler
|
||||
*/
|
||||
public function testPushInvalidHandler()
|
||||
{
|
||||
$run = $this->getRunInstance();
|
||||
$run->pushHandler($banana = 'actually turnip');
|
||||
|
||||
$this->expectExceptionOfType('InvalidArgumentException');
|
||||
|
||||
$run->pushHandler('actually turnip');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,7 +182,6 @@ class RunTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::unregister
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testUnregisterHandler()
|
||||
{
|
||||
@@ -191,6 +192,9 @@ class RunTest extends TestCase
|
||||
$run->pushHandler($handler);
|
||||
|
||||
$run->unregister();
|
||||
|
||||
$this->expectExceptionOfType('Exception');
|
||||
|
||||
throw $this->getException("I'm not supposed to be caught!");
|
||||
}
|
||||
|
||||
@@ -402,6 +406,7 @@ class RunTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::handleError
|
||||
* @requires PHP < 8
|
||||
*/
|
||||
public function testGetSilencedError()
|
||||
{
|
||||
@@ -491,10 +496,11 @@ class RunTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers Whoops\Run::sendHttpCode
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testSendHttpCodeWrongCode()
|
||||
{
|
||||
$this->expectExceptionOfType('InvalidArgumentException');
|
||||
|
||||
$this->getRunInstance()->sendHttpCode(1337);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,47 @@ class TestCase extends BaseTestCase
|
||||
return $run;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @return void
|
||||
*/
|
||||
protected function expectExceptionOfType($class)
|
||||
{
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException($class);
|
||||
} else {
|
||||
$this->setExpectedException($class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
* @return void
|
||||
*/
|
||||
protected function assertStringContains($a, $b)
|
||||
{
|
||||
if (method_exists($this, 'assertStringContainsString')) {
|
||||
$this->assertStringContainsString($a, $b);
|
||||
} else {
|
||||
$this->assertContains($a, $b);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
* @return void
|
||||
*/
|
||||
protected function assertStringNotContains($a, $b)
|
||||
{
|
||||
if (method_exists($this, 'assertStringNotContainsString')) {
|
||||
$this->assertStringNotContainsString($a, $b);
|
||||
} else {
|
||||
$this->assertNotContains($a, $b);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object|string $class_or_object
|
||||
* @param string $method
|
||||
|
||||
@@ -22,13 +22,19 @@ class SystemFacadeTest extends TestCase
|
||||
: call_user_func_array("\\$fn", $args);
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
public function getReady()
|
||||
{
|
||||
self::$runtime = \Mockery::mock(['ob_start' => true]);
|
||||
$this->facade = new SystemFacade();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
/**
|
||||
* @after
|
||||
*/
|
||||
public function finishUp()
|
||||
{
|
||||
self::$runtime = null;
|
||||
\Mockery::close();
|
||||
|
||||
@@ -16,9 +16,9 @@ class TemplateHelperTest extends TestCase
|
||||
private $helper;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @before
|
||||
*/
|
||||
public function setUp()
|
||||
public function getReady()
|
||||
{
|
||||
$this->helper = new TemplateHelper();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user