mirror of
https://github.com/danog/tgseclib.git
synced 2024-12-04 02:27:52 +01:00
Apply coding guidelines (with exceptions) to the tests directory.
This commit is contained in:
parent
9cb25c3032
commit
ef528ea879
@ -21,6 +21,7 @@ before_script:
|
|||||||
|
|
||||||
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.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/
|
- phpunit --verbose --coverage-text --coverage-html code_coverage/
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
|
21
build/code-sniffer-ruleset-tests.xml
Normal file
21
build/code-sniffer-ruleset-tests.xml
Normal 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>
|
@ -41,11 +41,13 @@ class Crypt_AES_ContinuousBufferTest extends Crypt_AES_TestCase
|
|||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
|
// @codingStandardsIgnoreStart
|
||||||
foreach ($this->modes as $mode)
|
foreach ($this->modes as $mode)
|
||||||
foreach ($this->plaintexts as $plaintext)
|
foreach ($this->plaintexts as $plaintext)
|
||||||
foreach ($this->ivs as $iv)
|
foreach ($this->ivs as $iv)
|
||||||
foreach ($this->keys as $key)
|
foreach ($this->keys as $key)
|
||||||
$result[] = array($mode, $plaintext, $iv, $key);
|
$result[] = array($mode, $plaintext, $iv, $key);
|
||||||
|
// @codingStandardsIgnoreEnd
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@ -61,8 +63,7 @@ class Crypt_AES_ContinuousBufferTest extends Crypt_AES_TestCase
|
|||||||
$aes->setKey($key);
|
$aes->setKey($key);
|
||||||
|
|
||||||
$actual = '';
|
$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]));
|
$actual .= $aes->decrypt($aes->encrypt($plaintext[$i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,23 +5,23 @@
|
|||||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require_once 'Crypt/AES.php';
|
||||||
|
|
||||||
abstract class Crypt_AES_TestCase extends PhpseclibTestCase
|
abstract class Crypt_AES_TestCase extends PhpseclibTestCase
|
||||||
{
|
{
|
||||||
static public function setUpBeforeClass()
|
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);
|
define('CRYPT_AES_MODE', CRYPT_AES_MODE_INTERNAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
if (defined('CRYPT_AES_MODE') && CRYPT_AES_MODE !== CRYPT_AES_MODE_INTERNAL)
|
if (defined('CRYPT_AES_MODE') && CRYPT_AES_MODE !== CRYPT_AES_MODE_INTERNAL) {
|
||||||
{
|
$this->markTestSkipped(
|
||||||
$this->markTestSkipped('Skipping test because CRYPT_AES_MODE is not defined as CRYPT_AES_MODE_INTERNAL.');
|
'Skipping test because CRYPT_AES_MODE is not defined as CRYPT_AES_MODE_INTERNAL.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,23 +5,23 @@
|
|||||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require_once 'Crypt/Hash.php';
|
||||||
|
|
||||||
abstract class Crypt_Hash_TestCase extends PhpseclibTestCase
|
abstract class Crypt_Hash_TestCase extends PhpseclibTestCase
|
||||||
{
|
{
|
||||||
static public function setUpBeforeClass()
|
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);
|
define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_INTERNAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
if (defined('CRYPT_HASH_MODE') && CRYPT_HASH_MODE !== CRYPT_HASH_MODE_INTERNAL)
|
if (defined('CRYPT_HASH_MODE') && CRYPT_HASH_MODE !== CRYPT_HASH_MODE_INTERNAL) {
|
||||||
{
|
$this->markTestSkipped(
|
||||||
$this->markTestSkipped('Skipping test because CRYPT_HASH_MODE is not defined as CRYPT_HASH_MODE_INTERNAL.');
|
'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(
|
$this->assertEquals(
|
||||||
strtolower($expected),
|
strtolower($expected),
|
||||||
bin2hex($hash->hash($message)),
|
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
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,10 @@
|
|||||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
require_once 'Crypt/RSA.php' ;
|
||||||
|
|
||||||
class Crypt_RSA_LoadKeyTest extends PhpseclibTestCase
|
class Crypt_RSA_LoadKeyTest extends PhpseclibTestCase
|
||||||
{
|
{
|
||||||
static public function setUpBeforeClass()
|
|
||||||
{
|
|
||||||
require_once('Crypt/RSA.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testBadKey()
|
public function testBadKey()
|
||||||
{
|
{
|
||||||
$rsa = new Crypt_RSA();
|
$rsa = new Crypt_RSA();
|
||||||
|
@ -9,8 +9,7 @@ class Math_BigInteger_BCMathTest extends Math_BigInteger_TestCase
|
|||||||
{
|
{
|
||||||
static public function setUpBeforeClass()
|
static public function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
if (!extension_loaded('bcmath'))
|
if (!extension_loaded('bcmath')) {
|
||||||
{
|
|
||||||
self::markTestSkipped('BCMath extension is not available.');
|
self::markTestSkipped('BCMath extension is not available.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,7 @@ class Math_BigInteger_GMPTest extends Math_BigInteger_TestCase
|
|||||||
{
|
{
|
||||||
static public function setUpBeforeClass()
|
static public function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
if (!extension_loaded('gmp'))
|
if (!extension_loaded('gmp')) {
|
||||||
{
|
|
||||||
self::markTestSkipped('GNU Multiple Precision (GMP) extension is not available.');
|
self::markTestSkipped('GNU Multiple Precision (GMP) extension is not available.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,7 @@ class Math_BigInteger_InternalOpenSSLTest extends Math_BigInteger_TestCase
|
|||||||
{
|
{
|
||||||
static public function setUpBeforeClass()
|
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.');
|
self::markTestSkipped('openssl_public_encrypt() function is not available.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,17 +8,6 @@
|
|||||||
|
|
||||||
class Net_SSH2Test extends PhpseclibTestCase
|
class Net_SSH2Test extends PhpseclibTestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @return Net_SSH2
|
|
||||||
*/
|
|
||||||
private function createSSHMock()
|
|
||||||
{
|
|
||||||
return $this->getMockBuilder('Net_SSH2')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->setMethods(array('__destruct'))
|
|
||||||
->getMock();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function formatLogDataProvider()
|
public function formatLogDataProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
@ -81,4 +70,14 @@ class Net_SSH2Test extends PhpseclibTestCase
|
|||||||
$this->assertEquals($expected, $identifier);
|
$this->assertEquals($expected, $identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Net_SSH2
|
||||||
|
*/
|
||||||
|
protected function createSSHMock()
|
||||||
|
{
|
||||||
|
return $this->getMockBuilder('Net_SSH2')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->setMethods(array('__destruct'))
|
||||||
|
->getMock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,25 +15,19 @@ abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
static protected function ensureConstant($constant, $expected)
|
static protected function ensureConstant($constant, $expected)
|
||||||
{
|
{
|
||||||
if (defined($constant))
|
if (defined($constant)) {
|
||||||
{
|
|
||||||
$value = constant($constant);
|
$value = constant($constant);
|
||||||
|
|
||||||
if ($value !== $expected)
|
if ($value !== $expected) {
|
||||||
{
|
if (function_exists('runkit_constant_redefine')) {
|
||||||
if (function_exists('runkit_constant_redefine'))
|
if (!runkit_constant_redefine($constant, $expected)) {
|
||||||
{
|
|
||||||
if (!runkit_constant_redefine($constant, $expected))
|
|
||||||
{
|
|
||||||
self::markTestSkipped(sprintf(
|
self::markTestSkipped(sprintf(
|
||||||
"Failed to redefine constant %s to %s",
|
"Failed to redefine constant %s to %s",
|
||||||
$constant,
|
$constant,
|
||||||
$expected
|
$expected
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
self::markTestSkipped(sprintf(
|
self::markTestSkipped(sprintf(
|
||||||
"Skipping test because constant %s is %s instead of %s",
|
"Skipping test because constant %s is %s instead of %s",
|
||||||
$constant,
|
$constant,
|
||||||
@ -42,9 +36,7 @@ abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
define($constant, $expected);
|
define($constant, $expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,8 +48,7 @@ abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
static protected function reRequireFile($filename)
|
static protected function reRequireFile($filename)
|
||||||
{
|
{
|
||||||
if (function_exists('runkit_import'))
|
if (function_exists('runkit_import')) {
|
||||||
{
|
|
||||||
$result = runkit_import(
|
$result = runkit_import(
|
||||||
$filename,
|
$filename,
|
||||||
RUNKIT_IMPORT_FUNCTIONS |
|
RUNKIT_IMPORT_FUNCTIONS |
|
||||||
@ -65,8 +56,7 @@ abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
|
|||||||
RUNKIT_IMPORT_OVERRIDE
|
RUNKIT_IMPORT_OVERRIDE
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!$result)
|
if (!$result) {
|
||||||
{
|
|
||||||
self::markTestSkipped("Failed to reimport file $filename");
|
self::markTestSkipped("Failed to reimport file $filename");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,11 @@ set_include_path(implode(PATH_SEPARATOR, array(
|
|||||||
|
|
||||||
function phpseclib_is_includable($suffix)
|
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;
|
$ds = substr($prefix, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR;
|
||||||
$file = $prefix . $ds . $suffix;
|
$file = $prefix . $ds . $suffix;
|
||||||
|
|
||||||
if (file_exists($file))
|
if (file_exists($file)) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,9 +33,10 @@ function phpseclib_autoload($class)
|
|||||||
{
|
{
|
||||||
$file = str_replace('_', '/', $class) . '.php';
|
$file = str_replace('_', '/', $class) . '.php';
|
||||||
|
|
||||||
if (phpseclib_is_includable($file))
|
if (phpseclib_is_includable($file)) {
|
||||||
{
|
// @codingStandardsIgnoreStart
|
||||||
require $file;
|
require $file;
|
||||||
|
// @codingStandardsIgnoreEnd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user