Apply coding guidelines (with exceptions) to the tests directory.

This commit is contained in:
Andreas Fischer 2014-02-15 19:57:49 +01:00
parent 9cb25c3032
commit ef528ea879
16 changed files with 573 additions and 563 deletions

View File

@ -21,6 +21,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/
after_success:

View File

@ -0,0 +1,21 @@
<?xml version="1.0"?>
<ruleset name="phpseclib Test Standard">
<description>phpseclib coding standard for tests</description>
<!-- In general rules that apply to library code also apply to tests. -->
<rule ref="./code-sniffer-ruleset.xml">
<!-- Exceptions to the library coding standard follow. -->
<!-- We do not care too much about method, class and file documentation,
but having @author, @copyright and @license tags would be nice.
The following configuration does not check for these tags, but
complains if the file doc block is missing completely. -->
<exclude name="PEAR.Commenting.ClassComment" />
<exclude name="PEAR.Commenting.FunctionComment" />
<exclude name="PEAR.Commenting.FileComment.MissingTag" />
<exclude name="PEAR.Commenting.FileComment.MissingVersion" />
<exclude name="PEAR.Commenting.FileComment.SpacingBeforeTags" />
</rule>
</ruleset>

View File

@ -41,11 +41,13 @@ class Crypt_AES_ContinuousBufferTest extends Crypt_AES_TestCase
{
$result = array();
// @codingStandardsIgnoreStart
foreach ($this->modes as $mode)
foreach ($this->plaintexts as $plaintext)
foreach ($this->ivs as $iv)
foreach ($this->keys as $key)
$result[] = array($mode, $plaintext, $iv, $key);
// @codingStandardsIgnoreEnd
return $result;
}
@ -61,8 +63,7 @@ class Crypt_AES_ContinuousBufferTest extends Crypt_AES_TestCase
$aes->setKey($key);
$actual = '';
for ($i = 0, $strlen = strlen($plaintext); $i < $strlen; ++$i)
{
for ($i = 0, $strlen = strlen($plaintext); $i < $strlen; ++$i) {
$actual .= $aes->decrypt($aes->encrypt($plaintext[$i]));
}

View File

@ -5,23 +5,23 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
require_once 'Crypt/AES.php';
abstract class Crypt_AES_TestCase extends PhpseclibTestCase
{
static public function setUpBeforeClass()
{
require_once('Crypt/AES.php');
if (!defined('CRYPT_AES_MODE'))
{
if (!defined('CRYPT_AES_MODE')) {
define('CRYPT_AES_MODE', CRYPT_AES_MODE_INTERNAL);
}
}
public function setUp()
{
if (defined('CRYPT_AES_MODE') && CRYPT_AES_MODE !== CRYPT_AES_MODE_INTERNAL)
{
$this->markTestSkipped('Skipping test because CRYPT_AES_MODE is not defined as CRYPT_AES_MODE_INTERNAL.');
if (defined('CRYPT_AES_MODE') && CRYPT_AES_MODE !== CRYPT_AES_MODE_INTERNAL) {
$this->markTestSkipped(
'Skipping test because CRYPT_AES_MODE is not defined as CRYPT_AES_MODE_INTERNAL.'
);
}
}
}

View File

@ -5,23 +5,23 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
require_once 'Crypt/Hash.php';
abstract class Crypt_Hash_TestCase extends PhpseclibTestCase
{
static public function setUpBeforeClass()
{
require_once('Crypt/Hash.php');
if (!defined('CRYPT_HASH_MODE'))
{
if (!defined('CRYPT_HASH_MODE')) {
define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_INTERNAL);
}
}
public function setUp()
{
if (defined('CRYPT_HASH_MODE') && CRYPT_HASH_MODE !== CRYPT_HASH_MODE_INTERNAL)
{
$this->markTestSkipped('Skipping test because CRYPT_HASH_MODE is not defined as CRYPT_HASH_MODE_INTERNAL.');
if (defined('CRYPT_HASH_MODE') && CRYPT_HASH_MODE !== CRYPT_HASH_MODE_INTERNAL) {
$this->markTestSkipped(
'Skipping test because CRYPT_HASH_MODE is not defined as CRYPT_HASH_MODE_INTERNAL.'
);
}
}
@ -41,7 +41,12 @@ abstract class Crypt_Hash_TestCase extends PhpseclibTestCase
$this->assertEquals(
strtolower($expected),
bin2hex($hash->hash($message)),
sprintf("Failed asserting that '%s' HMACs to '%s' with key '%s'.", $message, $expected, $key)
sprintf(
"Failed asserting that '%s' HMACs to '%s' with key '%s'.",
$message,
$expected,
$key
)
);
}
}

View File

@ -5,13 +5,10 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
require_once 'Crypt/RSA.php' ;
class Crypt_RSA_LoadKeyTest extends PhpseclibTestCase
{
static public function setUpBeforeClass()
{
require_once('Crypt/RSA.php');
}
public function testBadKey()
{
$rsa = new Crypt_RSA();

View File

@ -9,8 +9,7 @@ class Math_BigInteger_BCMathTest extends Math_BigInteger_TestCase
{
static public function setUpBeforeClass()
{
if (!extension_loaded('bcmath'))
{
if (!extension_loaded('bcmath')) {
self::markTestSkipped('BCMath extension is not available.');
}

View File

@ -9,8 +9,7 @@ class Math_BigInteger_GMPTest extends Math_BigInteger_TestCase
{
static public function setUpBeforeClass()
{
if (!extension_loaded('gmp'))
{
if (!extension_loaded('gmp')) {
self::markTestSkipped('GNU Multiple Precision (GMP) extension is not available.');
}

View File

@ -9,8 +9,7 @@ class Math_BigInteger_InternalOpenSSLTest extends Math_BigInteger_TestCase
{
static public function setUpBeforeClass()
{
if (!function_exists('openssl_public_encrypt'))
{
if (!function_exists('openssl_public_encrypt')) {
self::markTestSkipped('openssl_public_encrypt() function is not available.');
}

View File

@ -8,17 +8,6 @@
class Net_SSH2Test extends PhpseclibTestCase
{
/**
* @return Net_SSH2
*/
private function createSSHMock()
{
return $this->getMockBuilder('Net_SSH2')
->disableOriginalConstructor()
->setMethods(array('__destruct'))
->getMock();
}
public function formatLogDataProvider()
{
return array(
@ -65,12 +54,12 @@ class Net_SSH2Test extends PhpseclibTestCase
public function testGenerateIdentifier($expected, array $requiredExtensions)
{
$notAllowed = array('gmp', 'bcmath', 'mcrypt', 'gmp');
foreach($notAllowed as $notAllowedExtension) {
if(in_array($notAllowedExtension, $requiredExtensions)) {
foreach ($notAllowed as $notAllowedExtension) {
if (in_array($notAllowedExtension, $requiredExtensions)) {
continue;
}
if(extension_loaded($notAllowedExtension)) {
if (extension_loaded($notAllowedExtension)) {
$this->markTestSkipped('Extension ' . $notAllowedExtension . ' is not allowed for this data-set');
}
}
@ -81,4 +70,14 @@ class Net_SSH2Test extends PhpseclibTestCase
$this->assertEquals($expected, $identifier);
}
/**
* @return Net_SSH2
*/
protected function createSSHMock()
{
return $this->getMockBuilder('Net_SSH2')
->disableOriginalConstructor()
->setMethods(array('__destruct'))
->getMock();
}
}

View File

@ -15,25 +15,19 @@ abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
*/
static protected function ensureConstant($constant, $expected)
{
if (defined($constant))
{
if (defined($constant)) {
$value = constant($constant);
if ($value !== $expected)
{
if (function_exists('runkit_constant_redefine'))
{
if (!runkit_constant_redefine($constant, $expected))
{
if ($value !== $expected) {
if (function_exists('runkit_constant_redefine')) {
if (!runkit_constant_redefine($constant, $expected)) {
self::markTestSkipped(sprintf(
"Failed to redefine constant %s to %s",
$constant,
$expected
));
}
}
else
{
} else {
self::markTestSkipped(sprintf(
"Skipping test because constant %s is %s instead of %s",
$constant,
@ -42,9 +36,7 @@ abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
));
}
}
}
else
{
} else {
define($constant, $expected);
}
}
@ -56,8 +48,7 @@ abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
*/
static protected function reRequireFile($filename)
{
if (function_exists('runkit_import'))
{
if (function_exists('runkit_import')) {
$result = runkit_import(
$filename,
RUNKIT_IMPORT_FUNCTIONS |
@ -65,8 +56,7 @@ abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
RUNKIT_IMPORT_OVERRIDE
);
if (!$result)
{
if (!$result) {
self::markTestSkipped("Failed to reimport file $filename");
}
}

View File

@ -17,13 +17,11 @@ set_include_path(implode(PATH_SEPARATOR, array(
function phpseclib_is_includable($suffix)
{
foreach (explode(PATH_SEPARATOR, get_include_path()) as $prefix)
{
foreach (explode(PATH_SEPARATOR, get_include_path()) as $prefix) {
$ds = substr($prefix, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR;
$file = $prefix . $ds . $suffix;
if (file_exists($file))
{
if (file_exists($file)) {
return true;
}
}
@ -35,9 +33,10 @@ function phpseclib_autoload($class)
{
$file = str_replace('_', '/', $class) . '.php';
if (phpseclib_is_includable($file))
{
if (phpseclib_is_includable($file)) {
// @codingStandardsIgnoreStart
require $file;
// @codingStandardsIgnoreEnd
}
}