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

orchestral / testbench-core / 14963621168

12 May 2025 04:05AM UTC coverage: 92.331% (-0.1%) from 92.433%
14963621168

push

github

crynobone
[9.x] Improves deprecation during tests when deprecation logs is not available. (#346)

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

4 of 6 new or added lines in 1 file covered. (66.67%)

1529 of 1656 relevant lines covered (92.33%)

74.99 hits per line

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

76.67
/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 Throwable;
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
        try {
26
            parent::handleDeprecationError($message, $file, $line, $level);
2✔
NEW
27
        } catch (Throwable $e) {
×
NEW
28
            throw new DeprecatedException($message, $level, $file, $line);
×
29
        }
30

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

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

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

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

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

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

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

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