From ea31d9d38ce88792decfe309011fc4b498a036a8 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Mar 2014 01:34:43 +0100 Subject: [PATCH] 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; + } +}