|
Disclaimer:
These pages about different languages / apis / best practices were mostly jotted down quckily and rarely corrected afterwards. The languages / apis / best practices may have changed over time (e.g. the facebook api being a prime example), so what was documented as a good way to do something at the time might be outdated when you read it (some pages here are over 15 years old). Just as a reminder. PHP programming tips and tricksSome notes on software development with PHPFake slow loadingE.g. when checking that the onload events in javascript are firing properly, you want to fake slow loading times of for example images$file = 'images/ad.jpg'; $type = 'image/jpeg'; header('Content-Type:'.$type); header('Content-Length: ' . filesize($file)); sleep(12); readfile($file); PhpUnit, solving global variable problemruntest.php/* * phpunit keep everything global, * meaning that if you have two files that test for example stuff in subpages/ * you will get an error since it tries to redefined the no_render function * * So, this script is a workaround, it executes phpunit on one file at the time * and present the results */ $mo = find_all_files('.'); $failed=array(); $succ=array(); $failedFiles=array(); $succFiles=array(); $failCnt=0; $succCnt=0; foreach($mo as $k => $file) { echo "$file "; unset($output); exec("phpunit $file", $output, $returncode); if($returncode > 0 ) { //failed array_push($failedFiles, $file); $failCnt++; $failed = array_merge($failed, $output); echo "---- F "; } else { $succCnt++; array_push($succFiles, $file); $succ = array_merge($succ, $output); echo "---- . "; } } foreach($succ as $k => $l) { echo "$l "; } foreach($failed as $k => $l) { echo "$l "; } echo "-----------------SUMMARY----------------- "; echo "Succeded files: "; foreach($succFiles as $k => $l) { echo "$l "; } echo "------------------------------------ "; echo "Failed files: "; foreach($failedFiles as $k => $l) { echo "$l "; } echo "------------------------------------ "; echo "Failed: $failCnt Success: $succCnt "; echo "------------------------------------ "; function find_all_files($dir) { $root = scandir($dir); $result=array(); foreach($root as $value) { $value = rtrim($value); if($value === '.' || $value === '..') { continue; } if(is_file("$dir/$value")) { if(0 == endsWith($value)) { continue; } $result[]="$dir/$value";continue; } foreach(find_all_files("$dir/$value") as $value) { $result[]=$value; } } return $result; } function endsWith($haystack) { return preg_match("/Test\.php$/", $haystack); } Unit testing - SimpleTestHow to execute SimpleTest in subdirs$test = new TestSuite('All file tests'); $dirs = array( 'classes/dir', 'connect', 'include', 'include/db', 'include/util', 'refactor/include' ); global $configProd; foreach ($dirs as $aDir) { foreach(glob('/php/unit/tests/'.$aDir.'/*Test.php') as $aFile) { if(! $configProd){ echo "$aFile Profiling in PHPInstall xdebug
sudo pecl install xdebug
Add to php.ini
xdebug.profiler_enable=On
More programming related pages |
|