Skip to content

Commit 4801304

Browse files
authored
Merge pull request #26 from bilfeldt/features/log-testing
Fix log testing and increase minimum requirement to laravel 9 and php 8.1
2 parents c252465 + 6f90cbb commit 4801304

File tree

6 files changed

+68
-53
lines changed

6 files changed

+68
-53
lines changed

.github/workflows/psalm.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Setup PHP
1717
uses: shivammathur/setup-php@v2
1818
with:
19-
php-version: '7.4'
19+
php-version: '8.2'
2020
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
2121
coverage: none
2222

.github/workflows/run-tests.yml

+6-9
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,17 @@ jobs:
66
test:
77
runs-on: ${{ matrix.os }}
88
strategy:
9-
fail-fast: true
9+
fail-fast: false
1010
matrix:
1111
os: [ubuntu-latest, windows-latest]
12-
php: [8.0, 7.4]
13-
laravel: [9.*, 8.*]
12+
php: [8.2, 8.1]
13+
laravel: [10.*, 9.*]
1414
stability: [prefer-stable]
1515
include:
16+
- laravel: 10.*
17+
testbench: 8.*
1618
- laravel: 9.*
1719
testbench: 7.*
18-
- laravel: 8.*
19-
testbench: 6.*
20-
exclude:
21-
- laravel: 9.*
22-
php: 7.4
2320

2421
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2522

@@ -42,7 +39,7 @@ jobs:
4239
- name: Install dependencies
4340
run: |
4441
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
45-
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
42+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction --dev
4643
4744
- name: Execute tests
4845
run: vendor/bin/phpunit

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to `laravel-http-client-logger` will be documented in this f
44

55
## Upgrade guides
66

7+
### 1.* => 2.
8+
9+
No breaking changes. The only changes are to the development dependencies used for testing and then the minimum Laravel and PHP requirements.
10+
711
### 0.3.0 => 1.0.0
812

913
This release flattens the configuration variables. It is suggested to republish the configuration after upgrading.
@@ -51,6 +55,13 @@ The following changes are required when updating:
5155

5256
## Changes
5357

58+
### 2.0.0
59+
60+
- Minimum PHP requirement 8.1
61+
- Add support for PHP 8.2
62+
- Minimum Laravel requirement 9.0
63+
- Add support for Laravel 10.*
64+
5465
### 1.3.0
5566

5667
- Added return types for better IDE completion by @shahruslan in #24

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
An easy yet very flexible logger for the Laravel HTTP Client.
1212

13+
| Version | Laravel | PHP |
14+
|---------|-------------|----------------|
15+
| 1.* | 8.* \| 9.* | 7.4.* \| 8.0.* |
16+
| 2.* | 9.* \| 10.* | 8.1.* \| 8.2.* |
17+
1318
## Installation
1419

1520
You can install the package via composer:

composer.json

