Skip to content

Commit db06cc9

Browse files
Initial work on laravel 5.6 compatability
1 parent 45dae8c commit db06cc9

File tree

6 files changed

+110
-35
lines changed

6 files changed

+110
-35
lines changed

.travis.yml

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,116 @@ sudo: false
55
matrix:
66
include:
77
- php: 5.5.9
8-
env: GUZZLE_VERSION=^5.3
8+
env:
9+
- GUZZLE_VERSION=^5.3
10+
- LARAVEL_VERSION=5.1.*
911
- php: 5.5.9
10-
env: GUZZLE_VERSION=^6.0
12+
env:
13+
- GUZZLE_VERSION=^6.0
14+
- LARAVEL_VERSION=5.1.*
1115
- php: 5.5
12-
env: GUZZLE_VERSION=^5.3
16+
env:
17+
- GUZZLE_VERSION=^5.3
18+
- LARAVEL_VERSION=5.1.*
1319
- php: 5.5
14-
env: GUZZLE_VERSION=^6.0
20+
env:
21+
- GUZZLE_VERSION=^6.0
22+
- LARAVEL_VERSION=5.1.*
1523
- php: 5.6
16-
env: GUZZLE_VERSION=^5.3
24+
env:
25+
- GUZZLE_VERSION=^5.3
26+
- LARAVEL_VERSION=5.4.*
1727
- php: 5.6
18-
env: GUZZLE_VERSION=^6.0
28+
env:
29+
- GUZZLE_VERSION=^6.0
30+
- LARAVEL_VERSION=5.4.*
1931
- php: 7.0
20-
env: GUZZLE_VERSION=^5.3
32+
env:
33+
- GUZZLE_VERSION=^5.3
34+
- LARAVEL_VERSION=5.5.*
2135
- php: 7.0
22-
env: GUZZLE_VERSION=^6.0
36+
env:
37+
- GUZZLE_VERSION=^6.0
38+
- LARAVEL_VERSION=5.5.*
2339
- php: 7.1
24-
env: GUZZLE_VERSION=^5.3
40+
env:
41+
- GUZZLE_VERSION=^5.3
42+
- LARAVEL_VERSION=5.5.*
2543
- php: 7.1
26-
env: GUZZLE_VERSION=^6.0
44+
env:
45+
- GUZZLE_VERSION=^6.0
46+
- LARAVEL_VERSION=5.5.*
47+
- php: 7.1
48+
env:
49+
- GUZZLE_VERSION=^5.3
50+
- LARAVEL_VERSION=5.6.*
51+
- php: 7.1
52+
env:
53+
- GUZZLE_VERSION=^6.0
54+
- LARAVEL_VERSION=5.6.*
55+
- php: 7.2
56+
env:
57+
- GUZZLE_VERSION=^5.3
58+
- LARAVEL_VERSION=5.5.*
59+
- php: 7.2
60+
env:
61+
- GUZZLE_VERSION=^6.0
62+
- LARAVEL_VERSION=5.5.*
63+
- php: 7.2
64+
env:
65+
- GUZZLE_VERSION=^5.3
66+
- LARAVEL_VERSION=5.6.*
67+
- php: 7.2
68+
env:
69+
- GUZZLE_VERSION=^6.0
70+
- LARAVEL_VERSION=5.6.*
2771
- php: hhvm-3.6
2872
sudo: required
2973
dist: trusty
3074
group: edge
31-
env: GUZZLE_VERSION=^5.3
75+
env:
76+
- GUZZLE_VERSION=^5.3
77+
- LARAVEL_VERSION=5.1.*
3278
- php: hhvm-3.6
3379
sudo: required
3480
dist: trusty
3581
group: edge
36-
env: GUZZLE_VERSION=^6.0
82+
env:
83+
- GUZZLE_VERSION=^6.0
84+
- LARAVEL_VERSION=5.1.*
3785
- php: hhvm-3.9
3886
sudo: required
3987
dist: trusty
4088
group: edge
41-
env: GUZZLE_VERSION=^5.3
89+
env:
90+
- GUZZLE_VERSION=^5.3
91+
- LARAVEL_VERSION=5.1.*
4292
- php: hhvm-3.9
4393
sudo: required
4494
dist: trusty
4595
group: edge
46-
env: GUZZLE_VERSION=^6.0
96+
env:
97+
- GUZZLE_VERSION=^6.0
98+
- LARAVEL_VERSION=5.1.*
4799
- php: hhvm-3.12
48100
sudo: required
49101
dist: trusty
50102
group: edge
51-
env: GUZZLE_VERSION=^5.3
103+
env:
104+
- GUZZLE_VERSION=^5.3
105+
- LARAVEL_VERSION=5.1.*
52106
- php: hhvm-3.12
53107
sudo: required
54108
dist: trusty
55109
group: edge
56-
env: GUZZLE_VERSION=^6.0
110+
env:
111+
- GUZZLE_VERSION=^6.0
112+
- LARAVEL_VERSION=5.1.*
57113

