-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathWhenStepDefinitions.php
More file actions
64 lines (51 loc) · 1.88 KB
/
WhenStepDefinitions.php
File metadata and controls
64 lines (51 loc) · 1.88 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
<?php
namespace WP_CLI\Tests\Context;
use WP_CLI\Process;
use Exception;
trait WhenStepDefinitions {
public function wpcli_tests_invoke_proc( $proc, $mode ) {
$map = array(
'run' => 'run_check_stderr',
'try' => 'run',
);
$method = $map[ $mode ];
return $proc->$method();
}
public function wpcli_tests_capture_email_sends( $stdout ) {
$stdout = preg_replace( '#WP-CLI test suite: Sent email to.+\n?#', '', $stdout, -1, $email_sends );
return array( $stdout, $email_sends );
}
/**
* @When /^I launch in the background `([^`]+)`$/
*/
public function when_i_launch_in_the_background( $cmd ) {
$this->background_proc( $cmd );
}
/**
* @When /^I (run|try) `([^`]+)`$/
*/
public function when_i_run( $mode, $cmd ) {
$cmd = $this->replace_variables( $cmd );
$this->result = $this->wpcli_tests_invoke_proc( $this->proc( $cmd ), $mode );
list( $this->result->stdout, $this->email_sends ) = $this->wpcli_tests_capture_email_sends( $this->result->stdout );
}
/**
* @When /^I (run|try) `([^`]+)` from '([^\s]+)'$/
*/
public function when_i_run_from_a_subfolder( $mode, $cmd, $subdir ) {
$cmd = $this->replace_variables( $cmd );
$this->result = $this->wpcli_tests_invoke_proc( $this->proc( $cmd, array(), $subdir ), $mode );
list( $this->result->stdout, $this->email_sends ) = $this->wpcli_tests_capture_email_sends( $this->result->stdout );
}
/**
* @When /^I (run|try) the previous command again$/
*/
public function when_i_run_the_previous_command_again( $mode ) {
if ( ! isset( $this->result ) ) {
throw new Exception( 'No previous command.' );
}
$proc = Process::create( $this->result->command, $this->result->cwd, $this->result->env );
$this->result = $this->wpcli_tests_invoke_proc( $proc, $mode );
list( $this->result->stdout, $this->email_sends ) = $this->wpcli_tests_capture_email_sends( $this->result->stdout );
}
}