Repository navigation
Expand file tree
/
Copy pathBuildCest.php
More file actions
106 lines (88 loc) · 4.86 KB
/
Copy pathBuildCest.php
File metadata and controls
106 lines (88 loc) · 4.86 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
declare(strict_types=1);
// @group core
use Codeception\Scenario;
final class BuildCest
{
/** @var string */
private string $originalCliHelperContents;
public function _before()
{
$this->originalCliHelperContents = file_get_contents(codecept_root_dir('tests/support/CliHelper.php'));
}
public function _after()
{
file_put_contents(codecept_root_dir('tests/support/CliHelper.php'), $this->originalCliHelperContents);
}
public function buildsActionsForAClass(CliGuy $I)
{
$I->wantToTest('build command');
$I->runShellCommand('php codecept build');
$I->seeInShellOutput('generated successfully');
$I->seeInSupportDir('CodeGuy.php');
$I->seeInSupportDir('CliGuy.php');
$I->seeInThisFile('class CliGuy extends \Codeception\Actor');
$I->seeInThisFile('use _generated\CliGuyActions');
$I->seeFileFound('CliGuyActions.php', 'tests/support/_generated');
$I->seeInThisFile('seeFileFound(');
$I->seeInThisFile('public function assertSame($expected, $actual, string $message = "") {');
}
public function usesTypehintsWherePossible(CliGuy $I, Scenario $scenario)
{
$I->wantToTest('generate typehints with generated actions');
$cliHelperContents = file_get_contents(codecept_root_dir('tests/support/CliHelper.php'));
$cliHelperContents = str_replace('public function grabFromOutput($regex)', 'public function grabFromOutput(string $regex): int', $cliHelperContents);
file_put_contents(codecept_root_dir('tests/support/CliHelper.php'), $cliHelperContents);
$I->runShellCommand('php codecept build');
$I->seeInShellOutput('generated successfully');
$I->seeInSupportDir('CliGuy.php');
$I->seeInThisFile('class CliGuy extends \Codeception\Actor');
$I->seeInThisFile('use _generated\CliGuyActions');
$I->seeFileFound('CliGuyActions.php', 'tests/support/_generated');
$I->seeInThisFile('public function grabFromOutput(string $regex): int');
}
public function generatedUnionReturnTypeOnPhp8(CliGuy $I, Scenario $scenario)
{
if (PHP_MAJOR_VERSION < 8) {
$scenario->skip('Does not work in PHP < 8');
}
$I->wantToTest('generate action with union return type');
$cliHelperContents = file_get_contents(codecept_root_dir('tests/support/CliHelper.php'));
$cliHelperContents = str_replace('public function grabFromOutput($regex)', 'public function grabFromOutput(array|string $param): int|string', $cliHelperContents);
file_put_contents(codecept_root_dir('tests/support/CliHelper.php'), $cliHelperContents);
$I->runShellCommand('php codecept build');
$I->seeInShellOutput('generated successfully');
$I->seeInSupportDir('CliGuy.php');
$I->seeInThisFile('class CliGuy extends \Codeception\Actor');
$I->seeInThisFile('use _generated\CliGuyActions');
$I->seeFileFound('CliGuyActions.php', 'tests/support/_generated');
$I->seeInThisFile('public function grabFromOutput(array|string $param): string|int');
}
public function noReturnForVoidType(CliGuy $I, Scenario $scenario)
{
$I->wantToTest('no return keyword generated for void typehint');
$cliHelperContents = file_get_contents(codecept_root_dir('tests/support/CliHelper.php'));
$cliHelperContents = str_replace('public function seeDirFound($dir)', 'public function seeDirFound($dir): void', $cliHelperContents);
file_put_contents(codecept_root_dir('tests/support/CliHelper.php'), $cliHelperContents);
$I->runShellCommand('php codecept build');
$I->seeInShellOutput('generated successfully');
$I->seeInSupportDir('CliGuy.php');
$I->seeInThisFile('class CliGuy extends \Codeception\Actor');
$I->seeInThisFile('use _generated\CliGuyActions');
$I->seeFileFound('CliGuyActions.php', 'tests/support/_generated');
$I->seeInThisFile('public function seeDirFound($dir): void');
}
public function generateNullableParameters(CliGuy $I, Scenario $scenario)
{
$cliHelperContents = file_get_contents(codecept_root_dir('tests/support/CliHelper.php'));
$cliHelperContents = str_replace('public function seeDirFound($dir)', 'public function seeDirFound(\Directory $dir = null): ?bool', $cliHelperContents);
file_put_contents(codecept_root_dir('tests/support/CliHelper.php'), $cliHelperContents);
$I->runShellCommand('php codecept build');
$I->seeInShellOutput('generated successfully');
$I->seeInSupportDir('CliGuy.php');
$I->seeInThisFile('class CliGuy extends \Codeception\Actor');
$I->seeInThisFile('use _generated\CliGuyActions');
$I->seeFileFound('CliGuyActions.php', 'tests/support/_generated');
$I->seeInThisFile('public function seeDirFound(?\Directory $dir = NULL): ?bool');
}
}