Skip to content

Commit f9b217d

Browse files
authored
Merge pull request #57 from understand/feature/laravel-9-php-8-1
Laravel 9 and PHP8.1 support
2 parents 40d402e + 4b1fecd commit f9b217d

File tree

6 files changed

+71
-43
lines changed

6 files changed

+71
-43
lines changed

.github/workflows/run-test.yml

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ name: run-tests
33
jobs:
44
php-tests:
55
runs-on: ubuntu-latest
6+
continue-on-error: true
67

78
strategy:
89
matrix:
9-
php: [8.0, 7.4, 7.3, 7.2]
10-
laravel: [8.*, 7.*, 6.*, 5.8.*, 5.7.*, 5.6.*, 5.5.*]
10+
php: [8.1, 8.0, 7.4, 7.3, 7.2]
11+
laravel: [9.*, 8.*, 7.*, 6.*, 5.8.*, 5.7.*, 5.6.*, 5.5.*]
1112

1213
include:
14+
- laravel: 9.*
15+
testbench: 7.*
1316
- laravel: 8.*
1417
testbench: 6.*
1518
- laravel: 7.*
@@ -26,20 +29,38 @@ jobs:
2629
testbench: 3.5.*
2730

2831
exclude:
29-
- laravel: 8.*
30-
php: 7.2
31-
- laravel: 5.8.*
32-
php: 8.0
33-
- laravel: 5.7.*
34-
php: 8.0
35-
- laravel: 5.6.*
36-
php: 8.0
37-
- laravel: 5.5.*
38-
php: 8.0
39-
- laravel: 5.5.*
40-
php: 7.4
32+
- php: 7.2
33+
laravel: 9.*
34+
- php: 7.3
35+
laravel: 9.*
36+
- php: 7.4
37+
laravel: 9.*
38+
- php: 7.2
39+
laravel: 8.*
40+
- php: 8.1
41+
laravel: 7.*
42+
- php: 8.1
43+
laravel: 6.*
44+
- php: 8.1
45+
laravel: 5.8.*
46+
- php: 8.0
47+
laravel: 5.8.*
48+
- php: 8.1
49+
laravel: 5.7.*
50+
- php: 8.0
51+
laravel: 5.7.*
52+
- php: 8.1
53+
laravel: 5.6.*
54+
- php: 8.0
55+
laravel: 5.6.*
56+
- php: 8.1
57+
laravel: 5.5.*
58+
- php: 8.0
59+
laravel: 5.5.*
60+
- php: 7.4
61+
laravel: 5.5.*
4162

42-
name: P${{ matrix.php }} - L${{ matrix.laravel }}
63+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - T${{ matrix.testbench }}
4364

4465
steps:
4566
- name: Checkout code
@@ -54,8 +75,8 @@ jobs:
5475