58114
before_install:
59115
- if [[ $TRAVIS_PHP_VERSION =~ ^hhvm ]]; then echo 'hhvm.jit = false' >> /etc/hhvm/php.ini ; fi
60116
- composer require "guzzlehttp/guzzle:${GUZZLE_VERSION}" --no-update
117+
- composer require "laravel/framework:${LARAVEL_VERSION}" --no-update
61118

62119
install:
63120
- if [[ $TRAVIS_PHP_VERSION == 5.5.9 ]]; then travis_retry composer update --no-interaction --prefer-source --prefer-lowest ; fi

composer.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
"illuminate/contracts": "^5.0",
1616
"illuminate/support": "^5.0",
1717
"bugsnag/bugsnag": "^3.12",
18-
"bugsnag/bugsnag-psr-logger": "^1.4.0"
18+
"bugsnag/bugsnag-psr-logger": "^1.4",
19+
"monolog/monolog": "^1.12"
1920
},
2021
"require-dev": {
21-
"graham-campbell/testbench": "^3.1",
22-
"mockery/mockery": "^0.9.4",
23-
"phpunit/phpunit": "^4.8|^5.0"
22+
"graham-campbell/testbench": "^3.1|^4.0|^5.0",
23+
"mockery/mockery": "^1.0",
24+
"phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0"
2425
},
2526
"autoload": {
2627
"psr-4": {
@@ -30,7 +31,10 @@
3031
"autoload-dev": {
3132
"psr-4" : {
3233
"Bugsnag\\BugsnagLaravel\\Tests\\" : "tests/"
33-
}
34+
},
35+
"files": [
36+
"tests/bc.php"
37+
]
3438
},
3539
"extra": {
3640
"branch-alias": {

src/BugsnagServiceProvider.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@
88
use Bugsnag\Callbacks\CustomUser;
99
use Bugsnag\Client;
1010
use Bugsnag\Configuration;
11+
use Bugsnag\PsrLogger\BugsnagLogger;
12+
use Bugsnag\PsrLogger\MultiLogger as BaseMultiLogger;
1113
use Bugsnag\Report;
1214
use Illuminate\Auth\GenericUser;
1315
use Illuminate\Contracts\Container\Container;
1416
use Illuminate\Contracts\Events\Dispatcher;
17+
use Illuminate\Contracts\Logging\Log;
1518
use Illuminate\Database\Events\QueryExecuted;
1619
use Illuminate\Foundation\Application as LaravelApplication;
20+
use Illuminate\Logging\LogManager;
1721
use Illuminate\Queue\Events\JobProcessing;
1822
use Illuminate\Queue\QueueManager;
1923
use Illuminate\Routing\Events\RouteMatched;
2024
use Illuminate\Support\ServiceProvider;
2125
use Laravel\Lumen\Application as LumenApplication;
26+
use Monolog\Handler\PsrHandler;
27+
use Monolog\Logger;
2228
use ReflectionClass;
2329

2430
class BugsnagServiceProvider extends ServiceProvider
@@ -221,7 +227,7 @@ public function register()
221227

222228
$this->app->singleton('bugsnag.logger', function (Container $app) {
223229
$config = $app->config->get('bugsnag');
224-
$logger = new LaravelLogger($app['bugsnag'], $app['events']);
230+
$logger = class_exists(Log::class) ? new LaravelLogger($app['bugsnag'], $app['events']) : new BugsnagLogger($app['bugsnag']);
225231
if (isset($config['logger_notify_level'])) {
226232
$logger->setNotifyLevel($config['logger_notify_level']);
227233
}
@@ -230,13 +236,21 @@ public function register()
230236
});
231237

232238
$this->app->singleton('bugsnag.multi', function (Container $app) {
233-
return new MultiLogger([$app['log'], $app['bugsnag.logger']], $app['events']);
239+
return class_exists(Log::class) ? new MultiLogger([$app['log'], $app['bugsnag.logger']], $app['events']) : new BaseMultiLogger([$app['log'], $app['bugsnag.logger']]);
234240
});
235241

242+
if ($this->app['log'] instanceof LogManager) {
243+
$this->app['log']->extend('bugsnag', function (Container $app, array $config) {
244+
$handler = new PsrHandler($app['bugsnag.logger']);
245+
246+
return new Logger('bugsnag', [$handler]);
247+
});
248+
}
249+
236250
$this->app->alias('bugsnag', Client::class);
237251
$this->app->alias('bugsnag.tracker', Tracker::class);
238-
$this->app->alias('bugsnag.logger', LaravelLogger::class);
239-
$this->app->alias('bugsnag.multi', MultiLogger::class);
252+
$this->app->alias('bugsnag.logger', class_exists(Log::class) ? LaravelLogger::class : BugsnagLogger::class);
253+
$this->app->alias('bugsnag.multi', class_exists(Log::class) ? MultiLogger::class : BaseMultiLogger::class);
240254
}
241255

242256
/**

tests/AbstractTestCase.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77

88
abstract class AbstractTestCase extends AbstractPackageTestCase
99
{
10-
/**
11-
* @before
12-
*/
13-
public function setTheApiKey()
14-
{
15-
$this->app->config->set('bugsnag.api_key', 'qwertyuiop');
16-
}
17-
1810
/**
1911
* Get the service provider class.
2012
*

tests/ServiceProviderTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
use Bugsnag\BugsnagLaravel\MultiLogger;
77
use Bugsnag\BugsnagLaravel\Queue\Tracker;
88
use Bugsnag\Client;
9+
use Bugsnag\PsrLogger\BugsnagLogger;
10+
use Bugsnag\PsrLogger\MultiLogger as BaseMultiLogger;
911
use GrahamCampbell\TestBenchCore\ServiceProviderTrait;
12+
use Illuminate\Contracts\Logging\Log;
1013

1114
class ServiceProviderTest extends AbstractTestCase
1215
{
@@ -24,11 +27,11 @@ public function testJobTrackerIsInjectable()
2427

2528
public function testMultiLoggerIsInjectable()
2629
{
27-
$this->assertIsInjectable(MultiLogger::class);
30+
$this->assertIsInjectable(class_exists(Log::class) ? MultiLogger::class : BaseMultiLogger::class);
2831
}
2932

3033
public function testBugsnagLoggerIsInjectable()
3134
{
32-
$this->assertIsInjectable(LaravelLogger::class);
35+
$this->assertIsInjectable(class_exists(Log::class) ? LaravelLogger::class : BugsnagLogger::class);
3336
}
3437
}

tests/bc.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
if (class_exists(PHPUnit\Framework\TestCase::class) && !class_exists(PHPUnit_Framework_TestCase::class)) {
4+
class_alias(PHPUnit\Framework\TestCase::class, PHPUnit_Framework_TestCase::class);
5+
}

0 commit comments

Comments
 (0)