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

orchestral / testbench-core / 10483326636

21 Aug 2024 04:07AM UTC coverage: 92.107%. Remained the same
10483326636

Pull #222

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Pull Request #222: [7.x] Utilise `Orchestra\Testbench\join_paths`

11 of 14 new or added lines in 7 files covered. (78.57%)

1132 of 1229 relevant lines covered (92.11%)

60.72 hits per line

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

81.25
/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

9
use function Orchestra\Testbench\join_paths;
10
use function Orchestra\Testbench\phpunit_version_compare;
11

12
/**
13
 * @internal
14
 */
15
final class HandleExceptions extends \Illuminate\Foundation\Bootstrap\HandleExceptions
16
{
17
    /**
18
     * Testbench Class.
19
     *
20
     * @var \PHPUnit\Framework\TestCase|null
21
     */
22
    protected $testbench;
23

24
    /**
25
     * Create a new exception handler instance.
26
     *
27
     * @param  \PHPUnit\Framework\TestCase|null  $testbench
28
     */
29
    public function __construct($testbench = null)
30
    {
31
        $this->testbench = $testbench;
142✔
32
    }
33

34
    /**
35
     * Reports a deprecation to the "deprecations" logger.
36
     *
37
     * @param  string  $message
38
     * @param  string  $file
39
     * @param  int  $line
40
     * @param  int  $level
41
     * @return void
42
     *
43
     * @throws \Orchestra\Testbench\Exceptions\DeprecatedException
44
     */
45
    public function handleDeprecationError($message, $file, $line, $level = E_DEPRECATED)
46
    {
47
        parent::handleDeprecationError($message, $file, $line, $level);
3✔
48

49
        $testbenchConvertDeprecationsToExceptions = Env::get('TESTBENCH_CONVERT_DEPRECATIONS_TO_EXCEPTIONS');
3✔
50

51
        $error = new DeprecatedException($message, $level, $file, $line);
3✔
52

53
        if ($testbenchConvertDeprecationsToExceptions === true) {
3✔
54
            throw $error;
1✔
55
        }
56

57
        if ($testbenchConvertDeprecationsToExceptions !== false && $this->getPhpUnitConvertDeprecationsToExceptions() === true) {
2✔
58
            throw $error;
2✔
59
        }
60
    }
61

62
    /**
63
     * Ensure the "deprecations" logger is configured.
64
     *
65
     * @return void
66
     */
67
    protected function ensureDeprecationLoggerIsConfigured()
68
    {
69
        with(self::$app['config'], static function ($config) { /** @phpstan-ignore offsetAccess.nonOffsetAccessible */
3✔
70
            /** @var \Illuminate\Contracts\Config\Repository $config */
71
            if ($config->get('logging.channels.deprecations')) {
3✔
72
                return;
×
73
            }
74

75
            /** @var array{channel?: string, trace?: bool}|string|null $options */
76
            $options = $config->get('logging.deprecations');
3✔
77

78
            if (\is_array($options)) {
3✔
79
                $driver = $options['channel'] ?? 'null';
3✔
80
            } else {
81
                $driver = $options ?? 'null';
×
82
            }
83

84
            if ($driver === 'single') {
3✔
85
                $config->set('logging.channels.deprecations', array_merge($config->get('logging.channels.single'), [
×
NEW
86
                    'path' => self::$app->storagePath(join_paths('logs', 'deprecations.log')),
×
87
                ]));
×
88
            } else {
89
                $config->set('logging.channels.deprecations', $config->get("logging.channels.{$driver}"));
3✔
90
            }
91

92
            $config->set('logging.deprecations', [
3✔
93
                'channel' => 'deprecations',
3✔
94
                'trace' => true,
3✔
95
            ]);
3✔
96
        });
3✔
97
    }
98

99
    /**
100
     * Get PHPUnit convert deprecations to exceptions from TestResult.
101
     *
102
     * @phpunit-overrides
103
     *
104
     * @return bool
105
     */
106
    protected function getPhpUnitConvertDeprecationsToExceptions(): bool
107
    {
108
        if (phpunit_version_compare('10', '>=')) {
2✔
109
            return false;
×
110
        }
111

112
        /** @var \PHPUnit\Framework\TestResult|null $testResult */
113
        $testResult = $this->testbench?->getTestResultObject();
2✔
114

115
        return $testResult?->getConvertDeprecationsToExceptions() ?? false;
2✔
116
    }
117

118
    /**
119
     * Determine if deprecation error should be ignored.
120
     *
121
     * @return bool
122
     */
123
    protected function shouldIgnoreDeprecationErrors()
124
    {
125
        return ! class_exists(LogManager::class)
3✔
126
            || ! self::$app->hasBeenBootstrapped()
3✔
127
            || ! Env::get('LOG_DEPRECATIONS_WHILE_TESTING', true);
3✔
128
    }
129
}
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