2012-12-04 03:34:51 -05:00
< ? php
/**
*
2014-05-27 20:18:06 +02:00
* This file is part of the phpBB Forum Software package .
*
* @ copyright ( c ) phpBB Limited < https :// www . phpbb . com >
* @ license GNU General Public License , version 2 ( GPL - 2.0 )
*
* For full copyright and license information , please see
* the docs / CREDITS . txt file .
2012-12-04 03:34:51 -05:00
*
*/
2020-09-10 20:05:25 +07:00
class lint_test extends phpbb_test_case
2012-12-04 03:34:51 -05:00
{
2021-04-03 23:12:04 +02:00
protected static $php_binary ;
2012-12-04 16:42:58 -05:00
2020-07-13 14:06:04 +07:00
static public function setUpBeforeClass () : void
2012-12-04 16:42:58 -05:00
{
2013-11-29 13:53:11 +01:00
// Try to use PHP_BINARY constant if available so lint tests are run
// using the same php binary as phpunit. If not available (pre PHP
// 5.4), assume binary is called 'php' and is in PATH.
self :: $php_binary = defined ( 'PHP_BINARY' ) ? escapeshellcmd ( PHP_BINARY ) : 'php' ;
2012-12-04 17:43:36 -05:00
$output = array ();
$status = 1 ;
2013-11-29 13:53:11 +01:00
exec ( sprintf ( '(%s --version) 2>&1' , self :: $php_binary ), $output , $status );
2012-12-04 17:43:36 -05:00
if ( $status )
{
2012-12-04 18:52:27 -05:00
$output = implode ( " \n " , $output );
2013-11-29 13:53:11 +01:00
if ( self :: $php_binary === 'php' )
{
self :: markTestSkipped ( sprintf ( 'php is not in PATH or broken. Output: %s' , $output ));
}
else
{
self :: markTestSkipped ( sprintf ( 'Could not run PHP_BINARY %s. Output: %s' , self :: $php_binary , $output ));
}
2012-12-04 17:43:36 -05:00
}
2012-12-04 16:42:58 -05:00
}
2015-05-03 14:35:04 +02:00
/**
* @ dataProvider lint_data
*/
public function test_lint ( $path )
2012-12-04 03:34:51 -05:00
{
2015-05-03 14:35:04 +02:00
$cmd = sprintf ( '(%s -l %s) 2>&1' , self :: $php_binary , escapeshellarg ( $path ));
$output = array ();
$status = 1 ;
exec ( $cmd , $output , $status );
$output = implode ( " \n " , $output );
$this -> assertEquals ( 0 , $status , " PHP lint failed for $path : \n $output " );
}
public function lint_data ()
{
2017-12-03 17:19:59 +02:00
return $this -> check ( __DIR__ . '/..' );
2012-12-04 03:34:51 -05:00
}
protected function check ( $root )
{
2015-05-03 14:35:04 +02:00
$files = array ();
2012-12-04 03:34:51 -05:00
$dh = opendir ( $root );
2018-12-23 14:35:58 +01:00
if ( $dh === false )
{
return $files ;
}
2012-12-04 03:34:51 -05:00
while (( $filename = readdir ( $dh )) !== false )
{
2013-11-29 14:00:55 +01:00
if ( $filename == '.' || $filename == '..' )
2012-12-04 03:34:51 -05:00
{
continue ;
}
$path = $root . '/' . $filename ;
// skip symlinks to avoid infinite loops
if ( is_link ( $path ))
{
continue ;
}
2015-05-03 14:35:04 +02:00
if ( is_dir ( $path ) && ! in_array ( $path , array (
2017-12-03 17:19:59 +02:00
__DIR__ . '/../.git' ,
__DIR__ . '/../build/new_version' ,
__DIR__ . '/../build/old_versions' ,
__DIR__ . '/../phpBB/cache' ,
__DIR__ . '/../phpBB/ext' ,
__DIR__ . '/../phpBB/store' ,
2015-05-03 14:35:04 +02:00
// PHP Fatal error: Cannot declare class Container because the name is already in use in /var/www/projects/phpbb3/tests/../phpBB/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php on line 20
// https://gist.github.com/e003913ffd493da63cbc
2017-12-03 17:19:59 +02:00
__DIR__ . '/../phpBB/vendor' ,
__DIR__ . '/../node_modules' ,
2015-05-03 14:35:04 +02:00
)))
2012-12-04 03:34:51 -05:00
{
2015-05-03 14:35:04 +02:00
$files = array_merge ( $files , $this -> check ( $path ));
2012-12-04 03:34:51 -05:00
}
else if ( substr ( $filename , strlen ( $filename ) - 4 ) == '.php' )
{
2015-05-03 14:35:04 +02:00
$files [] = array ( $path );
2012-12-04 03:34:51 -05:00
}
}
2015-05-03 14:35:04 +02:00
return $files ;
2012-12-04 03:34:51 -05:00
}
}