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

orchestral / testbench-core / 11968182539

22 Nov 2024 07:16AM UTC coverage: 91.991% (+0.7%) from 91.321%
11968182539

Pull #265

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Pull Request #265: [7.x] Allow to configure `tty` via `Orchestra\Testbench\remote()` function

3 of 4 new or added lines in 1 file covered. (75.0%)

93 existing lines in 25 files now uncovered.

1206 of 1311 relevant lines covered (91.99%)

61.99 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;
153✔
32
    }
33

34
    /** {@inheritDoc} */
35
    #[\Override]
36
    public function handleDeprecationError($message, $file, $line, $level = E_DEPRECATED)
37
    {
38
        parent::handleDeprecationError($message, $file, $line, $level);
3✔
39

40
        $testbenchConvertDeprecationsToExceptions = Env::get('TESTBENCH_CONVERT_DEPRECATIONS_TO_EXCEPTIONS');
3✔
41

42
        $error = new DeprecatedException($message, $level, $file, $line);
3✔
43

44
        if ($testbenchConvertDeprecationsToExceptions === true) {
3✔
45
            throw $error;
1✔
46
        }
47

48
        if ($testbenchConvertDeprecationsToExceptions !== false && $this->getPhpUnitConvertDeprecationsToExceptions() === true) {
2✔
49
            throw $error;
2✔
50
        }
51
    }
52

53
    /**
54
     * Ensure the "deprecations" logger is configured.
55
     *
56
     * @return void
57
     */
58
    protected function ensureDeprecationLoggerIsConfigured()
59
    {
60
        with(self::$app['config'], static function ($config) { /** @phpstan-ignore offsetAccess.nonOffsetAccessible */
3✔
61
            /** @var \Illuminate\Contracts\Config\Repository $config */
62
            if ($config->get('logging.channels.deprecations')) {
3✔
UNCOV
63
                return;
×
64
            }
65

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

69
            if (\is_array($options)) {
3✔
70
                $driver = $options['channel'] ?? 'null';
3✔
71
            } else {
UNCOV
72
                $driver = $options ?? 'null';
×
73
            }
74

75
            if ($driver === 'single') {
3✔
UNCOV
76
                $config->set('logging.channels.deprecations', array_merge($config->get('logging.channels.single'), [
×
UNCOV
77
                    'path' => self::$app->storagePath(join_paths('logs', 'deprecations.log')),
×
UNCOV
78
                ]));
×
79
            } else {
80
                $config->set('logging.channels.deprecations', $config->get("logging.channels.{$driver}"));
3✔
81
            }
82

83
            $config->set('logging.deprecations', [
3✔
84
                'channel' => 'deprecations',
3✔
85
                'trace' => true,
3✔
86
            ]);
3✔
87
        });
3✔
88
    }
89

90
    /**
91
     * Get PHPUnit convert deprecations to exceptions from TestResult.
92
     *
93
     * @phpunit-overrides
94
     *
95
     * @return bool
96
     */
97
    protected function getPhpUnitConvertDeprecationsToExceptions(): bool
98
    {
99
        if (phpunit_version_compare('10', '>=')) {
2✔
UNCOV
100
            return false;
×
101
        }
102

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

106
        return $testResult?->getConvertDeprecationsToExceptions() ?? false;
2✔
107
    }
108

109
    /**
110
     * Determine if deprecation error should be ignored.
111
     *
112
     * @return bool
113
     */
114
    protected function shouldIgnoreDeprecationErrors()
115
    {
116
        return ! class_exists(LogManager::class)
3✔
117
            || ! self::$app->hasBeenBootstrapped()
3✔
118
            || ! Env::get('LOG_DEPRECATIONS_WHILE_TESTING', true);
3✔
119
    }
120
}
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