Skip to content

Commit

Permalink
Merge ad0efd0 into d0606a1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronan Dowling committed Jan 21, 2017
2 parents d0606a1 + ad0efd0 commit 3d11be6
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 23 deletions.
70 changes: 70 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
build: false
shallow_clone: true
platform: 'x86'
clone_folder: C:\projects\terminus
branches:
only:
- master

## Cache composer bits
cache:
- '%LOCALAPPDATA%\Composer\files -> composer.lock'

init:
#https://github.com/composer/composer/blob/master/appveyor.yml
#- SET ANSICON=121x90 (121x90)

# Inspired by https://github.com/Codeception/base/blob/master/appveyor.yml and https://github.com/phpmd/phpmd/blob/master/appveyor.yml
install:
- cinst -y curl
- SET PATH=C:\Program Files\curl;%PATH%
#which is only needed by the test suite.
- cinst -y which
- SET PATH=C:\Program Files\which;%PATH%
- git clone -q https://github.com/acquia/DevDesktopCommon.git #For tar, cksum, ...
- SET PATH=%APPVEYOR_BUILD_FOLDER%/DevDesktopCommon/bintools-win/msys/bin;%PATH%
- SET PATH=C:\Program Files\MySql\MySQL Server 5.7\bin\;%PATH%
#Install PHP per https://blog.wyrihaximus.net/2016/11/running-php-unit-tests-on-windows-using-appveyor-and-chocolatey/
- ps: appveyor-retry cinst --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $Env:php_ver_target | Select-Object -first 1) -replace '[php|]','')
- cd c:\tools\php
- copy php.ini-production php.ini

- echo extension_dir=ext >> php.ini
- echo extension=php_openssl.dll >> php.ini
- echo date.timezone="UTC" >> php.ini
- echo variables_order="EGPCS" >> php.ini #May be unneeded.
- echo mbstring.http_input=pass >> php.ini
- echo mbstring.http_output=pass >> php.ini
- echo sendmail_path=nul >> php.ini
- echo extension=php_mbstring.dll >> php.ini
- echo extension=php_curl.dll >> php.ini
- echo extension=php_pdo_mysql.dll >> php.ini
- echo extension=php_pdo_pgsql.dll >> php.ini
- echo extension=php_pdo_sqlite.dll >> php.ini
- echo extension=php_pgsql.dll >> php.ini
- echo extension=php_gd2.dll >> php.ini
- SET PATH=C:\tools\php;%PATH%
#Install Composer
- cd %APPVEYOR_BUILD_FOLDER%
#- appveyor DownloadFile https://getcomposer.org/composer.phar
- php -r "readfile('http://getcomposer.org/installer');" | php
#Install Terminus' dependencies via Composer
- php composer.phar -q install --prefer-dist -n
- SET PATH=%APPVEYOR_BUILD_FOLDER%;%APPVEYOR_BUILD_FOLDER%/vendor/bin;%PATH%
#Create a sandbox for testing. Don't think we need this.
- mkdir c:\terminus_temp

services:
- mysql

test_script:
- php composer.phar clover
- php composer.phar cs

