Skip to content

Commit c854a7c

Browse files
committed
CI Fix
1 parent 116b548 commit c854a7c

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

tests/Feature/CcpTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Kirschbaum\Monitor\Facades\Monitor;
88

99
it('logs ccp start and end', function () {
10+
$this->setupLogMocking();
11+
1012
Log::shouldReceive('info')
1113
->once()
1214
->withArgs(function ($message, $context) {
@@ -29,6 +31,8 @@
2931
});
3032

3133
it('logs ccp failure and throws', function () {
34+
$this->setupLogMocking();
35+
3236
Config::set('app.debug', false);
3337
Config::set('monitor.exception_trace.enabled', true);
3438
Config::set('monitor.exception_trace.full_on_debug', false);
@@ -52,6 +56,8 @@
5256
});
5357

5458
it('executes onFail callback when CCP fails', function () {
59+
$this->setupLogMocking();
60+
5561
Config::set('monitor.exception_trace.enabled', false);
5662

5763
$callbackExecuted = false;
@@ -81,6 +87,8 @@
8187
});
8288

8389
it('does not execute onFail callback when CCP succeeds', function () {
90+
$this->setupLogMocking();
91+
8492
$callbackExecuted = false;
8593

8694
Log::shouldReceive('info')->twice(); // STARTED and ENDED
@@ -96,6 +104,8 @@
96104
});
97105

98106
it('handles onFail callback exceptions gracefully', function () {
107+
$this->setupLogMocking();
108+
99109
Config::set('monitor.exception_trace.enabled', false);
100110

101111
Log::shouldReceive('info')->once(); // STARTED
@@ -119,6 +129,8 @@
119129
});
120130

121131
it('works without onFail callback (backward compatibility)', function () {
132+
$this->setupLogMocking();
133+
122134
Log::shouldReceive('info')->twice(); // STARTED and ENDED
123135

124136
$result = Monitor::ccp('backward_compat_test', fn () => 'success', ['key' => 'value']);
@@ -127,6 +139,8 @@
127139
});
128140

129141
it('passes correct context data to onFail callback', function () {
142+
$this->setupLogMocking();
143+
130144
Config::set('monitor.exception_trace.enabled', false);
131145

132146
$capturedContext = null;
@@ -154,6 +168,8 @@
154168
});
155169

156170
it('allows onFail callback to perform escalation actions', function () {
171+
$this->setupLogMocking();
172+
157173
Config::set('monitor.exception_trace.enabled', false);
158174

159175
$alertSent = false;
@@ -181,6 +197,8 @@
181197
});
182198

183199
it('provides complete exception information to onFail callback', function () {
200+
$this->setupLogMocking();
201+
184202
Config::set('monitor.exception_trace.enabled', true);
185203
Config::set('app.debug', true);
186204
Config::set('monitor.exception_trace.full_on_debug', true);
@@ -211,6 +229,8 @@
211229
// NEW COMPREHENSIVE TESTS:
212230

213231
it('does not include exception trace when disabled', function () {
232+
$this->setupLogMocking();
233+
214234
Config::set('monitor.exception_trace.enabled', false); // This tests line 67
215235

216236
Log::shouldReceive('info')->once(); // STARTED log
@@ -229,6 +249,8 @@
229249
});
230250

231251
it('includes full trace when debug mode is enabled', function () {
252+
$this->setupLogMocking();
253+
232254
Config::set('app.debug', true);
233255
Config::set('monitor.exception_trace.enabled', true);
234256
Config::set('monitor.exception_trace.full_on_debug', true);
@@ -250,6 +272,8 @@
250272
});
251273

252274
it('truncates trace when not in debug mode', function () {
275+
$this->setupLogMocking();
276+
253277
Config::set('app.debug', false);
254278
Config::set('monitor.exception_trace.enabled', true);
255279
Config::set('monitor.exception_trace.full_on_debug', true);
@@ -272,6 +296,8 @@
272296
});
273297

274298
it('forces full trace when force_full_trace is enabled', function () {
299+
$this->setupLogMocking();
300+
275301
Config::set('app.debug', false); // Debug off
276302
Config::set('monitor.exception_trace.enabled', true);
277303
Config::set('monitor.exception_trace.force_full_trace', true); // But force full trace
@@ -294,6 +320,8 @@
294320
});
295321

296322
it('includes custom context in both success and failure logs', function () {
323+
$this->setupLogMocking();
324+
297325
$customContext = ['user_id' => 123, 'action' => 'test_action'];
298326

299327
Log::shouldReceive('info')
@@ -319,6 +347,8 @@
319347
});
320348

321349
it('preserves custom context in failure logs', function () {
350+
$this->setupLogMocking();
351+
322352
$customContext = ['user_id' => 456, 'critical_action' => true];
323353

324354
Config::set('monitor.exception_trace.enabled', false); // No exception details
@@ -339,6 +369,8 @@
339369
});
340370

341371
it('includes all required fields in exception trace', function () {
372+
$this->setupLogMocking();
373+
342374
Config::set('monitor.exception_trace.enabled', true);
343375

344376
Log::shouldReceive('info')->once(); // STARTED log
@@ -374,6 +406,8 @@
374406
// The logic should be: $isDebug = Config::boolean('app.debug') || Config::boolean('monitor.exception_trace.force_full_trace', false);
375407
// If mutated to &&, this test will fail
376408

409+
$this->setupLogMocking();
410+
377411
Config::set('app.debug', false); // Debug is OFF
378412
Config::set('monitor.exception_trace.enabled', true);
379413
Config::set('monitor.exception_trace.force_full_trace', true); // But force is ON

tests/Feature/StructuredLoggerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
});
8484

8585
it('logs with enriched context', function () {
86+
$this->setupLogMocking();
87+
8688
config()->set('monitor.origin_path_wrapper', 'square');
8789

8890
Log::shouldReceive('info')
@@ -108,6 +110,8 @@
108110
});
109111

110112
it('logs all levels correctly', function () {
113+
$this->setupLogMocking();
114+
111115
config()->set('monitor.origin_path_wrapper', 'none');
112116

113117
$levels = ['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'];
@@ -126,6 +130,8 @@
126130
});
127131

128132
it('logs via the generic log() method', function () {
133+
$this->setupLogMocking();
134+
129135
config()->set('monitor.origin_path_wrapper', 'none');
130136

131137
Log::shouldReceive('info')
@@ -157,6 +163,8 @@
157163
});
158164

159165
it('handles custom context in logging', function () {
166+
$this->setupLogMocking();
167+
160168
config()->set('monitor.origin_path_wrapper', 'none');
161169

162170
$customContext = ['user_id' => 123, 'action' => 'test'];

tests/TestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Closure;
88
use Illuminate\Support\Facades\Http;
9+
use Illuminate\Support\Facades\Log;
910
use Kirschbaum\Monitor\MonitorServiceProvider;
1011
use Mockery\MockInterface;
1112
use Orchestra\Testbench\Concerns\WithWorkbench;
@@ -29,6 +30,18 @@ protected function setUp(): void
2930
Http::preventingStrayRequests();
3031
}
3132

33+
/**
34+
* Set up Log facade mocking to handle both explicit expectations and channel() calls.
35+
* Call this at the beginning of tests that need to mock Log methods.
36+
*/
37+
protected function setupLogMocking(): void
38+
{
39+
// Allow channel() calls that may happen during Carbon/exception handling
40+
Log::shouldReceive('channel')
41+
->andReturnSelf()
42+
->byDefault();
43+
}
44+
3245
/**
3346
* Force bind a mock into the container for app() calls with parameters.
3447
*/

0 commit comments

Comments
 (0)