cvs: pear-core /tests pear_common_analyzeSC.phpt /tests/PEAR_Common setup.php.inc test_analyzeSourceCode.phpt

From: Date: Thu, 28 Oct 2004 22:41:08 +0000
Subject: cvs: pear-core /tests pear_common_analyzeSC.phpt /tests/PEAR_Common setup.php.inc test_analyzeSourceCode.phpt
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-1183@lists.php.net to get a copy of this message
cellog Thu Oct 28 18:41:08 2004 EDT Added files: /pear-core/tests/PEAR_Common setup.php.inc test_analyzeSourceCode.phpt Removed files: /pear-core/tests pear_common_analyzeSC.phpt Log: move old-style unit test to new-style http://cvs.php.net/co.php/pear-core/tests/PEAR_Common/setup.php.inc?r=1.1&p=1 Index: pear-core/tests/PEAR_Common/setup.php.inc +++ pear-core/tests/PEAR_Common/setup.php.inc <?php require_once 'PEAR/Common.php'; function cleanall($dir = null) { if ($dir !== null) { $statedir = $dir; } else { $statedir = $GLOBALS['statedir']; } if (file_exists($statedir)) { $dp = opendir($statedir); while ($ent = readdir($dp)) { if (in_array($ent, array('.', '..'))) { continue; } if (is_dir($statedir . DIRECTORY_SEPARATOR . $ent)) { cleanall($statedir . DIRECTORY_SEPARATOR . $ent); continue; } unlink($statedir . DIRECTORY_SEPARATOR . $ent); } closedir($dp); rmdir($statedir); } } register_shutdown_function('cleanall'); $statedir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'registry_tester'; cleanall($statedir); mkdir($statedir); $config = serialize( array( 'php_dir' => $statedir . DIRECTORY_SEPARATOR . 'php', ) ); $fp = fopen($statedir . DIRECTORY_SEPARATOR . 'pear.ini', 'wb'); fwrite($fp, $config, strlen($config)); fclose($fp); //$config = &new PEAR_Config($statedir . DIRECTORY_SEPARATOR . 'pear.ini'); require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'phpt_test.php.inc'; $phpunit = &new PEAR_PHPTest(true); class fake_log { var $_log = array(); function log($level, $message) { $this->_log[] = array($level, $message); } function getLog() { $log = $this->_log; $this->_log = array(); return $log; } } $fakelog = new fake_log; ?> http://cvs.php.net/co.php/pear-core/tests/PEAR_Common/test_analyzeSourceCode.phpt?r=1.1&p=1 Index: pear-core/tests/PEAR_Common/test_analyzeSourceCode.phpt +++ pear-core/tests/PEAR_Common/test_analyzeSourceCode.phpt --TEST-- PEAR_Common::analyzeSourceCode test --SKIPIF-- <?php if (!getenv('PHP_PEAR_RUNTESTS')) { echo 'skip'; } if (!function_exists('token_get_all')) { echo 'skip'; } ?> --FILE-- <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'setup.php.inc'; $phpunit->assertFalse(PEAR_Common::analyzeSourceCode('=+"\\//452'), 'invalid filename'); $testdir = $statedir; @mkdir($testdir); $test1 = ' <?php ::error(); ?> '; $fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test1.php', 'w'); fwrite($fp, $test1); fclose($fp); $ret = PEAR_Common::analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test1.php'); $phpunit->assertErrors(array( array('package' => 'PEAR_Error', 'message' => 'Parser error: invalid PHP found in file "' . $testdir . DIRECTORY_SEPARATOR . 'test1.php"')), 'invalid php'); $phpunit->assertFalse($ret, 'wrong return value, invalid php in file'); unlink($testdir . DIRECTORY_SEPARATOR . 'test1.php'); $test3 = ' <?php class test { class test2 { } } ?> '; $fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test3.php', 'w'); fwrite($fp, $test3); fclose($fp); $ret = PEAR_Common::analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test3.php'); $phpunit->assertErrors(array( array('package' => 'PEAR_Error', 'message' => 'Parser error: invalid PHP found in file "' . $testdir . DIRECTORY_SEPARATOR . 'test3.php"')), 'more invalid php'); $phpunit->assertFalse($ret, 'wrong return value, 2nd invalid PHP test'); unlink($testdir . DIRECTORY_SEPARATOR . 'test3.php'); $test4 = ' <?php function test() { class test2 { } } ?> '; $fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test4.php', 'w'); fwrite($fp, $test4); fclose($fp); $ret = PEAR_Common::analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test4.php'); $phpunit->assertErrors(array( array('package' => 'PEAR_Error', 'message' => 'Parser error: invalid PHP found in file "' . $testdir . DIRECTORY_SEPARATOR . 'test4.php"')), '3rd invalid php'); $phpunit->assertFalse($ret, 'wrong return value, 3rd invalid PHP test'); unlink($testdir . DIRECTORY_SEPARATOR . 'test4.php'); $test5 = ' <?php function test() { } if (trytofool) { function fool() { } } class test2 { function test2() { parent::unused(); Greg::classes(); $a = new Pierre; } } class blah extends test2 { /** * @nodep Stig */ function blah() { Stig::rules(); } } ?> '; $fp = fopen($testdir . DIRECTORY_SEPARATOR . 'test5.php', 'w'); fwrite($fp, $test5); fclose($fp); $ret = PEAR_Common::analyzeSourceCode($testdir . DIRECTORY_SEPARATOR . 'test5.php'); $phpunit->assertNoErrors('1st valid PHP'); $phpunit->showall(); $phpunit->assertEquals(array ( 'source_file' => $testdir . DIRECTORY_SEPARATOR . 'test5.php', 'declared_classes' => array ( 0 => 'test2', 1 => 'blah', ), 'declared_interfaces' => array ( ), 'declared_methods' => array ( 'test2' => array ( 0 => 'test2', ), 'blah' => array ( 0 => 'blah', ), ), 'declared_functions' => array ( 0 => 'test', 1 => 'fool', ), 'used_classes' => array ( 0 => 'Greg', 1 => 'Pierre', ), 'inheritance' => array ( 'blah' => 'test2', ), 'implements' => array ( ), ), $ret, 'wrong return value, 1st valid PHP test'); echo 'tests done'; ?> --EXPECT-- tests done

« previous php.pear.core (#1183) next »