# environment variables
environment:
global:
TERMINUS_TEST_MODE: 1
COMPOSER_PROCESS_TIMEOUT: 3600
php_ver_target: 7.0

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"cbf": "phpcbf --standard=PSR2 -n tests/* bin/terminus src/*",
"clover": "phpunit -c tests/config/phpunit.xml.dist --coverage-clover tests/logs/clover.xml",
"coveralls": "coveralls -v -c tests/config/coveralls.xml",
"cs": "phpcs --standard=PSR2 --severity=1 -n tests/* bin/terminus src/*",
"cs": "phpcs --standard=PSR2 --severity=1 -n tests bin/terminus src",
"docs": "php scripts/make-docs.php",
"lint": "@cs",
"phpunit": "SHELL_INTERACTIVE=true phpunit --colors=always -c tests/config/phpunit.xml.dist --debug",
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Remote/SSHBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function ($type, $buffer) use ($output) {
$this->log()->notice('Command: {site}.{env} -- {command} [Exit: {exit}]', [
'site' => $this->site->get('name'),
'env' => $this->environment->id,
'command' => escapeshellarg($command_line),
'command' => ProcessUtils::escapeArgument($command_line),
'exit' => $exit,
]);

Expand Down
2 changes: 1 addition & 1 deletion src/Config/DefaultsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function getTerminusScript()
$debug = debug_backtrace();
$script_location = array_pop($debug);
$script_name = str_replace(
$this->getTerminusRoot() . '/',
$this->getTerminusRoot() . DIRECTORY_SEPARATOR,
'',
$script_location['file']
);
Expand Down
4 changes: 3 additions & 1 deletion src/Helpers/LocalMachineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function execInteractive($cmd, $callback = null)
{
$process = $this->getProcess($cmd);
// Set tty mode if the user is running terminus iteractively.
$process->setTty(posix_isatty(STDOUT));
if (function_exists('posix_isatty')) {
$process->setTty(posix_isatty(STDOUT));
}
$process->start();
$process->wait($callback);
return ['output' => $process->getOutput(), 'exit_code' => $process->getExitCode(),];
Expand Down
3 changes: 2 additions & 1 deletion src/Models/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Robo\Common\ConfigAwareTrait;
use Robo\Contract\ConfigAwareInterface;
use Pantheon\Terminus\Exceptions\TerminusException;
use Symfony\Component\Process\ProcessUtils;

/**
* Class Environment
Expand Down Expand Up @@ -733,7 +734,7 @@ public function sendCommandViaSsh($command, $callback = null)
$sftp = $this->sftpConnectionInfo();
$ssh_command = vsprintf(
'ssh -T %s@%s -p %s -o "AddressFamily inet" %s',
[$sftp['username'], $sftp['host'], $sftp['port'], escapeshellarg($command),]
[$sftp['username'], $sftp['host'], $sftp['port'], ProcessUtils::escapeArgument($command),]
);

// Catch Terminus running in test mode
Expand Down
16 changes: 13 additions & 3 deletions tests/unit_tests/Commands/Remote/SSHBaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Pantheon\Terminus\Exceptions\TerminusException;
use Pantheon\Terminus\Exceptions\TerminusProcessException;
use Pantheon\Terminus\UnitTests\Commands\CommandTestCase;
use Symfony\Component\Process\ProcessUtils;

/**
* SSHBaseCommand Test Suite
Expand Down Expand Up @@ -37,6 +38,11 @@ public function testExecuteCommand()
$command = 'dummy ' . implode(' ', $options);
$status_code = 0;

// For windows testing; wrap $command in the correct kind of quote
// characters. Presumes that nothing inside $command particularly
// needs escaping.
$expectedEscapedCommand = ProcessUtils::escapeArgument($command);

$this->environment->expects($this->once())
->method('get')
->with($this->equalTo('connection_mode'))
Expand All @@ -55,7 +61,7 @@ public function testExecuteCommand()
$this->equalTo([
'site' => $site_name,
'env' => $this->environment->id,
'command' => "'$command'",
'command' => "$expectedEscapedCommand",
'exit' => $status_code,
])
);
Expand All @@ -81,6 +87,8 @@ public function testExecuteCommandNonzeroStatus()
$this->environment->id = 'env_id';
$command = 'dummy ' . implode(' ', $options);

$expectedEscapedCommand = ProcessUtils::escapeArgument($command);

$this->environment->expects($this->once())
->method('get')
->with($this->equalTo('connection_mode'))
Expand All @@ -103,7 +111,7 @@ public function testExecuteCommandNonzeroStatus()
$this->equalTo([
'site' => $site_name,
'env' => $this->environment->id,
'command' => "'$command'",
'command' => "$expectedEscapedCommand",
'exit' => $status_code,
])
);
Expand All @@ -126,6 +134,8 @@ public function testExecuteCommandInGitMode()
$status_code = 0;
$command = 'dummy ' . implode(' ', $options);

$expectedEscapedCommand = ProcessUtils::escapeArgument($command);

$this->environment->expects($this->once())
->method('get')
->with($this->equalTo('connection_mode'))
Expand Down Expand Up @@ -153,7 +163,7 @@ public function testExecuteCommandInGitMode()
$this->equalTo([
'site' => $site_name,
'env' => $this->environment->id,
'command' => "'$command'",
'command' => "$expectedEscapedCommand",
'exit' => $status_code,
])
);
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/Config/TerminusConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ public function testGet()
$this->config->set('TERMINUS_SOME_VAR', 'abc');
$this->config->set('TERMINUS_ANOTHER_VAR', '[[ TERMINUS_SOME_VAR ]]/123');
$this->config->set('third_var', '[[ TERMINUS_ANOTHER_VAR ]]\321');
$this->assertEquals('abc/123', $this->config->get('another_var'));
$this->assertEquals('abc/123/321', $this->config->get('third_var'));
$this->assertEquals('abc' . DIRECTORY_SEPARATOR . '123', $this->config->get('another_var'));
$this->assertEquals('abc' . DIRECTORY_SEPARATOR . '123' . DIRECTORY_SEPARATOR . '321', $this->config->get('third_var'));
}

public function testKeys()
{
$this->config->fromArray(['foo' => 'bar', 'abc' => '123']);
$this->assertEquals(['foo', 'abc'], $this->config->keys());
}

public function testExtend()
{
$a = new TerminusConfig();
Expand Down
10 changes: 7 additions & 3 deletions tests/unit_tests/Models/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Pantheon\Terminus\Collections\Commits;
use Pantheon\Terminus\Models\Commit;
use Pantheon\Terminus\Exceptions\TerminusException;
use Symfony\Component\Process\ProcessUtils;

/**
* Class EnvironmentTest
Expand Down Expand Up @@ -818,20 +819,23 @@ public function testMergeToDev()

public function testSendCommandViaSsh()
{
$command = 'echo "Hello, World!"';
$expectedCommand = ProcessUtils::escapeArgument($command);

$expected = ['output' => 'Hello, World!', 'exit_code' => 0,];
$this->local_machine->expects($this->at(0))
->method('execInteractive')
->with('ssh -T dev.abc@appserver.dev.abc.drush.in -p 2222 -o "AddressFamily inet" \'echo "Hello, World!"\'')
->with('ssh -T dev.abc@appserver.dev.abc.drush.in -p 2222 -o "AddressFamily inet" ' . $expectedCommand)
->willReturn($expected);

$actual = $this->model->sendCommandViaSsh('echo "Hello, World!"');
$actual = $this->model->sendCommandViaSsh($command);
$this->assertEquals($expected, $actual);

$this->configSet(['test_mode' => 1]);
$expected = [
'output' => "Terminus is in test mode. "
. "Environment::sendCommandViaSsh commands will not be sent over the wire. "
. "SSH Command: ssh -T dev.abc@appserver.dev.abc.drush.in -p 2222 -o \"AddressFamily inet\" 'echo \"Hello, World!\"'",
. "SSH Command: ssh -T dev.abc@appserver.dev.abc.drush.in -p 2222 -o \"AddressFamily inet\" $expectedCommand",
'exit_code' => 0
];
$actual = $this->model->sendCommandViaSsh('echo "Hello, World!"');
Expand Down
4 changes: 4 additions & 0 deletions tests/unit_tests/Plugins/PluginDiscoveryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class PluginDiscoveryTest extends \PHPUnit_Framework_TestCase
{
public function testDiscover()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$this->markTestIncomplete("Plugins not supported on Windows yet.");
}

$plugins_dir = __DIR__ . '/../../fixtures/plugins/';

$paths = [
Expand Down
4 changes: 4 additions & 0 deletions tests/unit_tests/Plugins/PluginInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public function testCreatePluginInfo()

public function testLoadCommands()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$this->markTestIncomplete("Plugins not supported on Windows yet.");
}

$plugin = new PluginInfo($this->paths[2]);

$expected = [
Expand Down
28 changes: 19 additions & 9 deletions tests/unit_tests/Request/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class RequestTest extends \PHPUnit_Framework_TestCase
* @var Session
*/
protected $session;
/**
* @var string
*/
protected $user_agent;

/**
* @inheritdoc
Expand All @@ -75,13 +79,19 @@ public function setUp()
->disableOriginalConstructor()
->getMock();

$terminusVersion = '1.1.1';
$phpVersion = '7.0.0';
$script = 'foo/bar/baz.php';
$platformScript = str_replace('/', DIRECTORY_SEPARATOR, $script);
$this->user_agent = "Terminus/$terminusVersion (php_version=$phpVersion&script=$platformScript)";

$this->config = new TerminusConfig();
$this->config->set('host', 'example.com');
$this->config->set('protocol', 'https');
$this->config->set('port', '443');
$this->config->set('version', '1.1.1');
$this->config->set('script', 'foo/bar/baz.php');
$this->config->set('php_version', '7.0.0');
$this->config->set('version', $terminusVersion);
$this->config->set('script', $script);
$this->config->set('php_version', $phpVersion);

$this->container = $this->getMock(Container::class);
$this->session = $this->getMockBuilder(Session::class)
Expand Down Expand Up @@ -176,7 +186,7 @@ public function testRequest()
$headers = [
'foo' => 'bar',
'Content-type' => 'application/json',
'User-Agent' => 'Terminus/1.1.1 (php_version=7.0.0&script=foo/bar/baz.php)'
'User-Agent' => $this->user_agent,
];
$body = '';
$request_options = [$method, $uri, $headers, $body];
Expand All @@ -198,7 +208,7 @@ public function testRequestAuth()
$uri = 'https://example.com:443/api/foo/bar';
$headers = [
'Content-type' => 'application/json',
'User-Agent' => 'Terminus/1.1.1 (php_version=7.0.0&script=foo/bar/baz.php)',
'User-Agent' => $this->user_agent,
'Authorization' => 'Bearer abc123'
];
$body = '';
Expand All @@ -217,7 +227,7 @@ public function testRequestFullPath()
$uri = 'http://foo.bar/a/b/c';
$headers = [
'Content-type' => 'application/json',
'User-Agent' => 'Terminus/1.1.1 (php_version=7.0.0&script=foo/bar/baz.php)'
'User-Agent' => $this->user_agent,
];
$body = '';
$request_options = [$method, $uri, $headers, $body];
Expand All @@ -234,7 +244,7 @@ public function testRequestWithQuery()
$uri = 'https://example.com:443/api/foo/bar?foo=bar';
$headers = [
'Content-type' => 'application/json',
'User-Agent' => 'Terminus/1.1.1 (php_version=7.0.0&script=foo/bar/baz.php)'
'User-Agent' => $this->user_agent,
];
$body = '';
$request_options = [$method, $uri, $headers, $body];
Expand All @@ -259,7 +269,7 @@ public function testRequestNoVerify()
$uri = 'https://example.com:443/api/foo/bar';
$headers = [
'Content-type' => 'application/json',
'User-Agent' => 'Terminus/1.1.1 (php_version=7.0.0&script=foo/bar/baz.php)'
'User-Agent' => $this->user_agent,
];
$body = '';
$request_options = [$method, $uri, $headers, $body];
Expand All @@ -276,7 +286,7 @@ public function testPagedRequest()
$uri = 'https://example.com:443/api/foo/bar';
$headers = [
'Content-type' => 'application/json',
'User-Agent' => 'Terminus/1.1.1 (php_version=7.0.0&script=foo/bar/baz.php)',
'User-Agent' => $this->user_agent,
];
$body = '';
$request_options = [$method, $uri, $headers, $body];
Expand Down

0 comments on commit 3d11be6

Please sign in to comment.