cvs: pear-core /tests pear_common_downloadHttp.phpt pear_common_downloadHttp_php5.phpt /tests/PEAR_Common setup.php.inc test_downloadHttp.phpt
/tests/PEAR_Common/download testdownload.tgz

From: Date: Thu, 28 Oct 2004 23:45:47 +0000
Subject: cvs: pear-core /tests pear_common_downloadHttp.phpt pear_common_downloadHttp_php5.phpt /tests/PEAR_Common setup.php.inc test_downloadHttp.phpt
/tests/PEAR_Common/download testdownload.tgz
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-1185@lists.php.net to get a copy of this message
cellog Thu Oct 28 19:45:47 2004 EDT Added files: /pear-core/tests/PEAR_Common test_downloadHttp.phpt /pear-core/tests/PEAR_Common/download testdownload.tgz Removed files: /pear-core/tests pear_common_downloadHttp.phpt pear_common_downloadHttp_php5.phpt Modified files: /pear-core/tests/PEAR_Common setup.php.inc Log: move old-style tests into a single new-style test

http://cvs.php.net/diff.php/pear-core/tests/PEAR_Common/setup.php.inc?r1=1.1&r2=1.2&ty=u Index: pear-core/tests/PEAR_Common/setup.php.inc diff -u pear-core/tests/PEAR_Common/setup.php.inc:1.1 pear-core/tests/PEAR_Common/setup.php.inc:1.2 --- pear-core/tests/PEAR_Common/setup.php.inc:1.1 Thu Oct 28 18:41:08 2004 +++ pear-core/tests/PEAR_Common/setup.php.inc Thu Oct 28 19:45:47 2004 @@ -1,5 +1,6 @@ <?php require_once 'PEAR/Common.php'; +$statedir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testinstallertemp'; function cleanall($dir = null) { @@ -26,34 +27,96 @@ } register_shutdown_function('cleanall'); -$statedir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'registry_tester'; cleanall($statedir); -mkdir($statedir); -$config = serialize( -array( +if (!is_dir($statedir)) { + mkdir($statedir); +} +if (!is_dir($statedir . DIRECTORY_SEPARATOR . 'php')) { + mkdir($statedir . DIRECTORY_SEPARATOR . 'php'); +} +if (!is_dir($statedir . DIRECTORY_SEPARATOR . 'data')) { + mkdir($statedir . DIRECTORY_SEPARATOR . 'data'); +} +if (!is_dir($statedir . DIRECTORY_SEPARATOR . 'doc')) { + mkdir($statedir . DIRECTORY_SEPARATOR . 'doc'); +} +if (!is_dir($statedir . DIRECTORY_SEPARATOR . 'test')) { + mkdir($statedir . DIRECTORY_SEPARATOR . 'test'); +} +if (!is_dir($statedir . DIRECTORY_SEPARATOR . 'ext')) { + mkdir($statedir . DIRECTORY_SEPARATOR . 'ext'); +} +if (!is_dir($statedir . DIRECTORY_SEPARATOR . 'script')) { + mkdir($statedir . DIRECTORY_SEPARATOR . 'script'); +} +if (!is_dir($statedir . DIRECTORY_SEPARATOR . 'tmp')) { + mkdir($statedir . DIRECTORY_SEPARATOR . 'tmp'); +} +if (!is_dir($statedir . DIRECTORY_SEPARATOR . 'bin')) { + mkdir($statedir . DIRECTORY_SEPARATOR . 'bin'); +} +if (!is_dir($statedir . DIRECTORY_SEPARATOR . 'cache')) { + mkdir($statedir . DIRECTORY_SEPARATOR . 'cache'); +} +// make the fake configuration - we'll use one of these and it should work +$config = serialize(array('master_server' => 'pear.php.net', + 'preferred_state' => 'stable', + 'cache_dir' => $statedir . DIRECTORY_SEPARATOR . 'cache', 'php_dir' => $statedir . DIRECTORY_SEPARATOR . 'php', -) -); -$fp = fopen($statedir . DIRECTORY_SEPARATOR . 'pear.ini', 'wb'); -fwrite($fp, $config, strlen($config)); + 'ext_dir' => $statedir . DIRECTORY_SEPARATOR . 'ext', + 'data_dir' => $statedir . DIRECTORY_SEPARATOR . 'data', + 'doc_dir' => $statedir . DIRECTORY_SEPARATOR . 'doc', + 'test_dir' => $statedir . DIRECTORY_SEPARATOR . 'test', + 'bin_dir' => $statedir . DIRECTORY_SEPARATOR . 'bin',)); +touch($statedir . DIRECTORY_SEPARATOR . 'pear.conf'); +$fp = fopen($statedir . DIRECTORY_SEPARATOR . 'pear.conf', 'w'); +fwrite($fp, $config); +fclose($fp); +touch($statedir . DIRECTORY_SEPARATOR . 'pear.ini'); +$fp = fopen($statedir . DIRECTORY_SEPARATOR . 'pear.ini', 'w'); +fwrite($fp, $config); fclose($fp); + +putenv('PHP_PEAR_SYSCONF_DIR='.$statedir); +$home = getenv('HOME'); +if (!empty($home)) { + // for PEAR_Config initialization + putenv('HOME="'.$statedir); +} //$config = &new PEAR_Config($statedir . DIRECTORY_SEPARATOR . 'pear.ini'); +require_once dirname(dirname(__FILE__)) . '/download_test_classes.php.inc'; require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'phpt_test.php.inc'; $phpunit = &new PEAR_PHPTest(true); class fake_log { var $_log = array(); + var $_download = array(); function log($level, $message) { $this->_log[] = array($level, $message); } + function _downloadCallback($msg, $params) + { + if ($msg == 'setup') { + $params = 'self'; + } + $this->_download[] = array($msg, $params); + } + function getLog() { $log = $this->_log; $this->_log = array(); return $log; } + + function getDownload() + { + $log = $this->_download; + $this->_download = array(); + return $log; + } } $fakelog = new fake_log; ?> \ No newline at end of file http://cvs.php.net/co.php/pear-core/tests/PEAR_Common/test_downloadHttp.phpt?r=1.1&p=1 Index: pear-core/tests/PEAR_Common/test_downloadHttp.phpt +++ pear-core/tests/PEAR_Common/test_downloadHttp.phpt --TEST-- PEAR_Common::downloadHttp test --SKIPIF-- <?php if (!getenv('PHP_PEAR_RUNTESTS')) { echo 'skip'; } $fp = @fsockopen('pear.php.net', 80); if (!$fp) { echo 'skip'; } else { fclose($fp); } ?> --FILE-- <?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'setup.php.inc'; $php5 = version_compare(phpversion(), '5.0.0', '>='); $windows = substr(PHP_OS, 0, 3) == 'WIN'; $common = &new PEAR_Common; ob_start(); PEAR_Common::downloadHttp('http://test.pear.php.net/testdownload.tgz', $ui, $statedir); $caught = ob_get_contents(); ob_end_clean(); $phpunit->assertNoErrors('wrong simple'); $phpunit->assertEquals('', $caught, 'wrong simple'); $firstone = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'download' . DIRECTORY_SEPARATOR . 'testdownload.tgz')); $secondone = implode('', file($statedir . DIRECTORY_SEPARATOR . 'testdownload.tgz')); $phpunit->assertTrue($firstone == $secondone, 'files are not the same'); ob_start(); PEAR_Common::downloadHttp('http://test.poop.php.net/stuff.tgz', $ui, $statedir); ob_end_clean(); $phpunit->assertErrors(array( array('package' => 'PEAR_Error', 'message' => 'Connection to `test.poop.php.net:80\' failed: ' . ($php5 ? '' : 'The operation completed successfully.' . ($windows ? "\r\n" : "\n"))) ), 'static fail'); $phpunit->assertEquals('', $caught, 'wrong static simple'); //echo "Test callback:\n"; $phpunit->showall(); ob_start(); PEAR_Common::downloadHttp('http://test.pear.php.net/testdownload.tgz', $fakelog, $statedir, array(&$fakelog, '_downloadCallback')); $caught = ob_get_contents(); ob_end_clean(); $firstone = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'download' . DIRECTORY_SEPARATOR . 'testdownload.tgz')); $secondone = implode('', file($statedir . DIRECTORY_SEPARATOR . 'testdownload.tgz')); $phpunit->assertNoErrors('test callback'); $phpunit->assertEquals('', $caught, 'wrong simple'); $firstone = implode('', file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'download' . DIRECTORY_SEPARATOR . 'testdownload.tgz')); $secondone = implode('', file($statedir . DIRECTORY_SEPARATOR . 'testdownload.tgz')); $phpunit->assertTrue($firstone == $secondone, 'callback files are not the same'); $phpunit->assertEquals(array(), $fakelog->getLog(), 'callback log'); $phpunit->assertEquals(array ( 0 => array ( 0 => 'setup', 1 => 'self', ), 1 => array ( 0 => 'saveas', 1 => 'testdownload.tgz', ), 2 => array ( 0 => 'start', 1 => array ( 0 => 'testdownload.tgz', 1 => '41655', ), ), 3 => array ( 0 => 'bytesread', 1 => 1024, ), 4 => array ( 0 => 'bytesread', 1 => 2048, ), 5 => array ( 0 => 'bytesread', 1 => 3072, ), 6 => array ( 0 => 'bytesread', 1 => 4096, ), 7 => array ( 0 => 'bytesread', 1 => 5120, ), 8 => array ( 0 => 'bytesread', 1 => 6144, ), 9 => array ( 0 => 'bytesread', 1 => 7168, ), 10 => array ( 0 => 'bytesread', 1 => 8192, ), 11 => array ( 0 => 'bytesread', 1 => 9216, ), 12 => array ( 0 => 'bytesread', 1 => 10240, ), 13 => array ( 0 => 'bytesread', 1 => 11264, ), 14 => array ( 0 => 'bytesread', 1 => 12288, ), 15 => array ( 0 => 'bytesread', 1 => 13312, ), 16 => array ( 0 => 'bytesread', 1 => 14336, ), 17 => array ( 0 => 'bytesread', 1 => 15360, ), 18 => array ( 0 => 'bytesread', 1 => 16384, ), 19 => array ( 0 => 'bytesread', 1 => 17408, ), 20 => array ( 0 => 'bytesread', 1 => 18432, ), 21 => array ( 0 => 'bytesread', 1 => 19456, ), 22 => array ( 0 => 'bytesread', 1 => 20480, ), 23 => array ( 0 => 'bytesread', 1 => 21504, ), 24 => array ( 0 => 'bytesread', 1 => 22528, ), 25 => array ( 0 => 'bytesread', 1 => 23552, ), 26 => array ( 0 => 'bytesread', 1 => 24576, ), 27 => array ( 0 => 'bytesread', 1 => 25600, ), 28 => array ( 0 => 'bytesread', 1 => 26624, ), 29 => array ( 0 => 'bytesread', 1 => 27648, ), 30 => array ( 0 => 'bytesread', 1 => 28672, ), 31 => array ( 0 => 'bytesread', 1 => 29696, ), 32 => array ( 0 => 'bytesread', 1 => 30720, ), 33 => array ( 0 => 'bytesread', 1 => 31744, ), 34 => array ( 0 => 'bytesread', 1 => 32768, ), 35 => array ( 0 => 'bytesread', 1 => 33792, ), 36 => array ( 0 => 'bytesread', 1 => 34816, ), 37 => array ( 0 => 'bytesread', 1 => 35840, ), 38 => array ( 0 => 'bytesread', 1 => 36864, ), 39 => array ( 0 => 'bytesread', 1 => 37888, ), 40 => array ( 0 => 'bytesread', 1 => 38912, ), 41 => array ( 0 => 'bytesread', 1 => 39936, ), 42 => array ( 0 => 'bytesread', 1 => 40960, ), 43 => array ( 0 => 'bytesread', 1 => 41655, ), 44 => array ( 0 => 'done', 1 => 41655, ), ), $fakelog->getDownload(), 'download log'); //echo "Callback fail:\n"; ob_start(); PEAR_Common::downloadHttp('http://test.poop.php.net/stuff.tgz', $ui, $statedir, array(&$fakelog, '_downloadCallback')); $caught = ob_get_contents(); ob_end_clean(); $phpunit->assertErrors(array( array('package' => 'PEAR_Error', 'message' => 'Connection to `test.poop.php.net:80\' failed: ' . ($php5 ? '' : 'The operation completed successfully.' . ($windows ? "\r\n" : "\n"))) ), 'callback fail'); $phpunit->assertEquals(array(), $fakelog->getLog(), 'callback fail log'); $testarr = array ( 0 => 'test.poop.php.net', 1 => 80, 2 => $php5 ? 8526320 : 0, 3 => ($php5 ? '' : 'The operation completed successfully.' . ($windows ? "\r\n" : "\n")), ); $phpunit->assertEquals(array ( 0 => array ( 0 => 'setup', 1 => 'self', ), 1 => array ( 0 => 'connfailed', 1 => $testarr ), ), $fakelog->getDownload(), 'download fail log'); echo 'tests done'; ?> --EXPECT-- tests done
« previous php.pear.core (#1185) next »