Merge branch 'master' into php5

* master:
  Apply coding guidelines (with exceptions) to the tests directory.
  Update PHP_CodeSniffer from 1.4.7 to 1.5.2. This fixes a rule inheritance bug.
  Use exclude instead of changing severity.
  Add build directory.
This commit is contained in:
Andreas Fischer 2014-02-17 18:54:12 +01:00
commit 68fecc6431
19 changed files with 656 additions and 648 deletions

View File

@ -19,7 +19,8 @@ before_script:
- sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.5' ]; then composer install --dev --no-interaction; fi"
script:
- sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.5' ]; then vendor/bin/phpcs -s --extensions=php --standard=tests/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/
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

@ -0,0 +1,76 @@
<?xml version="1.0"?>
<ruleset name="phpseclib Standard">
<description>phpseclib coding standard</description>
<!-- We are using the PEAR standard as a base -->
<rule ref="PEAR">
<!-- Temporary exceptions to the PEAR standard follow -->
<exclude name="Generic.ControlStructures.InlineControlStructure.Discouraged" />
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="PEAR.NamingConventions.ValidFunctionName.FunctionNoCapital" />
<exclude name="PEAR.NamingConventions.ValidFunctionName.NotCamelCaps" />
<exclude name="PEAR.Commenting.ClassComment.InvalidVersion" />
<exclude name="PEAR.Commenting.ClassComment.MissingTag" />
<exclude name="PEAR.Commenting.FileComment.EmptyCopyright" />
<exclude name="PEAR.Commenting.FileComment.InvalidVersion" />
<exclude name="PEAR.Commenting.FunctionComment.ExtraParamComment" />
<exclude name="PEAR.Commenting.FunctionComment.MissingReturn" />
<exclude name="PEAR.Commenting.FunctionComment.MissingParamComment" />
<exclude name="PEAR.Commenting.FunctionComment.MissingParamName" />
<exclude name="PEAR.Commenting.FunctionComment.MissingParamTag" />
<exclude name="PEAR.Commenting.FunctionComment.ParameterCommentsNotAligned" />
<exclude name="PEAR.Commenting.FunctionComment.ParameterNamesNotAligned" />
<exclude name="PEAR.Commenting.FunctionComment.ParamNameNoMatch" />
<exclude name="PEAR.Commenting.FunctionComment.SpacingAfterParams" />
<exclude name="PEAR.Commenting.FunctionComment.SpacingBeforeParams" />
<exclude name="PEAR.Commenting.FunctionComment.SpacingBeforeTags" />
<exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
<exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
<exclude name="PEAR.Functions.FunctionCallSignature.Indent" />
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket" />
<exclude name="PEAR.WhiteSpace.ScopeClosingBrace.BreakIdent" />
<exclude name="PEAR.WhiteSpace.ScopeClosingBrace.Indent" />
<exclude name="PEAR.WhiteSpace.ScopeClosingBrace.Line" />
<exclude name="PEAR.WhiteSpace.ScopeIndent.Incorrect" />
</rule>
<!-- Useful additional rules follow -->
<!-- "for (; bar; )" should be "while (bar)" instead -->
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop" />
<!-- A method MUST not only call its parent -->
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod" />
<!-- All code files MUST use only UTF-8 without BOM. -->
<rule ref="Generic.Files.ByteOrderMark" />
<!-- Each file MUST end with exactly one newline character -->
<rule ref="PSR2.Files.EndFileNewline" />
<!-- In the argument list, there MUST NOT be a space before each comma,
and there MUST be one space after each comma. -->
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1"/>
</properties>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint" />
<!-- There MUST NOT be trailing whitespace at the end of lines. -->
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" />
<!-- There MUST NOT be whitespace before the first content of a file -->
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile" />
<!-- There MUST NOT be whitespace after the last content of a file -->
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile" />
<!-- Functions MUST NOT contain multiple empty lines in a row -->
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines" />
<!-- The ?> closing tag MUST be omitted from files containing only PHP. -->
<rule ref="Zend.Files.ClosingTag" />
</ruleset>

13
composer.lock generated
View File

