Skip to content

Instantly share code, notes, and snippets.

@masartz
Created February 3, 2015 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masartz/2e86974b85efdd77da44 to your computer and use it in GitHub Desktop.
Save masartz/2e86974b85efdd77da44 to your computer and use it in GitHub Desktop.
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