VersionPress\Tests\Automation\WpAutomation::runWpCliCommand PHP Method

runWpCliCommand() public method

Executes a WP-CLI command http://wp-Cli.org/commands/
public runWpCliCommand ( string $command, string $subcommand, array $args = [], boolean $debug = false ) : string
$command string Like "core"
$subcommand string Like "config". Might be null, e.g. if the main command is "eval" there is no subcommand
$args array Like array("dbname" => "wordpress", "dbuser" => "wpuser", "positionalargument") which will produce something like `--dbname='wordpress' --dbuser='wpuser' 'positionalargument'`
$debug boolean
return string
    public function runWpCliCommand($command, $subcommand, $args = [], $debug = false)
    {
        $cliCommand = "wp {$command}";
        if ($subcommand) {
            $cliCommand .= " {$subcommand}";
        }
        foreach ((array) $args as $name => $value) {
            if (is_int($name)) {
                // positional argument
                $cliCommand .= " " . ProcessUtils::escapeshellarg($value, null);
            } elseif ($value !== null) {
                $escapedValue = ProcessUtils::escapeshellarg($value, null);
                $cliCommand .= " --{$name}={$escapedValue}";
            } else {
                $cliCommand .= " --{$name}";
            }
        }
        return $this->exec($cliCommand, null, $debug);
    }

Usage Example

 /**
  * @test
  */
 public function runAutomation()
 {
     $testConfig = TestConfig::createDefaultConfig();
     $wpAutomation = new WpAutomation($testConfig->testSite, $testConfig->wpCliVersion);
     $wpAutomation->setUpSite();
     $wpAutomation->copyVersionPressFiles();
     $wpAutomation->activateVersionPress();
     $wpAutomation->runWpCliCommand('vp', 'config', ['VP_PROJECT_ROOT', '.']);
 }
All Usage Examples Of VersionPress\Tests\Automation\WpAutomation::runWpCliCommand