diff --git a/.travis.yml b/.travis.yml index 9f4ca74c..18d8cbea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,9 @@ php: - 5.3 - 5.4 +before_script: + - git clone git://github.com/zenovich/runkit.git && cd runkit && phpize && ./configure && make && make install && cd .. + - echo "extension=runkit.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` + script: - phpunit --verbose diff --git a/tests/Crypt/AES/TestCase.php b/tests/Crypt/AES/TestCase.php index d5884129..f845e4bb 100644 --- a/tests/Crypt/AES/TestCase.php +++ b/tests/Crypt/AES/TestCase.php @@ -5,7 +5,7 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -abstract class Crypt_AES_TestCase extends PHPUnit_Framework_TestCase +abstract class Crypt_AES_TestCase extends PhpseclibTestCase { static public function setUpBeforeClass() { diff --git a/tests/Crypt/Hash/TestCase.php b/tests/Crypt/Hash/TestCase.php index 1489acd7..5f61244c 100644 --- a/tests/Crypt/Hash/TestCase.php +++ b/tests/Crypt/Hash/TestCase.php @@ -5,7 +5,7 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -abstract class Crypt_Hash_TestCase extends PHPUnit_Framework_TestCase +abstract class Crypt_Hash_TestCase extends PhpseclibTestCase { static public function setUpBeforeClass() { diff --git a/tests/Math/BigInteger/BCMathTest.php b/tests/Math/BigInteger/BCMathTest.php new file mode 100644 index 00000000..08d4b3fe --- /dev/null +++ b/tests/Math/BigInteger/BCMathTest.php @@ -0,0 +1,21 @@ + + * @copyright MMXIII Andreas Fischer + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ + +class Math_BigInteger_BCMathTest extends Math_BigInteger_TestCase +{ + static public function setUpBeforeClass() + { + if (!extension_loaded('bcmath')) + { + self::markTestSkipped('BCMath extension is not available.'); + } + + parent::setUpBeforeClass(); + + self::ensureModeConstant('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_BCMATH); + } +} diff --git a/tests/Math/BigInteger/GMPTest.php b/tests/Math/BigInteger/GMPTest.php new file mode 100644 index 00000000..fcd898d1 --- /dev/null +++ b/tests/Math/BigInteger/GMPTest.php @@ -0,0 +1,21 @@ + + * @copyright MMXIII Andreas Fischer + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ + +class Math_BigInteger_GMPTest extends Math_BigInteger_TestCase +{ + static public function setUpBeforeClass() + { + if (!extension_loaded('gmp')) + { + self::markTestSkipped('GNU Multiple Precision (GMP) extension is not available.'); + } + + parent::setUpBeforeClass(); + + self::ensureModeConstant('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_GMP); + } +} diff --git a/tests/Math/BigInteger/InternalTest.php b/tests/Math/BigInteger/InternalTest.php new file mode 100644 index 00000000..1ca2ef74 --- /dev/null +++ b/tests/Math/BigInteger/InternalTest.php @@ -0,0 +1,16 @@ + + * @copyright MMXIII Andreas Fischer + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ + +class Math_BigInteger_InternalTest extends Math_BigInteger_TestCase +{ + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::ensureModeConstant('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_INTERNAL); + } +} diff --git a/tests/Math/BigIntegerTest.php b/tests/Math/BigInteger/TestCase.php similarity index 96% rename from tests/Math/BigIntegerTest.php rename to tests/Math/BigInteger/TestCase.php index 1317609f..01edc475 100644 --- a/tests/Math/BigIntegerTest.php +++ b/tests/Math/BigInteger/TestCase.php @@ -5,8 +5,17 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -class Math_BigIntegerTest extends PHPUnit_Framework_TestCase +require_once 'Math/BigInteger.php'; + +abstract class Math_BigInteger_TestCase extends PhpseclibTestCase { + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::reRequireFile('Math/BigInteger.php'); + } + public function getInstance($x = 0, $base = 10) { return new Math_BigInteger($x, $base); diff --git a/tests/PhpseclibTestCase.php b/tests/PhpseclibTestCase.php new file mode 100644 index 00000000..e69aa25a --- /dev/null +++ b/tests/PhpseclibTestCase.php @@ -0,0 +1,74 @@ + + * @copyright MMXIII Andreas Fischer + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ + +abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase +{ + /** + * @param string $constant + * @param mixed $expected + * + * @return null + */ + static protected function ensureModeConstant($constant, $expected) + { + if (defined($constant)) + { + $value = constant($constant); + + if ($value !== $expected) + { + if (function_exists('runkit_constant_redefine')) + { + if (!runkit_constant_redefine($constant, $expected)) + { + self::markTestSkipped(sprintf( + "Failed to redefine mode constant %s to %s", + $constant, + $expected + )); + } + } + else + { + self::markTestSkipped(sprintf( + "Skipping test because mode constant %s is %s instead of %s", + $constant, + $value, + $expected + )); + } + } + } + else + { + define($constant, $expected); + } + } + + /** + * @param string $filename + * + * @return null + */ + static protected function reRequireFile($filename) + { + if (function_exists('runkit_import')) + { + $result = runkit_import( + $filename, + RUNKIT_IMPORT_FUNCTIONS | + RUNKIT_IMPORT_CLASS_METHODS | + RUNKIT_IMPORT_OVERRIDE + ); + + if (!$result) + { + self::markTestSkipped("Failed to reimport file $filename"); + } + } + } +}