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

getWpCli() public method

We use a custom WP-CLI PHAR (latest stable). The local custom binary is re-downloaded every day to keep it fresh (stable WP-CLI releases go out every couple of months).
public getWpCli ( ) : string
return string The path to the custom WP-CLI PHAR.
    public function getWpCli()
    {
        $wpCliName = "wp-cli-{$this->wpCliVersion}.phar";
        $wpCliPath = sys_get_temp_dir() . '/' . $wpCliName;
        $wpCliTmpPath = $wpCliPath . '.tmp';
        if (!file_exists($wpCliPath) || $this->wpCliVersion === "latest-stable" && $this->fileIsOlderThanDays($wpCliPath, 1)) {
            $pharResource = @fopen($this->getWpCliDownloadUrl(), 'r');
            if (!$pharResource) {
                return $wpCliPath;
                // we're probably offline or there was some kind of network error
            }
            file_put_contents($wpCliTmpPath, $pharResource);
            if ($this->wpCliVersion === "latest-stable" && !$this->checkLatestStableChecksum($wpCliTmpPath)) {
                trigger_error("Wrong checksum of WP-CLI PHAR", E_USER_NOTICE);
            } else {
                rename($wpCliTmpPath, $wpCliPath);
            }
        }
        return $wpCliPath;
    }