5576
- name: Install dependencies
5677
run: |
57-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
58-
composer update --prefer-dist --no-interaction
78+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
79+
composer update --prefer-dist --no-interaction
5980
6081
- name: Execute tests
6182
run: vendor/bin/phpunit

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "understand/understand-laravel",
3-
"description": "Laravel 5, 6, 7 and 8 service provider for Understand.io",
4-
"keywords": ["laravel", "understand.io", "understand", "logs", "laravel 5", "Laravel 6"],
3+
"description": "Laravel 5, 6, 7, 8 and 9 service provider for Understand.io",
4+
"keywords": ["laravel", "understand.io", "understand", "logs"],
55
"license": "MIT",
66
"authors": [
77
{
@@ -10,14 +10,15 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^5.5 || ^7.0 || ^8.0",
13+
"php": "^5.5 || ^7.0 || ^8.0 || ^8.1",
1414
"ext-curl": "*",
15-
"illuminate/support": "^5.0 || ^6.0 || ^7.0 || ^8.0"
15+
"illuminate/support": "^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
1616
},
1717
"require-dev": {
1818
"phpunit/phpunit": "^6.0 || ^7.0 || ^8.0 || ^9.0",
1919
"orchestra/testbench": "3.* || 4.* || 5.* || 6.*",
20-
"mockery/mockery": "^1.2"
20+
"mockery/mockery": "^1.2",
21+
"ext-json": "*"
2122
},
2223
"autoload": {
2324
"psr-0": {
@@ -26,7 +27,7 @@
2627
},
2728
"extra": {
2829
"component": "package",
29-
"frameworks": ["Laravel 5", "Laravel 6", "Laravel 7", "Laravel 8"],
30+
"frameworks": ["Laravel 5", "Laravel 6", "Laravel 7", "Laravel 8", "Laravel 9"],
3031
"branch-alias": {
3132
"dev-master": "2.0-dev"
3233
},

src/Understand/UnderstandLaravel5/Handlers/BaseHandler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ protected function getEndpoint()
9898
*/
9999
protected function parseResponse($response)
100100
{
101+
if (is_null($response)) {
102+
return [];
103+
}
104+
101105
return json_decode($response, true);
102106
}
103107
}

src/Understand/UnderstandLaravel5/UnderstandLaravel5ServiceProvider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,18 @@ protected function resolveHandler($app)
298298

299299
throw new \ErrorException('understand-laravel handler misconfiguration:' . $handlerType);
300300
}
301-
301+
302302
/**
303303
* Detect Laravel version
304-
*
304+
*
305305
* @param array $versions
306306
* @return type
307307
*/
308308
protected function detectLaravelVersion(array $versions)
309309
{
310310
return Str::startsWith(Application::VERSION, $versions);
311311
}
312-
312+
313313
/**
314314
* Listen Laravel logs and queue events
315315
*
@@ -329,7 +329,7 @@ protected function listenLaravelEvents()
329329
{
330330
// starting from L5.4 MessageLogged event class was introduced
331331
// https://github.com/laravel/framework/commit/57c82d095c356a0fe0f9381536afec768cdcc072
332-
$this->app['events']->listen('Illuminate\Log\Events\MessageLogged', function($log)
332+
$this->app['events']->listen('Illuminate\Log\Events\MessageLogged', function($log)
333333
{
334334

335335
$this->handleEvent($log->level, $log->message, $log->context);
@@ -401,7 +401,7 @@ protected function listenQueryEvents()
401401

402402
/**
403403
* Handle a new log event
404-
*
404+
*
405405
* @param string $level
406406
* @param mixed $message
407407
* @param array $context

tests/EventListenerTest.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function testIgnoredLogsConfig()
144144

145145
$this->assertSame($called, 2);
146146
}
147-
147+
148148
/**
149149
* Test error handler logging
150150
*/
@@ -168,18 +168,18 @@ public function testErrorHandlerExceptionLogging()
168168
$handler = new CallbackHandler($callback);
169169

170170
$this->app['understand.logger'] = new Logger($fieldProvider, $handler, false);
171-
171+
172172
$this->app->singleton('Illuminate\Contracts\Debug\ExceptionHandler', 'Illuminate\Foundation\Exceptions\Handler');
173-
173+
174174
$exception = new \RuntimeException('Test');
175175
$this->app['Illuminate\Foundation\Exceptions\Handler']->report($exception);
176-
176+
177177
$this->assertSame($called, 1);
178178
}
179-
179+
180180
/**
181181
* Test message tag
182-
*
182+
*
183183
* @return void
184184
*/
185185
public function testExceptionLogTag()
@@ -199,28 +199,28 @@ public function testExceptionLogTag()
199199
$handler = new CallbackHandler($callback);
200200

201201
$this->app['understand.logger'] = new Logger($fieldProvider, $handler, false);
202-
202+
203203
$exception = new \RuntimeException('Test');
204204
$this->app['Psr\Log\LoggerInterface']->error($exception);
205205

206206
$this->assertSame($called, 1);
207207
$this->assertTrue($exceptionLogTag);
208208
}
209-
209+
210210
/**
211211
* Test token provider values
212-
*
212+
*
213213
* @return void
214214
*/
215215
public function testTokenProviderValue()
216216
{
217217
$token = $this->app['understand.tokenProvider']->getToken();
218218
$token2 = $this->app['understand.tokenProvider']->getToken();
219-
219+
220220
$this->assertNotEmpty($token2);
221221
$this->assertSame($token2, $token);
222222
}
223-
223+
224224
/**
225225
* @return void
226226
*/
@@ -250,7 +250,7 @@ public function testLoggerMessageInteger()
250250
$this->assertSame($called, 1);
251251
$this->assertTrue($messageSame);
252252
}
253-
253+
254254
/**
255255
* @return void
256256
*/
@@ -265,8 +265,10 @@ public function testLoggerMessageBoolean()
265265
$called++;
266266
$decoded = json_decode($data, true);
267267

268-
// `false` should be casted to `0`
269-
$messageSame = '0' === $decoded['message'];
268+
// `false` should be casted to `0` in L<9
269+
// `false` should be casted to `` in L9
270+
$messageSame = in_array($decoded['message'], ['', '0'], true);
271+
270272
$laravelLogTag = in_array('exception_log', $decoded['tags'], true);
271273
};
272274

tests/ExceptionEncoderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function assertIncompleteClassStackTrace($exception, $index)
101101
$encoder = new Understand\UnderstandLaravel5\ExceptionEncoder();
102102
$stackTraceArray = $encoder->stackTraceToArray($exception->getTrace());
103103

104-
if (Str::startsWith(phpversion(), ['7.4', '8.0'])) {
104+
if (Str::startsWith(phpversion(), ['7.4', '8.0', '8.1'])) {
105105
// As of PHP 7.4 Exception::getTrace()
106106
// no longer contains "args" keys by default
107107
$this->assertSame([], $stackTraceArray[$index]['args']);

0 commit comments

Comments
 (0)