-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathTryTo.php
More file actions
51 lines (42 loc) · 1.33 KB
/
TryTo.php
File metadata and controls
51 lines (42 loc) · 1.33 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
<?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 = (string) $template->getVar('action');
if (
str_starts_with($action, 'have') ||
str_starts_with($action, 'am') ||
str_starts_with($action, 'wait') ||
str_starts_with($action, 'grab')
) {
return null;
}
$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');
}
}