1111
1212trait CommandLine {
1313 /** @var int return code of last command */
14- private $ lastCode ;
14+ private int $ lastCode = 0 ;
1515 /** @var string stdout of last command */
16- private $ lastStdOut ;
16+ private string $ lastStdOut = '' ;
1717 /** @var string stderr of last command */
18- private $ lastStdErr ;
19-
20- /** @var string */
21- protected $ ocPath = '../.. ' ;
18+ private string $ lastStdErr = '' ;
19+ protected string $ ocPath = '../.. ' ;
2220
2321 /**
2422 * Invokes an OCC command
2523 *
26- * @param []string $args OCC command, the part behind "occ". For example: "files:transfer-ownership"
24+ * @param string[] $args OCC command, the part behind "occ". For example: "files:transfer-ownership"
2725 * @return int exit code
2826 */
29- public function runOcc ($ args = [], string $ inputString = '' ) {
27+ public function runOcc (array $ args = [], string $ inputString = '' ): int {
3028 $ args = array_map (function ($ arg ) {
3129 return escapeshellarg ($ arg );
3230 }, $ args );
@@ -57,23 +55,23 @@ public function runOcc($args = [], string $inputString = '') {
5755 /**
5856 * @Given /^invoking occ with "([^"]*)"$/
5957 */
60- public function invokingTheCommand ($ cmd ) {
58+ public function invokingTheCommand (string $ cmd ): void {
6159 $ args = explode (' ' , $ cmd );
6260 $ this ->runOcc ($ args );
6361 }
6462
6563 /**
6664 * @Given /^invoking occ with "([^"]*)" with input "([^"]+)"$/
6765 */
68- public function invokingTheCommandWith ($ cmd , $ inputString ) {
66+ public function invokingTheCommandWith (string $ cmd , string $ inputString ): void {
6967 $ args = explode (' ' , $ cmd );
7068 $ this ->runOcc ($ args , $ inputString );
7169 }
7270
7371 /**
7472 * Find exception texts in stderr
7573 */
76- public function findExceptions () {
74+ public function findExceptions (): array {
7775 $ exceptions = [];
7876 $ captureNext = false ;
7977 // the exception text usually appears after an "[Exception"] row
@@ -94,7 +92,7 @@ public function findExceptions() {
9492 /**
9593 * @Then /^the command was successful$/
9694 */
97- public function theCommandWasSuccessful () {
95+ public function theCommandWasSuccessful (): void {
9896 $ exceptions = $ this ->findExceptions ();
9997 if ($ this ->lastCode !== 0 ) {
10098 $ msg = 'The command was not successful, exit code was ' . $ this ->lastCode . '. ' ;
@@ -111,7 +109,7 @@ public function theCommandWasSuccessful() {
111109 /**
112110 * @Then /^the command failed with exit code ([0-9]+)$/
113111 */
114- public function theCommandFailedWithExitCode ($ exitCode ) {
112+ public function theCommandFailedWithExitCode ($ exitCode ): void {
115113 if ($ this ->lastCode !== (int )$ exitCode ) {
116114 throw new \Exception ('The command was expected to fail with exit code ' . $ exitCode . ' but got ' . $ this ->lastCode );
117115 }
@@ -120,7 +118,7 @@ public function theCommandFailedWithExitCode($exitCode) {
120118 /**
121119 * @Then /^the command failed with exception text "([^"]*)"$/
122120 */
123- public function theCommandFailedWithException ($ exceptionText ) {
121+ public function theCommandFailedWithException (string $ exceptionText ): void {
124122 $ exceptions = $ this ->findExceptions ();
125123 if (empty ($ exceptions )) {
126124 throw new \Exception ('The command did not throw any exceptions ' );
@@ -134,21 +132,21 @@ public function theCommandFailedWithException($exceptionText) {
134132 /**
135133 * @Then /^the command output contains the text "([^"]*)"$/
136134 */
137- public function theCommandOutputContainsTheText ($ text ) {
138- Assert::assertStringContainsString ($ text , $ this ->lastStdOut , 'The command did not output the expected text on stdout ' );
135+ public function theCommandOutputContainsTheText (string $ text ): void {
136+ Assert::assertStringContainsString ($ text , $ this ->lastStdOut , 'The command did not output the expected text on stdout. ' );
139137 }
140138
141139 /**
142140 * @Then /^the command output does not contain the text "([^"]*)"$/
143141 */
144- public function theCommandOutputDoesNotContainTheText ($ text ) {
145- Assert::assertStringNotContainsString ($ text , $ this ->lastStdOut , 'The command did output the not expected text on stdout ' );
142+ public function theCommandOutputDoesNotContainTheText (string $ text ): void {
143+ Assert::assertStringNotContainsString ($ text , $ this ->lastStdOut , 'The command did output the not expected text on stdout. ' );
146144 }
147145
148146 /**
149147 * @Then /^the command error output contains the text "([^"]*)"$/
150148 */
151- public function theCommandErrorOutputContainsTheText ($ text ) {
152- Assert::assertStringContainsString ($ text , $ this ->lastStdErr , 'The command did not output the expected text on stderr ' );
149+ public function theCommandErrorOutputContainsTheText (string $ text ): void {
150+ Assert::assertStringContainsString ($ text , $ this ->lastStdErr , 'The command did not output the expected text on stderr. ' );
153151 }
154152}
0 commit comments