-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShell.php
More file actions
79 lines (66 loc) · 2.42 KB
/
Shell.php
File metadata and controls
79 lines (66 loc) · 2.42 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
79
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace Ibexa\Behat\Core\Debug\Shell;
use Exception;
use Ibexa\Behat\Core\Debug\Matcher\ObjectFunctionCallChainMatcher;
use Ibexa\Behat\Core\Debug\Matcher\ThisObjectMethodsMatcher;
use Psy\Shell as BaseShell;
use Psy\TabCompletion\Matcher\AbstractMatcher;
use Psy\TabCompletion\Matcher\FunctionsMatcher;
class Shell extends BaseShell
{
/**
* @return \Psy\TabCompletion\Matcher\AbstractMatcher[]
*/
protected function getDefaultMatchers(): array
{
$matchers = array_filter(parent::getDefaultMatchers(), static function (AbstractMatcher $matcher) {
// Remove FunctionsMatcher as it spams autocomplete too much
return get_class($matcher) !== FunctionsMatcher::class;
});
$matchers[] = new ThisObjectMethodsMatcher();
$matchers[] = new ObjectFunctionCallChainMatcher();
return $matchers;
}
public function addBaseImports(): void
{
$level = 1;
while (str_contains(dirname(__DIR__, $level), 'vendor')) {
++$level;
}
$dir = dirname(__DIR__, $level);
$classes = array_map(
'strval',
array_keys(require $dir . '/vendor/composer/autoload_classmap.php')
);
$baseImports = array_filter($classes, static function (string $classFcqn): bool {
return str_starts_with($classFcqn, 'Ibexa\Behat\Browser\Element') ||
str_starts_with($classFcqn, 'Ibexa\Behat\Browser\Locator');
});
foreach ($baseImports as $import) {
$this->addInput(sprintf('use %s;', $import), true);
}
}
public function writeStartupMessages(): void
{
$messages = [
'🕵️ Welcome to interactive debugging mode.',
"You can start by running 'trace --num 5' to get an idea which code has been executed so far.",
];
foreach ($messages as $message) {
$this->writeMessage($message);
}
}
public function writeMessage(string $message): void
{
$this->addInput(sprintf('sprintf("%s");', $message), true);
}
public function displayExceptionMessage(Exception $e): void
{
$this->writeMessage('The error message is: ' . $e->getMessage());
}
}