From ea31d9d38ce88792decfe309011fc4b498a036a8 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Mar 2014 01:34:43 +0100 Subject: [PATCH 1/4] Introduce abstract class for functional tests. --- tests/PhpseclibFunctionalTestCase.php | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/PhpseclibFunctionalTestCase.php 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; + } +} From dbcba5119826cdab5bc2204cbfd82c41e686d36d Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Mar 2014 02:10:01 +0100 Subject: [PATCH 2/4] Extract phpunit call to run-phpunit.sh --- .travis.yml | 2 +- travis/run-phpunit.sh | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100755 travis/run-phpunit.sh diff --git a/.travis.yml b/.travis.yml index 76fae1c7..aacbd919 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ before_script: 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/travis/run-phpunit.sh b/travis/run-phpunit.sh new file mode 100755 index 00000000..a448774a --- /dev/null +++ b/travis/run-phpunit.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e +set -x + +phpunit \ + --verbose \ + --coverage-text \ + --coverage-html code_coverage/ From 00c19f4cc1410c41d6364c643530cf57eaf12f9e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Mar 2014 01:43:58 +0100 Subject: [PATCH 3/4] Add basic SSH2 functional test as an example. --- .travis.yml | 1 + tests/Net/SSH2FunctionalTest.php | 35 ++++++++++++++++++++++++++++++++ travis/run-phpunit.sh | 4 ++++ travis/setup-secure-shell.sh | 17 ++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 tests/Net/SSH2FunctionalTest.php create mode 100755 travis/setup-secure-shell.sh diff --git a/.travis.yml b/.travis.yml index aacbd919..16cf99fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ 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" diff --git a/tests/Net/SSH2FunctionalTest.php b/tests/Net/SSH2FunctionalTest.php new file mode 100644 index 00000000..40bfeea3 --- /dev/null +++ b/tests/Net/SSH2FunctionalTest.php @@ -0,0 +1,35 @@ + + * @copyright MMXIV Andreas Fischer + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ + +class Net_SSH2FunctionalTest extends PhpseclibFunctionalTestCase +{ + 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/travis/run-phpunit.sh b/travis/run-phpunit.sh index a448774a..35b16aee 100755 --- a/travis/run-phpunit.sh +++ b/travis/run-phpunit.sh @@ -2,6 +2,10 @@ set -e set -x +export PHPSECLIB_SSH_HOSTNAME='localhost' +export PHPSECLIB_SSH_USERNAME='phpseclib' +export PHPSECLIB_SSH_PASSWORD='EePoov8po1aethu2kied1ne0' + phpunit \ --verbose \ --coverage-text \ 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 From 3d3d55b4078deef8688cc4dcb57b623206abc14e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 4 Mar 2014 14:56:42 +0100 Subject: [PATCH 4/4] Mark SSH2 Test as Incomplete on Travis PHP 5.3.3 and below for now. --- tests/Net/SSH2FunctionalTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Net/SSH2FunctionalTest.php b/tests/Net/SSH2FunctionalTest.php index 40bfeea3..34a9377b 100644 --- a/tests/Net/SSH2FunctionalTest.php +++ b/tests/Net/SSH2FunctionalTest.php @@ -8,6 +8,16 @@ 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'));