Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for the NewFunctions sniff. #161

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
159 changes: 103 additions & 56 deletions Sniffs/PHP/NewFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
'5.1' => false,
'5.2' => true
),
'swfmovie::namedanchor' => array(
'5.1' => false,
'5.2' => true
),
'swfmovie::protect' => array(
'5.1' => false,
'5.2' => true
),
'openssl_csr_get_public_key' => array(
'5.1' => false,
'5.2' => true
Expand Down Expand Up @@ -322,14 +314,6 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
'5.2' => false,
'5.3' => true
),
'streamWrapper::stream_cast' => array(
'5.2' => false,
'5.3' => true
),
'streamWrapper::stream_set_option' => array(
'5.2' => false,
'5.3' => true
),
'date_add' => array(
'5.2' => false,
'5.3' => true
Expand Down Expand Up @@ -382,6 +366,10 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
'5.2' => false,
'5.3' => true
),
'mysqli_get_cache_stats' => array(
'5.2' => false,
'5.3' => true
),
'mysqli_fetch_all' => array(
'5.2' => false,
'5.3' => true
Expand Down Expand Up @@ -434,6 +422,22 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
'5.2' => false,
'5.3' => true
),
'asinh' => array(
'5.2' => false,
'5.3' => true
),
'atanh' => array(
'5.2' => false,
'5.3' => true
),
'expm1' => array(
'5.2' => false,
'5.3' => true
),
'log1p' => array(
'5.2' => false,
'5.3' => true
),
'enchant_broker_describe' => array(
'5.2' => false,
'5.3' => true
Expand Down Expand Up @@ -1080,14 +1084,83 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
'5.4' => false,
'5.5' => true
),
'SplFixedArray::_wakup' => array(
'5.4' => false,
'5.5' => true

'gmp_root' => array(
'5.5' => false,
'5.6' => true
),
'Closure::call' => array(
'5.6' => false,
'7.0' => true
'gmp_rootrem' => array(
'5.5' => false,
'5.6' => true
),
'hash_equals' => array(
'5.5' => false,
'5.6' => true
),
'ldap_escape' => array(
'5.5' => false,
'5.6' => true
),
'ldap_modify_batch' => array(
'5.4.25' => false,
'5.5.9' => false,
'5.4.26' => true,
'5.5.10' => true,
'5.6.0' => true,
),
'mysqli_get_links_stats' => array(
'5.5' => false,
'5.6' => true
),
'openssl_get_cert_locations' => array(
'5.5' => false,
'5.6' => true
),
'openssl_x509_fingerprint' => array(
'5.5' => false,
'5.6' => true
),
'openssl_spki_new' => array(
'5.5' => false,
'5.6' => true
),
'openssl_spki_verify' => array(
'5.5' => false,
'5.6' => true
),
'openssl_spki_export_challenge' => array(
'5.5' => false,
'5.6' => true
),
'openssl_spki_export' => array(
'5.5' => false,
'5.6' => true
),
'pg_connect_poll' => array(
'5.5' => false,
'5.6' => true
),
'pg_consume_input' => array(
'5.5' => false,
'5.6' => true
),
'pg_flush' => array(
'5.5' => false,
'5.6' => true
),
'pg_socket' => array(
'5.5' => false,
'5.6' => true
),
'session_abort' => array(
'5.5' => false,
'5.6' => true
),
'session_reset' => array(
'5.5' => false,
'5.6' => true
),

'random_bytes' => array(
'5.6' => false,
'7.0' => true
Expand All @@ -1100,10 +1173,6 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
'5.6' => false,
'7.0' => true
),
'Generator::getReturn' => array(
'5.6' => false,
'7.0' => true
),
'gmp_random_seed' => array(
'5.6' => false,
'7.0' => true
Expand All @@ -1128,34 +1197,6 @@ class PHPCompatibility_Sniffs_PHP_NewFunctionsSniff extends PHPCompatibility_Sni
'5.6' => false,
'7.0' => true
),
'ReflectionParameter::getType' => array(
'5.6' => false,
'7.0' => true
),
'' => array(
'5.6' => false,
'7.0' => true
),
'ReflectionParameter::hasType' => array(
'5.6' => false,
'7.0' => true
),
'ReflectionFunctionAbstract::getReturnType' => array(
'5.6' => false,
'7.0' => true
),
'ReflectionFunctionAbstract::hasReturnType' => array(
'5.6' => false,
'7.0' => true
),
'ZipArchive::setCompressionIndex' => array(
'5.6' => false,
'7.0' => true
),
'ZipArchive::setCompressionName' => array(
'5.6' => false,
'7.0' => true
),
'inflate_add' => array(
'5.6' => false,
'7.0' => true
Expand Down Expand Up @@ -1192,6 +1233,8 @@ public function register()
// Everyone has had a chance to figure out what forbidden functions
// they want to check for, so now we can cache out the list.
$this->forbiddenFunctionNames = array_keys($this->forbiddenFunctions);
$this->forbiddenFunctionNames = array_map('strtolower', $this->forbiddenFunctionNames);
$this->forbiddenFunctions = array_combine($this->forbiddenFunctionNames, $this->forbiddenFunctions);

if ($this->patternMatch === true) {
foreach ($this->forbiddenFunctionNames as $i => $name) {
Expand Down Expand Up @@ -1228,6 +1271,10 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
// Not a call to a PHP function.
return;
}
else if($tokens[$prevToken]['code'] === T_NS_SEPARATOR && $tokens[$prevToken - 1]['code'] === T_STRING) {
// Namespaced function.
return;
}

$function = strtolower($tokens[$stackPtr]['content']);
$pattern = null;
Expand All @@ -1254,7 +1301,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}
}

$this->addError($phpcsFile, $stackPtr, $function, $pattern);
$this->addError($phpcsFile, $stackPtr, $tokens[$stackPtr]['content'], $pattern);

}//end process()

Expand All @@ -1273,7 +1320,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
{
if ($pattern === null) {
$pattern = $function;
$pattern = strtolower($function);
}

$error = '';
Expand Down