@ -3,23 +3,23 @@
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "e692359d277b10176319a11c2aef51aa",
"hash": "4975b8cde04a99d6e78e108753845af6",
"packages": [
],
"packages-dev": [
{
"name": "squizlabs/php_codesniffer",
"version": "1.4.7",
"version": "1.5.2",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "df764a1604607ea61c4eeea5410666e27cb37a8b"
"reference": "a76a39b317ce8106abe6264daa505e24e1731860"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/df764a1604607ea61c4eeea5410666e27cb37a8b",
"reference": "df764a1604607ea61c4eeea5410666e27cb37a8b",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/a76a39b317ce8106abe6264daa505e24e1731860",
"reference": "a76a39b317ce8106abe6264daa505e24e1731860",
"shasum": ""
},
"require": {
@ -39,7 +39,6 @@
"CodeSniffer/CLI.php",
"CodeSniffer/Exception.php",
"CodeSniffer/File.php",
"CodeSniffer/MultiFileSniff.php",
"CodeSniffer/Report.php",
"CodeSniffer/Reporting.php",
"CodeSniffer/Sniff.php",
@ -77,7 +76,7 @@
"phpcs",
"standards"
],
"time": "2013-09-26 00:08:21"
"time": "2014-02-04 23:49:58"
}
],
"aliases": [

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
}
}

View File

@ -1,77 +0,0 @@
<?xml version="1.0"?>
<ruleset name="phpseclib Standard">
<description>phpseclib coding standard</description>
<!-- We are using the PEAR standard as a base -->
<rule ref="PEAR"/>
<!-- Temporary exceptions to the PEAR standard follow -->
<rule ref="Generic.ControlStructures.InlineControlStructure.Discouraged"><severity>0</severity></rule>
<rule ref="Generic.Files.LineLength.TooLong"><severity>0</severity></rule>
<rule ref="PEAR.NamingConventions.ValidFunctionName.FunctionNoCapital"><severity>0</severity></rule>
<rule ref="PEAR.NamingConventions.ValidFunctionName.NotCamelCaps"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.ClassComment.InvalidVersion"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.ClassComment.MissingTag"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FileComment.EmptyCopyright"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FileComment.InvalidVersion"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FunctionComment.ExtraParamComment"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FunctionComment.MissingReturn"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FunctionComment.MissingParamComment"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FunctionComment.MissingParamName"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FunctionComment.MissingParamTag"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FunctionComment.ParameterCommentsNotAligned"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FunctionComment.ParameterNamesNotAligned"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FunctionComment.ParamNameNoMatch"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FunctionComment.SpacingAfterParams"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FunctionComment.SpacingBeforeParams"><severity>0</severity></rule>
<rule ref="PEAR.Commenting.FunctionComment.SpacingBeforeTags"><severity>0</severity></rule>
<rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket"><severity>0</severity></rule>
<rule ref="PEAR.Functions.FunctionCallSignature.CloseBracketLine"><severity>0</severity></rule>
<rule ref="PEAR.Functions.FunctionCallSignature.Indent"><severity>0</severity></rule>
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket"><severity>0</severity></rule>
<rule ref="PEAR.WhiteSpace.ScopeClosingBrace.BreakIdent"><severity>0</severity></rule>
<rule ref="PEAR.WhiteSpace.ScopeClosingBrace.Indent"><severity>0</severity></rule>
<rule ref="PEAR.WhiteSpace.ScopeClosingBrace.Line"><severity>0</severity></rule>
<rule ref="PEAR.WhiteSpace.ScopeIndent.Incorrect"><severity>0</severity></rule>
<!-- Useful additional rules follow -->
<!-- "for (; bar; )" should be "while (bar)" instead -->
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop" />
<!-- A method MUST not only call its parent -->
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod" />
<!-- All code files MUST use only UTF-8 without BOM. -->
<rule ref="Generic.Files.ByteOrderMark" />
<!-- Each file MUST end with exactly one newline character -->
<rule ref="PSR2.Files.EndFileNewline" />
<!-- In the argument list, there MUST NOT be a space before each comma,
and there MUST be one space after each comma. -->
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1"/>
</properties>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint" />
<!-- There MUST NOT be trailing whitespace at the end of lines. -->
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" />
<!-- There MUST NOT be whitespace before the first content of a file -->
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile" />
<!-- There MUST NOT be whitespace after the last content of a file -->
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile" />
<!-- Functions MUST NOT contain multiple empty lines in a row -->
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines" />
<!-- The ?> closing tag MUST be omitted from files containing only PHP. -->
<rule ref="Zend.Files.ClosingTag" />
</ruleset>