diff --git a/.travis.yml b/.travis.yml index 76fae1c7..16cf99fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,13 +16,14 @@ env: - secure: "jtQTZKQBnzUlp/jz7NlM6470ZDnLGVAs53sgvIm4tcYqf9TWSXSXjIYvFsrS\nKPR2eyZaAevYysUkIGRFTUXTlG6tC36YngMp9+6FPxASl8mnGXsTbKcm613B\n59vD3242pgIgqhhmgFQ0c8gbvnE8PuF2aS4/hluP3r+AxhWN56E=" before_script: + - travis/setup-secure-shell.sh - sh -c "if [ '$TRAVIS_PHP_VERSION' != 'hhvm' ]; then travis/install-php-extensions.sh; fi" - sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.5' ]; then composer install --dev --no-interaction; fi" script: - sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.5' ]; then vendor/bin/phpcs -s --extensions=php --standard=build/code-sniffer-ruleset.xml phpseclib/; fi" - sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.5' ]; then vendor/bin/phpcs -s --extensions=php --standard=build/code-sniffer-ruleset-tests.xml tests/; fi" - - phpunit --verbose --coverage-text --coverage-html code_coverage/ + - travis/run-phpunit.sh after_success: - sh -c "if $TRAVIS_SECURE_ENV_VARS; then travis/upload-code-coverage.sh; fi" diff --git a/tests/Net/SSH2FunctionalTest.php b/tests/Net/SSH2FunctionalTest.php new file mode 100644 index 00000000..34a9377b --- /dev/null +++ b/tests/Net/SSH2FunctionalTest.php @@ -0,0 +1,45 @@ + + * @copyright MMXIV Andreas Fischer + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ + +class Net_SSH2FunctionalTest extends PhpseclibFunctionalTestCase +{ + public function setUp() + { + if (getenv('TRAVIS') && version_compare(PHP_VERSION, '5.3.3', '<=')) { + $this->markTestIncomplete( + 'This test hangs on Travis CI on PHP 5.3.3 and below.' + ); + } + parent::setUp(); + } + + public function testConstructor() + { + $ssh = new Net_SSH2($this->getEnv('SSH_HOSTNAME')); + + $this->assertTrue( + is_object($ssh), + 'Could not construct NET_SSH2 object.' + ); + + return $ssh; + } + + /** + * @depends testConstructor + */ + public function testPasswordLogin($ssh) + { + $username = $this->getEnv('SSH_USERNAME'); + $password = $this->getEnv('SSH_PASSWORD'); + $this->assertTrue( + $ssh->login($username, $password), + 'SSH2 login using password failed.' + ); + } +} diff --git a/tests/PhpseclibFunctionalTestCase.php b/tests/PhpseclibFunctionalTestCase.php new file mode 100644 index 00000000..42fd80f5 --- /dev/null +++ b/tests/PhpseclibFunctionalTestCase.php @@ -0,0 +1,47 @@ + + * @copyright MMXIV Andreas Fischer + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ + +abstract class PhpseclibFunctionalTestCase extends PhpseclibTestCase +{ + /** + * @param string $variable + * @param string|null $message + * + * @return null + */ + protected function requireEnv($variable, $message = null) + { + if ($this->_getEnv($variable) === false) { + $msg = $message ? $message : sprintf( + "This test requires the '%s' environment variable.", + $this->_prefixEnvVariable($variable) + ); + $this->markTestSkipped($msg); + } + } + + /** + * @param string $variable + * + * @return string + */ + protected function getEnv($variable) + { + $this->requireEnv($variable); + return $this->_getEnv($variable); + } + + private function _getEnv($variable) + { + return getenv($this->_prefixEnvVariable($variable)); + } + + private function _prefixEnvVariable($variable) + { + return 'PHPSECLIB_' . $variable; + } +} diff --git a/travis/run-phpunit.sh b/travis/run-phpunit.sh new file mode 100755 index 00000000..35b16aee --- /dev/null +++ b/travis/run-phpunit.sh @@ -0,0 +1,12 @@ +#!/bin/sh +set -e +set -x + +export PHPSECLIB_SSH_HOSTNAME='localhost' +export PHPSECLIB_SSH_USERNAME='phpseclib' +export PHPSECLIB_SSH_PASSWORD='EePoov8po1aethu2kied1ne0' + +phpunit \ + --verbose \ + --coverage-text \ + --coverage-html code_coverage/ diff --git a/travis/setup-secure-shell.sh b/travis/setup-secure-shell.sh new file mode 100755 index 00000000..ad8d3504 --- /dev/null +++ b/travis/setup-secure-shell.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# +# This file is part of the phpseclib project. +# +# (c) Andreas Fischer +# +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. +# +set -e +set -x + +USERNAME='phpseclib' +PASSWORD='EePoov8po1aethu2kied1ne0' + +sudo useradd "$USERNAME" +echo "$USERNAME:$PASSWORD" | sudo chpasswd