+4-10
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020
}
2121
],
2222
"require": {
23-
"php": "^7.4 || ^8.0",
23+
"php": "~8.2.0 | ~8.1.0",
2424
"ext-json": "*",
2525
"guzzlehttp/guzzle": "^7.2",
26-
"illuminate/http": "^8.0 || ^9.0",
27-
"illuminate/support": "^8.0 || ^9.0",
26+
"illuminate/http": "^9.0 || ^10.0",
27+
"illuminate/support": "^9.0 || ^10.0",
2828
"spatie/laravel-package-tools": "^1.1"
2929
},
3030
"require-dev": {
3131
"orchestra/testbench": "^7.0",
3232
"phpunit/phpunit": "^9.5.10",
3333
"spatie/laravel-ray": "^1.29",
34-
"timacdonald/log-fake": "dev-return-types",
34+
"timacdonald/log-fake": "^2.0",
3535
"vimeo/psalm": "^4.20"
3636
},
3737
"autoload": {
@@ -44,12 +44,6 @@
4444
"Bilfeldt\\LaravelHttpClientLogger\\Tests\\": "tests"
4545
}
4646
},
47-
"repositories": [
48-
{
49-
"type": "vcs",
50-
"url": "https://github.com/bilfeldt/log-fake.git"
51-
}
52-
],
5347
"scripts": {
5448
"psalm": "vendor/bin/psalm",
5549
"test": "vendor/bin/phpunit --colors=always",

tests/HttpLoggerTest.php

+41-33
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use GuzzleHttp\Psr7\Response;
99
use Illuminate\Support\Facades\Log;
1010
use Illuminate\Support\Str;
11+
use TiMacDonald\Log\LogEntry;
1112
use TiMacDonald\Log\LogFake;
1213

1314
class HttpLoggerTest extends TestCase
@@ -26,118 +27,125 @@ public function setUp(): void
2627

2728
public function test_response_code_200_logs_debug_level()
2829
{
29-
Log::swap(new LogFake());
30+
LogFake::bind();
3031

3132
$this->logger->log($this->request, new Response(200), 0.2);
3233

33-
Log::assertLogged('debug');
34+
Log::assertLogged(fn (LogEntry $log) => $log->level === 'debug');
3435
}
3536

3637
public function test_response_code_300_logs_info_level()
3738
{
38-
Log::swap(new LogFake());
39+
LogFake::bind();
3940

4041
$this->logger->log($this->request, new Response(300), 0.2);
4142

42-
Log::assertLogged('info');
43+
Log::assertLogged(fn (LogEntry $log) => $log->level === 'info');
4344
}
4445

4546
public function test_response_code_400_logs_error_level()
4647
{
47-
Log::swap(new LogFake());
48+
LogFake::bind();
4849

4950
$this->logger->log($this->request, new Response(400), 0.2);
5051

51-
Log::assertLogged('error');
52+
Log::assertLogged(fn (LogEntry $log) => $log->level === 'error');
5253
}
5354

5455
public function test_response_code_400_logs_critical_level()
5556
{
56-
Log::swap(new LogFake());
57+
LogFake::bind();
5758

5859
$this->logger->log($this->request, new Response(500), 0.2);
5960

60-
Log::assertLogged('critical');
61+
Log::assertLogged(fn (LogEntry $log) => $log->level === 'critical');
6162
}
6263

6364
public function test_log_contains_request_header()
6465
{
65-
Log::swap(new LogFake());
66+
LogFake::bind();
6667

6768
$this->logger->log($this->request, new Response(200), 0.2);
6869

69-
Log::assertLogged('debug', function ($message, $context) {
70-
return Str::contains($message, 'header1: HIJKL');
70+
Log::assertLogged(function (LogEntry $log): bool {
71+
return $log->level === 'debug'
72+
&& Str::contains($log->message, 'header1: HIJKL');
7173
});
7274
}
7375

7476
public function test_log_contains_request_body()
7577
{
76-
Log::swap(new LogFake());
78+
LogFake::bind();
7779

7880
$this->logger->log($this->request, new Response(200), 0.2);
7981

80-
Log::assertLogged('debug', function ($message, $context) {
81-
return Str::contains($message, 'TestRequestBody');
82+
Log::assertLogged(function (LogEntry $log): bool {
83+
return $log->level === 'debug'
84+
&& Str::contains($log->message, 'TestRequestBody');
8285
});
8386
}
8487

8588
public function test_log_contains_response_header()
8689
{
87-
Log::swap(new LogFake());
90+
LogFake::bind();
8891

8992
$this->logger->log($this->request, new Response(200, ['header2' => 'XYZ']), 0.2);
9093

91-
Log::assertLogged('debug', function ($message, $context) {
92-
return Str::contains($message, 'header2: XYZ');
94+
Log::assertLogged(function (LogEntry $log): bool {
95+
return $log->level === 'debug'
96+
&& Str::contains($log->message, 'header2: XYZ');
9397
});
9498
}
9599

96100
public function test_log_contains_response_body()
97101
{
98-
Log::swap(new LogFake());
102+
LogFake::bind();
99103

100104
$this->logger->log($this->request, new Response(200, [], 'TestResponseBody'), 0.2);
101105

102-
Log::assertLogged('debug', function ($message, $context) {
103-
return Str::contains($message, 'TestResponseBody');
106+
Log::assertLogged(function (LogEntry $log): bool {
107+
return $log->level === 'debug'
108+
&& Str::contains($log->message, 'TestResponseBody');
104109
});
105110
}
106111

107112
public function test_logs_context()
108113
{
109-
Log::swap(new LogFake());
114+
LogFake::bind();
110115

111116
$this->logger->log($this->request, new Response(200), 0.2, ['context']);
112117

113-
Log::assertLogged('debug', function ($message, $context) {
114-
return $context == ['context'];
118+
Log::assertLogged(function (LogEntry $log): bool {
119+
return $log->level === 'debug'
120+
&& $log->context == ['context'];
115121
});
116122
}
117123

118124
public function test_replaces_placeholders_from_request()
119125
{
120-
Log::swap(new LogFake());
126+
LogFake::bind();
121127

122128
$this->logger->log($this->request, new Response(200), 0.2, ['test123'], ['replace' => ['example.com' => 'mock.org']]);
123129

124-
Log::assertLogged('debug', function ($message, $context) {
125-
return Str::contains($message, 'mock.org')
126-
&& !Str::contains($message, 'example.com')
127-
&& $context == ['test123'];
130+
Log::assertLogged(function (LogEntry $log): bool {
131+
return $log->level === 'debug'
132+
&& Str::contains($log->message, 'mock.org')
133+
&& !Str::contains($log->message, 'example.com')
134+
&& $log->context == ['test123'];
128135
});
129136
}
130137

131138
public function test_replaces_placeholders_from_response()
132139
{
133-
Log::swap(new LogFake());
140+
LogFake::bind();
134141

135142
$this->logger->log($this->request, new Response(200, [], 'My name is John Doe'), 0.2, ['test123'], ['replace' => ['Doe' => 'Smith']]);
136143

137-
Log::assertLogged('debug', function ($message, $context) {
138-
return Str::contains($message, 'Smith')
139-
&& !Str::contains($message, 'Doe')
140-
&& $context == ['test123'];
144+
Log::assertLogged(function (LogEntry $log): bool {
145+
return $log->level === 'debug'
146+
&& Str::contains($log->message, 'Smith')
147+
&& !Str::contains($log->message, 'Doe')
148+
&& $log->context == ['test123'];
141149
});
142150
}
143151
}

0 commit comments

Comments
 (0)