update v 1.0.7.5

This commit is contained in:
Sujit Prasad
2016-06-13 20:41:55 +05:30
parent aa9786d829
commit 283d97e3ea
5078 changed files with 339851 additions and 175995 deletions

3
vendor/bugsnag/bugsnag/.gitattributes vendored Normal file
View File

@@ -0,0 +1,3 @@
example/ export-ignore
tests/ export-ignore
phpunit.xml

View File

@@ -1,6 +1,32 @@
Changelog
=========
## 2.7.1 (2016-06-02)
### Bug Fixes
* Fix failure to merge array due to type conflicts
[Jesse Collis](https://github.com/jessedc)
[#118](https://github.com/bugsnag/bugsnag-php/pull/118)
## 2.7.0 (2016-03-09)
### Enhancements
* Support `timeout` settings outside of cURL
[Ivan Shalganov](https://github.com/bzick)
[#111](https://github.com/bugsnag/bugsnag-php/pull/111)
* Support PUT request payloads
[forgadenny](https://github.com/forgandenny)
[#83](https://github.com/bugsnag/bugsnag-php/pull/83)
### Bug Fixes
* Remove exception code filtering
[Duncan Hewett](https://github.com/duncanhewett)
[#113](https://github.com/bugsnag/bugsnag-php/pull/113)
2.6.1 (2016-01-28)
-----
@@ -10,19 +36,23 @@ Changelog
[Petr Bugyík](https://github.com/o5)
[#110](https://github.com/bugsnag/bugsnag-php/pull/110)
2.6.0 (23 Dec 2015)
* Fix error which occurs when `$_SERVER['SERVER_PORT']` is unset
[Michael Curry](https://github.com/michaelcurry)
[#109](https://github.com/bugsnag/bugsnag-php/pull/109)
2.6.0 (2015-12-23)
-----
### Enhancements
* Add support for PHP 7's Throwable
| [Chris Stone](https://github.com/cmstone)
| [#106](https://github.com/bugsnag/bugsnag-php/pull/106)
[Chris Stone](https://github.com/cmstone)
[#106](https://github.com/bugsnag/bugsnag-php/pull/106)
* Fix errors which arise from from error payloads not encoded using UTF-8
| [GaetanNaulin](https://github.com/GaetanNaulin)
| [#104](https://github.com/bugsnag/bugsnag-php/pull/104)
| [#105](https://github.com/bugsnag/bugsnag-php/pull/105)
[GaetanNaulin](https://github.com/GaetanNaulin)
[#104](https://github.com/bugsnag/bugsnag-php/pull/104)
[#105](https://github.com/bugsnag/bugsnag-php/pull/105)
2.5.6
-----

View File

@@ -39,10 +39,11 @@ Releasing
php pharbuilder.php
```
4. Commit, tag push
5. Commit, tag push
```
git commit -am v2.x.x
git tag v2.x.x
git push origin master && git push --tags
```
6. Update the setup guides for PHP (and its frameworks) with any new content.

View File

@@ -241,9 +241,7 @@ $bugsnag->setEndpoint("http://bugsnag.internal.example.com");
###setTimeout
> Note: Timeout configuration is only possible if the PHP cURL extension is installed.
Define a custom timeout, in seconds, for cURL connection when notifying bugsnag.com.
Define a custom timeout in seconds for the connection when notifying bugsnag.com.
```php
$bugsnag->setTimeout(2);

Binary file not shown.

View File

@@ -1,16 +0,0 @@
- Install composer
<http://getcomposer.org/doc/01-basic-usage.md>
- Install bugsnag using composer
```shell
composer install
```
- Add your API key to the example script
- Run the example script
```shell
php index.php
```

View File

@@ -1,5 +0,0 @@
{
"require": {
"bugsnag/bugsnag": "1.*"
}
}

View File

@@ -1,8 +0,0 @@
<?php
require_once "../../build/bugsnag.phar";
$bugsnag = new Bugsnag_Client("YOUR-API-KEY-HERE");
$bugsnag->notifyError("Broken", "Something broke", array("tab" => array("paying" => true, "object" => (object)array("key" => "value"), "null" => NULL, "string" => "test", "int" => 4)));
?>

View File

@@ -18,7 +18,7 @@ class Bugsnag_Configuration
public $proxySettings = array();
public $notifier = array(
'name' => 'Bugsnag PHP (Official)',
'version' => '2.6.1',
'version' => '2.7.1',
'url' => 'https://bugsnag.com',
);
public $sendEnvironment = false;

View File

@@ -171,7 +171,7 @@ class Bugsnag_Error
'payloadVersion' => $this->payloadVersion,
'severity' => $this->severity,
'exceptions' => $this->exceptionArray(),
'metaData' => $this->cleanupObj($this->metaData),
'metaData' => $this->cleanupObj($this->metaData, true),
);
if (isset($this->groupingHash)) {
@@ -195,10 +195,10 @@ class Bugsnag_Error
'stacktrace' => $this->stacktrace->toArray(),
);
return $this->cleanupObj($exceptionArray);
return $this->cleanupObj($exceptionArray, false);
}
private function cleanupObj($obj)
private function cleanupObj($obj, $isMetaData)
{
if (is_null($obj)) {
return null;
@@ -207,23 +207,23 @@ class Bugsnag_Error
if (is_array($obj)) {
$cleanArray = array();
foreach ($obj as $key => $value) {
// Apply filters if required
if (is_array($this->config->filters)) {
// Check if this key should be filtered
$shouldFilter = false;
// Check if this key should be filtered
$shouldFilter = false;
// Apply filters to metadata if required
if ($isMetaData && is_array($this->config->filters)) {
foreach ($this->config->filters as $filter) {
if (strpos($key, $filter) !== false) {
$shouldFilter = true;
break;
}
}
// Apply filters
if ($shouldFilter) {
$cleanArray[$key] = '[FILTERED]';
} else {
$cleanArray[$key] = $this->cleanupObj($value);
}
}
// Apply filter
if ($shouldFilter) {
$cleanArray[$key] = '[FILTERED]';
} else {
$cleanArray[$key] = $this->cleanupObj($value, $isMetaData);
}
}
@@ -237,7 +237,7 @@ class Bugsnag_Error
}
} elseif (is_object($obj)) {
// json_encode -> json_decode trick turns an object into an array
return $this->cleanupObj(json_decode(json_encode($obj), true));
return $this->cleanupObj(json_decode(json_encode($obj), true), $isMetaData);
} else {
return $obj;
}

View File

@@ -171,17 +171,13 @@ class Bugsnag_Notification
error_log('Bugsnag Warning: Can\'t use proxy settings unless cURL is installed');
}
// Warn about lack of timeout support if we are using fopen()
if ($this->config->timeout != Bugsnag_Configuration::$DEFAULT_TIMEOUT) {
error_log('Bugsnag Warning: Can\'t change timeout settings unless cURL is installed');
}
// Create the request context
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => Bugsnag_Notification::$CONTENT_TYPE_HEADER.'\r\n',
'content' => $body,
'timeout' => $this->config->timeout
),
'ssl' => array(
'verify_peer' => false,

View File

@@ -11,6 +11,8 @@ class Bugsnag_Request
{
$requestData = array();
$methodsWithPayload = array('PUT');
// Request Tab
$requestData['request'] = array();
$requestData['request']['url'] = self::getCurrentUrl();
@@ -21,8 +23,21 @@ class Bugsnag_Request
if (!empty($_POST)) {
$requestData['request']['params'] = $_POST;
} else {
if (isset($_SERVER['CONTENT_TYPE']) && stripos($_SERVER['CONTENT_TYPE'], 'application/json') === 0) {
$requestData['request']['params'] = json_decode(file_get_contents('php://input'));
$requestData['request']['params'] = json_decode(file_get_contents('php://input'), true);
}
if (isset($_SERVER['REQUEST_METHOD']) && in_array(strtoupper($_SERVER['REQUEST_METHOD']), $methodsWithPayload)) {
parse_str(file_get_contents('php://input'),$params);
if (isset($requestData['request']['params']) && is_array($requestData['request']['params']))
{
$requestData['request']['params'] = array_merge($requestData['request']['params'],$params);
}
else
{
$requestData['request']['params'] = $params;
}
}
}

View File

@@ -1,29 +0,0 @@
<?php
abstract class Bugsnag_TestCase extends PHPUnit_Framework_TestCase
{
/** @var Bugsnag_Configuration */
protected $config;
/** @var Bugsnag_Diagnostics */
protected $diagnostics;
protected function getError($name = "Name", $message = "Message")
{
return Bugsnag_Error::fromNamedError($this->config, $this->diagnostics, $name, $message);
}
protected function getFixturePath($file)
{
return realpath(dirname(__FILE__)."/../fixtures/".$file);
}
protected function getFixture($file)
{
return file_get_contents($this->getFixturePath($file));
}
protected function getJsonFixture($file)
{
return json_decode($this->getFixture($file), true);
}
}

View File

@@ -1,97 +0,0 @@
<?php
if (!defined('PHP_VERSION_ID')) {
$version = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
}
if (PHP_VERSION_ID < 50207) {
define('PHP_MAJOR_VERSION', $version[0]);
define('PHP_MINOR_VERSION', $version[1]);
define('PHP_RELEASE_VERSION', $version[2]);
}
class ClientTest extends PHPUnit_Framework_TestCase
{
/** @var PHPUnit_Framework_MockObject_MockObject|Bugsnag_Client */
protected $client;
protected function setUp()
{
// Mock the notify function
$this->client = $this->getMockBuilder('Bugsnag_Client')
->setMethods(array('notify'))
->setConstructorArgs(array('example-api_key'))
->getMock();
}
public function testErrorHandler()
{
$this->client->expects($this->once())
->method('notify');
$this->client->errorHandler(E_WARNING, "Something broke", "somefile.php", 123);
}
public function testExceptionHandler()
{
$this->client->expects($this->once())
->method('notify');
$this->client->exceptionHandler(new Exception("Something broke"));
}
public function testManualErrorNotification()
{
$this->client->expects($this->once())
->method('notify');
$this->client->notifyError("SomeError", "Some message");
}
public function testManualExceptionNotification()
{
$this->client->expects($this->once())
->method('notify');
$this->client->notifyException(new Exception("Something broke"));
}
public function testErrorReportingLevel()
{
$this->client->expects($this->once())
->method('notify');
$this->client->setErrorReportingLevel(E_NOTICE)
->errorHandler(E_NOTICE, "Something broke", "somefile.php", 123);
}
public function testErrorReportingLevelFails()
{
$this->client->expects($this->never())
->method('notify');
$this->client->setErrorReportingLevel(E_NOTICE)
->errorHandler(E_WARNING, "Something broke", "somefile.php", 123);
}
public function testErrorReportingWithoutNotice()
{
$this->client->expects($this->never())
->method('notify');
$this->client->setErrorReportingLevel(E_ALL & ~E_NOTICE)
->errorHandler(E_NOTICE, "Something broke", "somefile.php", 123);
}
public function testSetInvalidCurlOptions()
{
if (PHP_MAJOR_VERSION >= 7) {
$this->setExpectedException('TypeError');
} else {
$this->setExpectedException('PHPUnit_Framework_Error');
}
$this->client->setCurlOptions("option");
}
}

View File

@@ -1,74 +0,0 @@
<?php
class ConfigurationTest extends PHPUnit_Framework_TestCase
{
/** @var Bugsnag_Configuration */
protected $config;
protected function setUp()
{
$this->config = new Bugsnag_Configuration();
}
public function testDefaultEndpoint()
{
$this->assertEquals($this->config->getNotifyEndpoint(), "https://notify.bugsnag.com");
}
public function testNonSSLEndpoint()
{
$this->config->useSSL = false;
$this->assertEquals($this->config->getNotifyEndpoint(), "http://notify.bugsnag.com");
}
public function testCustomEndpoint()
{
$this->config->useSSL = false;
$this->config->endpoint = "localhost";
$this->assertEquals($this->config->getNotifyEndpoint(), "http://localhost");
}
public function testDefaultReleaseStageShouldNotify()
{
$this->assertTrue($this->config->shouldNotify());
}
public function testCustomReleaseStageShouldNotify()
{
$this->config->releaseStage = "staging";
$this->assertTrue($this->config->shouldNotify());
}
public function testCustomNotifyReleaseStagesShouldNotify()
{
$this->config->notifyReleaseStages = array("banana");
$this->assertFalse($this->config->shouldNotify());
}
public function testBothCustomShouldNotify()
{
$this->config->releaseStage = "banana";
$this->config->notifyReleaseStages = array("banana");
$this->assertTrue($this->config->shouldNotify());
}
public function testNotifier()
{
$this->assertEquals($this->config->notifier['name'], "Bugsnag PHP (Official)");
$this->assertEquals($this->config->notifier['url'], "https://bugsnag.com");
}
public function testShouldIgnore()
{
$this->config->errorReportingLevel = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
$this->assertTrue($this->config->shouldIgnoreErrorCode(E_NOTICE));
}
public function testShouldNotIgnore()
{
$this->config->errorReportingLevel = E_ALL;
$this->assertfalse($this->config->shouldIgnoreErrorCode(E_NOTICE));
}
}

View File

@@ -1,54 +0,0 @@
<?php
class DiagnosticsTest extends PHPUnit_Framework_TestCase
{
/** @var Bugsnag_Configuration */
protected $config;
/** @var Bugsnag_Diagnostics */
protected $diagnostics;
protected function setUp()
{
$this->config = new Bugsnag_Configuration();
$this->diagnostics = new Bugsnag_Diagnostics($this->config);
}
public function testDefaultAppData()
{
$this->config->releaseStage = 'qa1';
$this->config->appVersion = '1.2.3';
$this->config->type = "laravel";
$appData = $this->diagnostics->getAppData();
$this->assertEquals($appData['releaseStage'], 'qa1');
$this->assertEquals($appData['version'], '1.2.3');
$this->assertEquals($appData['type'], 'laravel');
}
public function testDefaultDeviceData()
{
$this->config->hostname = 'web1.example.com';
$deviceData = $this->diagnostics->getDeviceData();
$this->assertEquals($deviceData['hostname'], 'web1.example.com');
}
public function testDefaultContext()
{
$this->config->context = 'herp#derp';
$this->assertEquals($this->diagnostics->getContext(), 'herp#derp');
}
public function testDefaultUser()
{
$this->config->user = array('id' => 123, 'email' => "test@email.com", 'name' => "Bob Hoskins");
$userData = $this->diagnostics->getUser();
$this->assertEquals($userData['id'], 123);
$this->assertEquals($userData['email'], "test@email.com");
$this->assertEquals($userData['name'], "Bob Hoskins");
}
}

View File

@@ -1,137 +0,0 @@
<?php
require_once 'Bugsnag_TestCase.php';
class ErrorTest extends Bugsnag_TestCase
{
/** @var Bugsnag_Configuration */
protected $config;
/** @var Bugsnag_Diagnostics */
protected $diagnostics;
/** @var Bugsnag_Error */
protected $error;
protected function setUp()
{
$this->config = new Bugsnag_Configuration();
$this->diagnostics = new Bugsnag_Diagnostics($this->config);
$this->error = $this->getError();
}
public function testMetaData()
{
$this->error->setMetaData(array("Testing" => array("globalArray" => "hi")));
$errorArray = $this->error->toArray();
$this->assertEquals($errorArray['metaData']["Testing"]["globalArray"], "hi");
}
public function testMetaDataMerging()
{
$this->error->setMetaData(array("Testing" => array("globalArray" => "hi")));
$this->error->setMetaData(array("Testing" => array("localArray" => "yo")));
$errorArray = $this->error->toArray();
$this->assertEquals($errorArray['metaData']["Testing"]["globalArray"], "hi");
$this->assertEquals($errorArray['metaData']["Testing"]["localArray"], "yo");
}
public function testFiltering()
{
$this->error->setMetaData(array("Testing" => array("password" => "123456")));
$errorArray = $this->error->toArray();
$this->assertEquals($errorArray['metaData']['Testing']['password'], '[FILTERED]');
}
public function testNoticeName()
{
$this->error->setPHPError(E_NOTICE, "Broken", "file", 123);
$errorArray = $this->error->toArray();
$this->assertEquals($errorArray['exceptions'][0]['errorClass'], 'PHP Notice');
}
public function testErrorName()
{
$this->error->setPHPError(E_ERROR, "Broken", "file", 123);
$errorArray = $this->error->toArray();
$this->assertEquals($errorArray['exceptions'][0]['errorClass'], 'PHP Fatal Error');
}
public function testErrorPayloadVersion()
{
$this->error->setPHPError(E_ERROR, "Broken", "file", 123);
$errorArray = $this->error->toArray();
$this->assertEquals($errorArray['payloadVersion'], '2');
}
public function testNoticeSeverity()
{
$this->error->setPHPError(E_NOTICE, "Broken", "file", 123);
$errorArray = $this->error->toArray();
$this->assertEquals($errorArray['severity'], 'info');
}
public function testErrorSeverity()
{
$this->error->setPHPError(E_ERROR, "Broken", "file", 123);
$errorArray = $this->error->toArray();
$this->assertEquals($errorArray['severity'], 'error');
}
public function testManualSeverity()
{
$this->error->setSeverity("error");
$errorArray = $this->error->toArray();
$this->assertEquals($errorArray['severity'], 'error');
}
public function testInvalidSeverity()
{
$this->error->setSeverity("bunk");
$errorArray = $this->error->toArray();
$this->assertEquals($errorArray['severity'], 'warning');
}
public function testPreviousException()
{
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
$exception = new Exception("secondly", 65533, new Exception("firstly"));
$error = Bugsnag_Error::fromPHPThrowable($this->config, $this->diagnostics, $exception);
$errorArray = $error->toArray();
$this->assertEquals(count($errorArray['exceptions']), 2);
$this->assertEquals($errorArray['exceptions'][0]['message'], 'firstly');
$this->assertEquals($errorArray['exceptions'][1]['message'], 'secondly');
}
}
public function testErrorGroupingHash()
{
$this->error->setGroupingHash('herp#derp');
$errorArray = $this->error->toArray();
$this->assertEquals($errorArray['groupingHash'], 'herp#derp');
}
public function testErrorGroupingHashNotSet()
{
$errorArray = $this->error->toArray();
$this->assertArrayNotHasKey('groupingHash', $errorArray);
}
public function testSetPHPException()
{
$exception = version_compare(PHP_VERSION, '7.0.0', '>=') ? new \Error() : new Exception();
$this->error->setPHPException($exception);
}
}

View File

@@ -1,11 +0,0 @@
<?php
class ErrorTypesTest extends PHPUnit_Framework_TestCase
{
public function testGetLevelsForSeverity()
{
$this->assertEquals(Bugsnag_ErrorTypes::getLevelsForSeverity("error"), 4437);
$this->assertEquals(Bugsnag_ErrorTypes::getLevelsForSeverity("warning"), 674);
$this->assertEquals(Bugsnag_ErrorTypes::getLevelsForSeverity("info"), 27656);
}
}

View File

@@ -1,131 +0,0 @@
<?php
require_once 'Bugsnag_TestCase.php';
class NotificationTest extends Bugsnag_TestCase
{
/** @var Bugsnag_Configuration */
protected $config;
/** @var Bugsnag_Diagnostics */
protected $diagnostics;
/** @var Bugsnag_Notification|PHPUnit_Framework_MockObject_MockObject */
protected $notification;
protected function setUp()
{
$this->config = new Bugsnag_Configuration();
$this->config->apiKey = "6015a72ff14038114c3d12623dfb018f";
$this->config->beforeNotifyFunction = "before_notify_skip_error";
$this->diagnostics = new Bugsnag_Diagnostics($this->config);
$this->notification = $this->getMockBuilder('Bugsnag_Notification')
->setMethods(array("postJSON"))
->setConstructorArgs(array($this->config))
->getMock();
}
public function testNotification()
{
// Create a mock notification object
$this->notification = $this->getMockBuilder('Bugsnag_Notification')
->setMethods(array("postJSON"))
->setConstructorArgs(array($this->config))
->getMock();
// Expect postJSON to be called
$this->notification->expects($this->once())
->method("postJSON")
->with($this->equalTo("https://notify.bugsnag.com"),
$this->anything());
// Add an error to the notification and deliver it
$this->notification->addError($this->getError());
$this->notification->deliver();
}
public function testBeforeNotifySkipsError()
{
$this->notification->expects($this->never())
->method("postJSON");
$this->notification->addError($this->getError("SkipMe", "Message"));
$this->notification->deliver();
}
/**
* Test for ensuring that the addError method calls shouldNotify
*
* If shouldNotify returns false, the error should not be added
*/
public function testAddErrorChecksShouldNotifyFalse()
{
$config = $this->getMockBuilder('Bugsnag_Configuration')
->setMethods(array("shouldNotify"))
->getMock();
$config->expects($this->once())
->method('shouldNotify')
->will($this->returnValue(false));
/** @var Bugsnag_Notification $notification */
$notification = $this->getMockBuilder('Bugsnag_Notification')
->setMethods(array("postJSON"))
->setConstructorArgs(array($config))
->getMock();
$this->assertFalse($notification->addError($this->getError()));
}
/**
* Test for ensuring that the deliver method calls shouldNotify
*
* If shouldNotify returns false, the error should not be sent
*/
public function testDeliverChecksShouldNotify()
{
$config = $this->getMockBuilder('Bugsnag_Configuration')
->setMethods(array("shouldNotify"))
->getMock();
$config->expects($this->once())
->method('shouldNotify')
->will($this->returnValue(false));
/** @var Bugsnag_Notification|PHPUnit_Framework_MockObject_MockObject $notification */
$notification = $this->getMockBuilder('Bugsnag_Notification')
->setMethods(array("postJSON"))
->setConstructorArgs(array($config))
->getMock();
$notification->expects($this->never())
->method("postJSON");
$notification->addError($this->getError());
$notification->deliver();
}
public function testNoEnvironmentByDefault()
{
$_ENV["SOMETHING"] = "blah";
$notification = new Bugsnag_Notification($this->config);
$notification->addError($this->getError());
$notificationArray = $notification->toArray();
$this->assertArrayNotHasKey("Environment", $notificationArray["events"][0]["metaData"]);
}
public function testEnvironmentPresentWhenRequested()
{
$_ENV["SOMETHING"] = "blah";
$this->config->sendEnvironment = true;
$notification = new Bugsnag_Notification($this->config);
$notification->addError($this->getError());
$notificationArray = $notification->toArray();
$this->assertEquals($notificationArray["events"][0]["metaData"]["Environment"]["SOMETHING"], "blah");
}
}
function before_notify_skip_error($error)
{
return $error->name != "SkipMe";
}

View File

@@ -1,37 +0,0 @@
<?php
class RequestTest extends PHPUnit_Framework_TestCase
{
protected function setUp()
{
$_SERVER['REQUEST_METHOD'] = "GET";
$_SERVER['REQUEST_URI'] = "/blah/blah.php?some=param";
$_SERVER['REMOTE_ADDR'] = "123.45.67.8";
$_SERVER['SERVER_PORT'] = "80";
$_SERVER['HTTP_HOST'] = "example.com";
$_SERVER['HTTP_USER_AGENT'] = "Example Browser 1.2.3";
$_COOKIE = array("cookie" => "cookieval");
$_SESSION = array("session" => "sessionval");
}
public function testIsRequest()
{
$this->assertTrue(Bugsnag_Request::isRequest());
}
public function testGetContext()
{
$this->assertEquals(Bugsnag_Request::getContext(), "GET /blah/blah.php");
}
public function testGetCurrentUrl()
{
$this->assertEquals(Bugsnag_Request::getCurrentUrl(), "http://example.com/blah/blah.php?some=param");
}
public function testRequestIp()
{
$this->assertEquals(Bugsnag_Request::getRequestIp(), "123.45.67.8");
}
}

View File

@@ -1,211 +0,0 @@
<?php
require_once 'Bugsnag_TestCase.php';
class StacktraceTest extends Bugsnag_TestCase
{
/** @var Bugsnag_Configuration */
protected $config;
/** @var Bugsnag_Diagnostics */
protected $diagnostics;
protected function setUp()
{
$this->config = new Bugsnag_Configuration();
$this->diagnostics = new Bugsnag_Diagnostics($this->config);
}
protected function assertFrameEquals($frame, $method, $file, $line)
{
$this->assertEquals($frame["method"], $method);
$this->assertEquals($frame["file"], $file);
$this->assertEquals($frame["lineNumber"], $line);
}
protected function assertCodeEquals($expected, $actual)
{
$this->assertEquals(rtrim(substr($expected, 0, 200)), $actual);
}
public function testFromFrame()
{
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, "some_file.php", 123)->toarray();
$this->assertCount(1, $stacktrace);
$this->assertFrameEquals($stacktrace[0], "[unknown]", "some_file.php", 123);
}
public function testFrameInsideBugsnag()
{
$frame = $this->getJsonFixture('frames/non_bugsnag.json');
$bugsnagFrame = $this->getJsonFixture('frames/bugsnag.json');
$this->assertFalse(Bugsnag_Stacktrace::frameInsideBugsnag($frame));
$this->assertTrue(Bugsnag_Stacktrace::frameInsideBugsnag($bugsnagFrame));
}
public function testTriggeredErrorStacktrace()
{
$fixture = $this->getJsonFixture('backtraces/trigger_error.json');
$stacktrace = Bugsnag_Stacktrace::fromBacktrace($this->config, $fixture['backtrace'], $fixture['file'], $fixture['line'])->toArray();
$this->assertCount(4, $stacktrace);
$this->assertFrameEquals($stacktrace[0], "trigger_error", "[internal]", 0);
$this->assertFrameEquals($stacktrace[1], "crashy_function", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 17);
$this->assertFrameEquals($stacktrace[2], "parent_of_crashy_function", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 13);
$this->assertFrameEquals($stacktrace[3], "[main]", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 20);
}
public function testErrorHandlerStacktrace()
{
$fixture = $this->getJsonFixture('backtraces/error_handler.json');
$stacktrace = Bugsnag_Stacktrace::fromBacktrace($this->config, $fixture['backtrace'], $fixture['file'], $fixture['line'])->toArray();
$this->assertCount(3, $stacktrace);
$this->assertFrameEquals($stacktrace[0], "crashy_function", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 22);
$this->assertFrameEquals($stacktrace[1], "parent_of_crashy_function", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 13);
$this->assertFrameEquals($stacktrace[2], "[main]", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 25);
}
public function testExceptionHandlerStacktrace()
{
$fixture = $this->getJsonFixture('backtraces/exception_handler.json');
$stacktrace = Bugsnag_Stacktrace::fromBacktrace($this->config, $fixture['backtrace'], $fixture['file'], $fixture['line'])->toArray();
$this->assertCount(3, $stacktrace);
$this->assertFrameEquals($stacktrace[0], "crashy_function", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 25);
$this->assertFrameEquals($stacktrace[1], "parent_of_crashy_function", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 13);
$this->assertFrameEquals($stacktrace[2], "[main]", "/Users/james/src/bugsnag/bugsnag-php/testing.php", 28);
}
public function testAnonymousFunctionStackframes()
{
$fixture = $this->getJsonFixture('backtraces/anonymous_frame.json');
$stacktrace = Bugsnag_Stacktrace::fromBacktrace($this->config, $fixture['backtrace'], "somefile.php", 123)->toArray();
$this->assertCount(5, $stacktrace);
$this->assertFrameEquals($stacktrace[0], "Illuminate\\Support\\Facades\\Facade::__callStatic", "somefile.php", 123);
$this->assertFrameEquals($stacktrace[1], "Bugsnag\\BugsnagLaravel\\BugsnagFacade::notifyError", "controllers/ExampleController.php", 12);
$this->assertFrameEquals($stacktrace[2], "ExampleController::index", "controllers/ExampleController.php", 12);
$this->assertFrameEquals($stacktrace[3], "call_user_func_array", "[internal]", 0);
$this->assertFrameEquals($stacktrace[4], "[main]", "Routing/Controller.php", 194);
}
public function testXdebugErrorStackframes()
{
$fixture = $this->getJsonFixture('backtraces/xdebug_error.json');
$stacktrace = Bugsnag_Stacktrace::fromBacktrace($this->config, $fixture['backtrace'], $fixture['file'], $fixture['line'])->toArray();
$this->assertCount(7, $stacktrace);
$this->assertFrameEquals($stacktrace[0], null, "somefile.php", 123);
$this->assertFrameEquals($stacktrace[1], "Illuminate\\View\\Engines\\PhpEngine::evaluatePath", "/View/Engines/PhpEngine.php", 39);
$this->assertFrameEquals($stacktrace[2], "Illuminate\\View\\Engines\\CompilerEngine::get", "View/Engines/CompilerEngine.php", 57);
$this->assertFrameEquals($stacktrace[3], "Illuminate\\View\\View::getContents", "View/View.php", 136);
$this->assertFrameEquals($stacktrace[4], "Illuminate\\View\\View::renderContents", "View/View.php", 104);
$this->assertFrameEquals($stacktrace[5], "Illuminate\\View\\View::render", "View/View.php", 78);
$this->assertFrameEquals($stacktrace[6], "[main]", "storage/views/f2df2d6b49591efeb36fc46e6dc25e0e", 5);
}
public function testEvaledStackframes()
{
$evalFrame = $this->getJsonFixture('frames/eval.json');
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $evalFrame["file"], $evalFrame["line"])->toArray();
$topFrame = $stacktrace[0];
$this->assertEquals($topFrame["file"], "path/some/file.php");
$this->assertEquals($topFrame["lineNumber"], 123);
$evalFrame = $this->getJsonFixture('frames/runtime_created.json');
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $evalFrame["file"], $evalFrame["line"])->toArray();
$topFrame = $stacktrace[0];
$this->assertEquals($topFrame["file"], "path/some/file.php");
$this->assertEquals($topFrame["lineNumber"], 123);
}
public function testStrippingPaths()
{
$fixture = $this->getJsonFixture('backtraces/exception_handler.json');
$this->config->setStripPath("/Users/james/src/bugsnag/bugsnag-php/");
$stacktrace = Bugsnag_Stacktrace::fromBacktrace($this->config, $fixture['backtrace'], $fixture['file'], $fixture['line'])->toArray();
$this->assertCount(3, $stacktrace);
$this->assertFrameEquals($stacktrace[0], "crashy_function", "testing.php", 25);
$this->assertFrameEquals($stacktrace[1], "parent_of_crashy_function", "testing.php", 13);
$this->assertFrameEquals($stacktrace[2], "[main]", "testing.php", 28);
}
public function testCode()
{
$fileContents = explode("\n", $this->getFixture('code/File.php'));
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $this->getFixturePath('code/File.php'), 12)->toArray();
$this->assertCount(1, $stacktrace);
$topFrame = $stacktrace[0];
$this->assertCount(7, $topFrame["code"]);
for ($i=9; $i<=15; $i++) {
$this->assertCodeEquals($fileContents[$i - 1], $topFrame["code"][$i]);
}
}
public function testCodeShortFile()
{
$fileContents = explode("\n", $this->getFixture('code/ShortFile.php'));
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $this->getFixturePath('code/ShortFile.php'), 1)->toArray();
$this->assertCount(1, $stacktrace);
$topFrame = $stacktrace[0];
$this->assertCount(3, $topFrame["code"]);
for ($i=1; $i<=2; $i++) {
$this->assertCodeEquals($fileContents[$i - 1], $topFrame["code"][$i]);
}
}
public function testCodeEndOfFile()
{
$fileContents = explode("\n", $this->getFixture('code/File.php'));
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $this->getFixturePath('code/File.php'), 22)->toArray();
$this->assertCount(1, $stacktrace);
$topFrame = $stacktrace[0];
$this->assertCount(7, $topFrame["code"]);
for ($i=16; $i<=22; $i++) {
$this->assertCodeEquals($fileContents[$i - 1], $topFrame["code"][$i]);
}
}
public function testCodeStartOfFile()
{
$fileContents = explode("\n", $this->getFixture('code/File.php'));
$stacktrace = Bugsnag_Stacktrace::fromFrame($this->config, $this->getFixturePath('code/File.php'), 1)->toArray();
$this->assertCount(1, $stacktrace);
$topFrame = $stacktrace[0];
$this->assertCount(7, $topFrame["code"]);
for ($i=1; $i<=7; $i++) {
$this->assertCodeEquals($fileContents[$i - 1], $topFrame["code"][$i]);
}
}
public function testCodeDisabled()
{
$config = new Bugsnag_Configuration();
$config->sendCode = false;
$stacktrace = Bugsnag_Stacktrace::fromFrame($config, $this->getFixturePath('code/File.php'), 1)->toArray();
$this->assertCount(1, $stacktrace);
$topFrame = $stacktrace[0];
$this->assertArrayNotHasKey('code', $topFrame);
}
}

View File

@@ -1,25 +0,0 @@
{
"backtrace": [
{
"file": "controllers/ExampleController.php",
"line": "12",
"class": "Illuminate\\Support\\Facades\\Facade",
"function": "__callStatic"
},
{
"file": "controllers/ExampleController.php",
"line": "12",
"class": "Bugsnag\\BugsnagLaravel\\BugsnagFacade",
"function": "notifyError"
},
{
"class": "ExampleController",
"function": "index"
},
{
"file": "Routing/Controller.php",
"line": "194",
"function": "call_user_func_array"
}
]
}

View File

@@ -1,40 +0,0 @@
{
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
"line": 22,
"backtrace": [
{
"file": "/Users/james/src/bugsnag/bugsnag-php/src/Bugsnag/Error.php",
"line": 116,
"function": "generate",
"class": "Bugsnag_Stacktrace"
},
{
"file": "/Users/james/src/bugsnag/bugsnag-php/src/Bugsnag/Error.php",
"line": 25,
"function": "setPHPError",
"class": "Bugsnag_Error"
},
{
"file": "/Users/james/src/bugsnag/bugsnag-php/src/Bugsnag/Client.php",
"line": 346,
"function": "fromPHPError",
"class": "Bugsnag_Error"
},
{
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
"line": 22,
"function": "errorHandler",
"class": "Bugsnag_Client"
},
{
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
"line": 13,
"function": "crashy_function"
},
{
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
"line": 25,
"function": "parent_of_crashy_function"
}
]
}

View File

@@ -1,16 +0,0 @@
{
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
"line": 25,
"backtrace": [
{
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
"line": 13,
"function": "crashy_function"
},
{
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
"line": 28,
"function": "parent_of_crashy_function"
}
]
}

View File

@@ -1,43 +0,0 @@
{
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
"line": 17,
"backtrace": [
{
"file": "/Users/james/src/bugsnag/bugsnag-php/src/Bugsnag/Error.php",
"line": 116,
"function": "generate",
"class": "Bugsnag_Stacktrace"
},
{
"file": "/Users/james/src/bugsnag/bugsnag-php/src/Bugsnag/Error.php",
"line": 25,
"function": "setPHPError",
"class": "Bugsnag_Error"
},
{
"file": "/Users/james/src/bugsnag/bugsnag-php/src/Bugsnag/Client.php",
"line": 346,
"function": "fromPHPError",
"class": "Bugsnag_Error"
},
{
"function": "errorHandler",
"class": "Bugsnag_Client"
},
{
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
"line": 17,
"function": "trigger_error"
},
{
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
"line": 13,
"function": "crashy_function"
},
{
"file": "/Users/james/src/bugsnag/bugsnag-php/testing.php",
"line": 20,
"function": "parent_of_crashy_function"
}
]
}

View File

@@ -1,52 +0,0 @@
{
"file": "somefile.php",
"line": 123,
"backtrace": [
{
"file": "/View/Engines/PhpEngine.php",
"line": 39,
"include_filename": "storage/framework/views/9159822bf9c110749a4f033b96974fef",
"args": []
},
{
"function": "evaluatePath",
"type": "->",
"class": "Illuminate\\View\\Engines\\PhpEngine",
"file": "View/Engines/CompilerEngine.php",
"line": 57,
"args": []
},
{
"function": "get",
"type": "->",
"class": "Illuminate\\View\\Engines\\CompilerEngine",
"file": "View/View.php",
"line": 136,
"args": []
},
{
"function": "getContents",
"type": "->",
"class": "Illuminate\\View\\View",
"file": "View/View.php",
"line": 104,
"args": []
},
{
"function": "renderContents",
"type": "->",
"class": "Illuminate\\View\\View",
"file": "View/View.php",
"line": 78,
"args": []
},
{
"function": "render",
"type": "->",
"class": "Illuminate\\View\\View",
"file": "storage/views/f2df2d6b49591efeb36fc46e6dc25e0e",
"line": 5,
"args": []
}
]
}

View File

@@ -1,21 +0,0 @@
<?
//
// Example PHP file
//
// Some variables
$a = 1;
$b = 2;
// Create an exception
$exception = new Exception("Exception!");
// Throw the exception
throw $exception;
// Some more variables
$c = 3;
$d = 4;
?>

View File

@@ -1,2 +0,0 @@
$a = 1;
$b = 2;

View File

@@ -1,6 +0,0 @@
{
"file": "Bugsnag/Client.php",
"line": "123",
"class": "Bugsnag_Client",
"function": "example_function"
}

View File

@@ -1,5 +0,0 @@
{
"file": "path/some/file.php(123) : eval()'d code",
"line": "12",
"function": "something"
}

View File

@@ -1,6 +0,0 @@
{
"file": "controllers/ExampleController.php",
"line": "12",
"class": "Illuminate\\Support\\Facades\\Facade",
"function": "__callStatic"
}

View File

@@ -1,5 +0,0 @@
{
"file": "path/some/file.php(123) : runtime-created function",
"line": "12",
"function": "something"
}