2012-12-04 03:34:51 -05:00
< ? php
/**
*
* @ package testing
* @ copyright ( c ) 2012 phpBB Group
* @ license http :// opensource . org / licenses / gpl - 2.0 . php GNU General Public License v2
*
*/
class phpbb_lint_test extends phpbb_test_case
{
2012-12-04 16:42:58 -05:00
static protected $exclude ;
static public function setUpBeforeClass ()
{
2012-12-04 17:43:36 -05:00
$output = array ();
$status = 1 ;
2012-12-04 18:52:27 -05:00
exec ( '(php -v) 2>&1' , $output , $status );
2012-12-04 17:43:36 -05:00
if ( $status )
{
2012-12-04 18:52:27 -05:00
$output = implode ( " \n " , $output );
2012-12-04 17:43:36 -05:00
self :: markTestSkipped ( " php is not in PATH or broken: $output " );
}
2012-12-04 16:42:58 -05:00
self :: $exclude = array (
2013-11-29 14:00:55 +01:00
dirname ( __FILE__ ) . '/../.git' ,
2013-11-29 10:50:38 +01:00
dirname ( __FILE__ ) . '/../build/new_version' ,
dirname ( __FILE__ ) . '/../build/old_versions' ,
2013-11-29 14:02:50 +01:00
dirname ( __FILE__ ) . '/../phpBB/cache' ,
2012-12-04 16:42:58 -05: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
dirname ( __FILE__ ) . '/../phpBB/vendor' ,
);
}
2012-12-04 03:34:51 -05:00
public function test_lint ()
{
2012-12-04 13:58:14 -05:00
if ( version_compare ( PHP_VERSION , '5.3.0' , '<' ))
{
$this -> markTestSkipped ( 'phpBB uses PHP 5.3 syntax in some files, linting on PHP < 5.3 will fail' );
}
2012-12-04 03:34:51 -05:00
$root = dirname ( __FILE__ ) . '/..' ;
$this -> check ( $root );
}
protected function check ( $root )
{
$dh = opendir ( $root );
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 ;
}
2012-12-04 16:42:58 -05:00
if ( is_dir ( $path ) && ! in_array ( $path , self :: $exclude ))
2012-12-04 03:34:51 -05:00
{
$this -> check ( $path );
}
else if ( substr ( $filename , strlen ( $filename ) - 4 ) == '.php' )
{
// assume php binary is called php and it is in PATH
2012-12-04 18:52:27 -05:00
$cmd = '(php -l ' . escapeshellarg ( $path ) . ') 2>&1' ;
2012-12-04 03:34:51 -05:00
$output = array ();
$status = 1 ;
exec ( $cmd , $output , $status );
$output = implode ( " \n " , $output );
$this -> assertEquals ( 0 , $status , " php -l failed for $path : \n $output " );
}
}
}
}