• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

orchestral / testbench-core / 14964371020

12 May 2025 05:15AM UTC coverage: 92.844% (+0.04%) from 92.808%
14964371020

push

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

21 of 22 new or added lines in 1 file covered. (95.45%)

1492 of 1607 relevant lines covered (92.84%)

69.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.46
/src/Bootstrap/HandleExceptions.php
1
<?php
2

3
namespace Orchestra\Testbench\Bootstrap;
4

5
use Illuminate\Log\LogManager;
6
use Orchestra\Testbench\Exceptions\DeprecatedException;
7
use Orchestra\Testbench\Foundation\Env;
8
use PHPUnit\Runner\ErrorHandler;
9

10
use function Orchestra\Sidekick\join_paths;
11

12
/**
13
 * @internal
14
 */
15
final class HandleExceptions extends \Illuminate\Foundation\Bootstrap\HandleExceptions
16
{
17
    /**
18
     * {@inheritDoc}
19
     *
20
     * @throws \Orchestra\Testbench\Exceptions\DeprecatedException
21
     */
22
    #[\Override]
23
    public function handleDeprecationError($message, $file, $line, $level = E_DEPRECATED)
24
    {
25
        rescue(function () use ($message, $file, $line, $level) {
2✔
26
            parent::handleDeprecationError($message, $file, $line, $level);
2✔
27
        }, null, false);
2✔
28

29
        $testbenchConvertDeprecationsToExceptions = (bool) Env::get(
2✔
30
            'TESTBENCH_CONVERT_DEPRECATIONS_TO_EXCEPTIONS', false
2✔
31
        );
2✔
32

33
        if ($testbenchConvertDeprecationsToExceptions === true) {
2✔
34
            throw new DeprecatedException($message, $level, $file, $line);
1✔
35
        }
36
    }
37

38
    /** {@inheritDoc} */
39
    #[\Override]
40
    protected function ensureDeprecationLoggerIsConfigured()
41
    {
42
        with(self::$app->make('config'), static function ($config) {
2✔
43
            /** @var \Illuminate\Contracts\Config\Repository $config */
44
            if ($config->get('logging.channels.deprecations')) {
2✔
45
                return;
×
46
            }
47

48
            /** @var array{channel?: string, trace?: bool}|string|null $options */
49
            $options = $config->get('logging.deprecations');
2✔
50
            $trace = Env::get('LOG_DEPRECATIONS_TRACE', false);
2✔
51

52
            if (\is_array($options)) {
2✔
53
                $driver = $options['channel'] ?? 'null';
2✔
54
                $trace = $options['trace'] ?? true;
2✔
55
            } else {
56
                $driver = $options ?? 'null';
×
57
            }
58

59
            if ($driver === 'single') {
2✔
60
                $config->set('logging.channels.deprecations', array_merge($config->get('logging.channels.single'), [
×
61
                    'path' => self::$app->storagePath(join_paths('logs', 'deprecations.log')),
×
62
                ]));
×
63
            } else {
64
                $config->set('logging.channels.deprecations', $config->get("logging.channels.{$driver}"));
2✔
65
            }
66

67
            $config->set('logging.deprecations', [
2✔
68
                'channel' => 'deprecations',
2✔
69
                'trace' => $trace,
2✔
70
            ]);
2✔
71
        });
2✔
72
    }
73

74
    /** {@inheritDoc} */
75
    #[\Override]
76
    protected function shouldIgnoreDeprecationErrors()
77
    {
78
        return ! class_exists(LogManager::class)
2✔
79
            || ! self::$app->hasBeenBootstrapped()
2✔
80
            || ! Env::get('LOG_DEPRECATIONS_WHILE_TESTING', true);
2✔
81
    }
82

83
    /** {@inheritDoc} */
84
    #[\Override]
85
    public static function forgetApp()
86
    {
87
        if (\is_null(self::$app)) {
174✔
NEW
88
            return;
×
89
        }
90

91
        self::flushHandlersState();
174✔
92

93
        self::$app = null; /** @phpstan-ignore assign.propertyType */
174✔
94
        self::$reservedMemory = null;
174✔
95
    }
96

97
    /**
98
     * Flush the bootstrapper's global handlers state.
99
     *
100
     * @return void
101
     */
102
    public static function flushHandlersState()
103
    {
104
        while (true) {
174✔
105
            $previousHandler = set_exception_handler(static fn () => null);
174✔
106
            restore_exception_handler();
174✔
107

108
            if ($previousHandler === null) {
174✔
109
                break;
174✔
110
            }
111

112
            restore_exception_handler();
174✔
113
        }
114

115
        while (true) {
174✔
116
            $previousHandler = set_error_handler(static fn () => null); /** @phpstan-ignore argument.type */
174✔
117
            restore_error_handler();
174✔
118

119
            if ($previousHandler === null) {
174✔
120
                break;
174✔
121
            }
122

123
            restore_error_handler();
174✔
124
        }
125

126
        if (class_exists(ErrorHandler::class)) {
174✔
127
            $instance = ErrorHandler::instance();
174✔
128

129
            if ((fn () => $this->enabled ?? false)->call($instance)) {
174✔
130
                $instance->disable();
174✔
131
                $instance->enable();
174✔
132
            }
133
        }
134
    }
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc