-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
TryTo.php
53 lines (42 loc) · 1.42 KB
/
TryTo.php
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
<?php
declare(strict_types=1);
namespace Codeception\Step;
use Codeception\Lib\ModuleContainer;
use Codeception\Util\Template;
use Exception;
use function codecept_debug;
use function ucfirst;
class TryTo extends Assertion implements GeneratedStep
{
public function run(ModuleContainer $container = null): bool
{
$this->isTry = true;
try {
parent::run($container);
} catch (Exception $e) {
codecept_debug("Failed to perform: {$e->getMessage()}, skipping...");
return false;
}
return true;
}
public static function getTemplate(Template $template): ?Template
{
$action = $template->getVar('action');
if ((str_starts_with($action, 'have')) || (str_starts_with($action, 'am'))) {
return null; // dont try on conditions
}
if (str_starts_with($action, 'wait')) {
return null; // dont try on waiters
}
if (str_starts_with($action, 'grab')) {
return null; // dont on grabbers
}
$conditionalDoc = "* [!] Test won't be stopped on fail. Error won't be logged \n " . $template->getVar('doc');
return $template
->place('doc', $conditionalDoc)
->place('action', 'tryTo' . ucfirst($action))
->place('return', 'return ')
->place('return_type', ': bool')
->place('step', 'TryTo');
}
}