Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
php syntax check test
<?php
/**
* Test_PHP_Syntax
*
* @group App
* @uses TestCase
*
*/
class SyntaxTest extends PHPUnit_Framework_TestCase
{
public $TARGET_DIR = array(
'./lib'
);
public function test_php_syntax()
{
$file_list = array();
foreach( $this->TARGET_DIR as $target_dir ){
$file_list = $this->search_file_list( $target_dir );
foreach( $file_list as $file) {
system("php -l $file >/dev/null 2>&1" , $exit_status );
$this->assertEquals( $exit_status , 0 , "$file syntax OK");
}
}
}
private function search_file_list($target_dir)
{
$iterator = new RecursiveDirectoryIterator( $target_dir );
$iterator = new RecursiveIteratorIterator($iterator);
$file_list = array();
foreach ($iterator as $fileinfo) { // $fileinfoはSplFiIeInfoオブジェクト
if ($fileinfo->isFile() && $fileinfo->getExtension() === "php") {
$file_list[] = $fileinfo->getPathname();
}
}
return $file_list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment