@@ -41,7 +41,7 @@ public function usesTypehintsWherePossible(CliGuy $I, Scenario $scenario)
41
41
$ I ->wantToTest ('generate typehints with generated actions ' );
42
42
43
43
$ cliHelperContents = file_get_contents (codecept_root_dir ('tests/support/CliHelper.php ' ));
44
- $ cliHelperContents = str_replace ('public function grabFromOutput($regex) ' , 'public function grabFromOutput($regex): int ' , $ cliHelperContents );
44
+ $ cliHelperContents = str_replace ('public function grabFromOutput($regex) ' , 'public function grabFromOutput(string $regex): int ' , $ cliHelperContents );
45
45
file_put_contents (codecept_root_dir ('tests/support/CliHelper.php ' ), $ cliHelperContents );
46
46
47
47
$ I ->runShellCommand ('php codecept build ' );
@@ -50,15 +50,34 @@ public function usesTypehintsWherePossible(CliGuy $I, Scenario $scenario)
50
50
$ I ->seeInThisFile ('class CliGuy extends \Codeception\Actor ' );
51
51
$ I ->seeInThisFile ('use _generated\CliGuyActions ' );
52
52
$ I ->seeFileFound ('CliGuyActions.php ' , 'tests/support/_generated ' );
53
- $ I ->openFile (codecept_root_dir ('tests/support/CliHelper.php ' ));
54
- $ I ->seeInThisFile ('public function grabFromOutput($regex): int ' );
55
- $ I ->seeInThisFile ('return $match[1] ' );
53
+ $ I ->seeInThisFile ('public function grabFromOutput(string $regex): int ' );
54
+ }
55
+
56
+ public function generatedUnionReturnTypeOnPhp8 (CliGuy $ I , Scenario $ scenario )
57
+ {
58
+ if (PHP_MAJOR_VERSION < 8 ) {
59
+ $ scenario ->skip ('Does not work in PHP < 8 ' );
60
+ }
61
+
62
+ $ I ->wantToTest ('generate action with union return type ' );
63
+
64
+ $ cliHelperContents = file_get_contents (codecept_root_dir ('tests/support/CliHelper.php ' ));
65
+ $ cliHelperContents = str_replace ('public function grabFromOutput($regex) ' , 'public function grabFromOutput(array|string $param): int|string ' , $ cliHelperContents );
66
+ file_put_contents (codecept_root_dir ('tests/support/CliHelper.php ' ), $ cliHelperContents );
67
+
68
+ $ I ->runShellCommand ('php codecept build ' );
69
+ $ I ->seeInShellOutput ('generated successfully ' );
70
+ $ I ->seeInSupportDir ('CliGuy.php ' );
71
+ $ I ->seeInThisFile ('class CliGuy extends \Codeception\Actor ' );
72
+ $ I ->seeInThisFile ('use _generated\CliGuyActions ' );
73
+ $ I ->seeFileFound ('CliGuyActions.php ' , 'tests/support/_generated ' );
74
+ $ I ->seeInThisFile ('public function grabFromOutput(array|string $param): string|int ' );
56
75
}
57
76
58
77
public function noReturnForVoidType (CliGuy $ I , Scenario $ scenario )
59
78
{
60
- if (PHP_MAJOR_VERSION < 7 ) {
61
- $ scenario ->skip ('Does not work in PHP < 7 ' );
79
+ if (PHP_VERSION_ID < 70100 ) {
80
+ $ scenario ->skip ('Does not work in PHP < 7.1 ' );
62
81
}
63
82
64
83
$ I ->wantToTest ('no return keyword generated for void typehint ' );
@@ -73,9 +92,6 @@ public function noReturnForVoidType(CliGuy $I, Scenario $scenario)
73
92
$ I ->seeInThisFile ('class CliGuy extends \Codeception\Actor ' );
74
93
$ I ->seeInThisFile ('use _generated\CliGuyActions ' );
75
94
$ I ->seeFileFound ('CliGuyActions.php ' , 'tests/support/_generated ' );
76
- $ I ->openFile (codecept_root_dir ('tests/support/CliHelper.php ' ));
77
95
$ I ->seeInThisFile ('public function seeDirFound($dir): void ' );
78
- $ I ->dontSeeInThisFile ('return $this->assertTrue(is_dir( ' );
79
- $ I ->seeInThisFile ('$this->assertTrue(is_dir( ' );
80
96
}
81
97
}
0 commit comments