Created
February 3, 2015 02:48
-
-
Save masartz/2e86974b85efdd77da44 to your computer and use it in GitHub Desktop.
php syntax check test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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