-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathDebug.php
More file actions
78 lines (63 loc) · 1.99 KB
/
Copy pathDebug.php
File metadata and controls
78 lines (63 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
namespace Codeception\Util;
use Codeception\Lib\Console\Output;
use Codeception\Lib\PauseShell;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Question\ConfirmationQuestion;
/**
* This class is used only when Codeception is executed in `--debug` mode.
* In other cases method of this class won't be seen.
*/
class Debug
{
protected static ?Output $output = null;
public static function setOutput(Output $output): void
{
self::$output = $output;
}
/**
* Prints data to screen. Message can be any type of data
*/
public static function debug(mixed $message): void
{
self::$output?->debug($message);
}
public static function isEnabled(): bool
{
return self::$output instanceof Output;
}
public static function pause(array $vars = []): void
{
if (!self::isEnabled()) {
return;
}
$pauseShell = new PauseShell();
$psy = $pauseShell->getShell();
$psy->setScopeVariables($vars);
foreach (debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 3) as $backtraceStep) {
$class = $backtraceStep['class'] ?? null;
$fn = $backtraceStep['function'] ?? null;
if (
($class === self::class && $fn === 'pause') ||
($fn === 'codecept_pause' && !$class) ||
!isset($backtraceStep['object'])
) {
continue;
}
$pauseShell->addMessage('Use $this-> to access current object');
$psy->setBoundObject($backtraceStep['object']);
break;
}
$psy->run();
}
public static function confirm($question)
{
if (!self::$output instanceof Output) {
return null;
}
return (new QuestionHelper())
->ask(new ArgvInput(), self::$output, new ConfirmationQuestion($question));
}
}