cvs: pear-core /tests/PEAR_Command test_registerCommands_remoteinstall.phpt /tests/PEAR_Installer/ftp_test_files FTP.php.inc
| From: | Greg Beaver | Date: | Wed, 22 Feb 2006 22:04:08 +0000 |
| Subject: | cvs: pear-core /tests/PEAR_Command test_registerCommands_remoteinstall.phpt /tests/PEAR_Installer/ftp_test_files FTP.php.inc | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-4575@lists.php.net to get a copy of this message | ||
cellog Wed Feb 22 22:04:08 2006 UTC
Modified files:
/pear-core/tests/PEAR_Command
test_registerCommands_remoteinstall.phpt
/pear-core/tests/PEAR_Installer/ftp_test_files FTP.php.inc
Log:
fix test
http://cvs.php.net/viewcvs.cgi/pear-core/tests/PEAR_Command/test_registerCommands_remoteinstall.phpt?r1=1.4&r2=1.5&diff_format=u Index: pear-core/tests/PEAR_Command/test_registerCommands_remoteinstall.phpt diff -u pear-core/tests/PEAR_Command/test_registerCommands_remoteinstall.phpt:1.4 pear-core/tests/PEAR_Command/test_registerCommands_remoteinstall.phpt:1.5 --- pear-core/tests/PEAR_Command/test_registerCommands_remoteinstall.phpt:1.4 Fri Feb 3 05:07:19 2006 +++ pear-core/tests/PEAR_Command/test_registerCommands_remoteinstall.phpt Wed Feb 22 22:04:08 2006 @@ -193,7 +193,7 @@ $phpunit->assertEquals('', $s, 'short info'); $phpunit->assertEquals(array(), $l, 'long info'); PEAR_Command::getGetoptArgs('install', $s, $l); -$phpunit->assertEquals('flnrsBZR:aoOp', $s, 'short install'); +$phpunit->assertEquals('flnrsBZR:P:aoOp', $s, 'short install'); $phpunit->assertEquals(array ( 0 => 'force', 1 => 'loose', @@ -203,11 +203,12 @@ 5 => 'nobuild', 6 => 'nocompress', 7 => 'installroot=', - 8 => 'ignore-errors', - 9 => 'alldeps', - 10 => 'onlyreqdeps', - 11 => 'offline', - 12 => 'pretend', + 'packagingroot=', + 'ignore-errors', + 'alldeps', + 'onlyreqdeps', + 'offline', + 'pretend', ), $l, 'long install'); PEAR_Command::getGetoptArgs('list', $s, $l); $phpunit->assertEquals('c:a', $s, 'short list'); @@ -310,8 +311,8 @@ 6 => 'remoteconfig=', ), $l, 'long remote-upgrade-all'); PEAR_Command::getGetoptArgs('run-tests', $s, $l); -$phpunit->assertEquals('ri:lqsp', $s, 'short run-tests'); -$phpunit->assertEquals(array ('recur', 'ini=', 'realtimelog', 'quiet', 'simple', 'package'), $l, 'long run-tests'); +$phpunit->assertEquals('ri:lqspu', $s, 'short run-tests'); +$phpunit->assertEquals(array ('recur', 'ini=', 'realtimelog', 'quiet', 'simple', 'package', 'phpunit'), $l, 'long run-tests'); PEAR_Command::getGetoptArgs('search', $s, $l); $phpunit->assertEquals('c:', $s, 'short search'); $phpunit->assertEquals(array ('channel='), $l, 'long search'); @@ -334,7 +335,7 @@ $phpunit->assertEquals('', $s, 'short update-channels'); $phpunit->assertEquals(array (), $l, 'long update-channels'); PEAR_Command::getGetoptArgs('upgrade', $s, $l); -$phpunit->assertEquals('flnrBZR:aoOp', $s, 'short upgrade'); +$phpunit->assertEquals('flnrBZR:P:aoOp', $s, 'short upgrade'); $phpunit->assertEquals(array ( 0 => 'force', 1 => 'loose', @@ -343,11 +344,12 @@ 4 => 'nobuild', 5 => 'nocompress', 6 => 'installroot=', - 7 => 'ignore-errors', - 8 => 'alldeps', - 9 => 'onlyreqdeps', - 10 => 'offline', - 11 => 'pretend', + 'packagingroot=', + 'ignore-errors', + 'alldeps', + 'onlyreqdeps', + 'offline', + 'pretend', ), $l, 'long upgrade'); PEAR_Command::getGetoptArgs('upgrade-all', $s, $l); $phpunit->assertEquals('nrBZR:', $s, 'short upgrade-all'); http://cvs.php.net/viewcvs.cgi/pear-core/tests/PEAR_Installer/ftp_test_files/FTP.php.inc?r1=1.1&r2=1.2&diff_format=u Index: pear-core/tests/PEAR_Installer/ftp_test_files/FTP.php.inc diff -u pear-core/tests/PEAR_Installer/ftp_test_files/FTP.php.inc:1.1 pear-core/tests/PEAR_Installer/ftp_test_files/FTP.php.inc:1.2 --- pear-core/tests/PEAR_Installer/ftp_test_files/FTP.php.inc:1.1 Wed Dec 29 06:19:12 2004 +++ pear-core/tests/PEAR_Installer/ftp_test_files/FTP.php.inc Wed Feb 22 22:04:08 2006 @@ -171,4 +171,166 @@ $f->_dirsExisting = array_flip($dirs); } } +require_once 'PEAR/RemoteInstaller.php'; +class test_PEAR_RemoteInstaller extends PEAR_RemoteInstaller { + function download($packages, $options, &$config, &$installpackages, + &$errors, $installed = false, $willinstall = false, $state = false) + { + // trickiness: initialize here + $this->PEAR_Downloader($this->ui, $options, $config); + $this->_remote = &new test_PEAR_Remote($config); + $ret = PEAR_Downloader::download($packages); + $errors = $this->getErrorMsgs(); + $installpackages = $this->getDownloadedPackages(); + trigger_error("PEAR Warning: PEAR_Installer::download() is deprecated " . + "in favor of PEAR_Downloader class", E_USER_WARNING); + return $ret; + } + + /** + * For simpler unit-testing + * @param PEAR_Config + * @param int + * @param string + */ + function &getPackagefileObject(&$c, $d, $dir = null) + { + $a = &new test_PEAR_PackageFile($c, $d, $dir); + return $a; + } + + function downloadHttp($url, &$ui, $save_dir = '.', $callback = null) + { +// return parent::downloadHttp($url, $ui, $save_dir, $callback); + if ($callback) { + call_user_func($callback, 'setup', array(&$ui)); + } + $info = parse_url($url); + if (!isset($info['scheme']) || $info['scheme'] != 'http') { + return PEAR::raiseError('Cannot download non-http URL "' . $url . '"'); + } + if (!isset($info['host'])) { + return PEAR::raiseError('Cannot download from non-URL "' . $url . '"'); + } else { + $host = @$info['host']; + $port = @$info['port']; + $path = @$info['path']; + } + if (isset($this)) { + $config = &$this->config; + } else { + $config = &PEAR_Config::singleton(); + } + $proxy_host = $proxy_port = $proxy_user = $proxy_pass = ''; + if ($proxy = parse_url($config->get('http_proxy'))) { + $proxy_host = @$proxy['host']; + $proxy_port = @$proxy['port']; + $proxy_user = @$proxy['user']; + $proxy_pass = @$proxy['pass']; + + if ($proxy_port == '') { + $proxy_port = 8080; + } + if ($callback) { + call_user_func($callback, 'message', "Using HTTP proxy $host:$port"); + } + } + if (empty($port)) { + $port = 80; + } + // use _pearweb to get file + $retrieved = explode("\n", $this->_remote->_pearweb->receiveHttp($url)); + $headers = array(); + $line = array_shift($retrieved); + while (strlen(trim($line))) { + if (preg_match('/^([^:]+):\s+(.*)\s*$/', $line, $matches)) { + $headers[strtolower($matches[1])] = trim($matches[2]); + } elseif (preg_match('|^HTTP/1.[01] ([0-9]{3}) |', $line, $matches)) { + if ($matches[1] != 200) { + return PEAR::raiseError("File http://$host:$port$path not valid (received: $line)"); + } + } + $line = array_shift($retrieved); + } + $retrieved = join("\n", $retrieved); + if (isset($headers['content-disposition']) && + preg_match('/\sfilename=\"([^;]*\S)\"\s*(;|$)/', $headers['content-disposition'], $matches)) { + $save_as = basename($matches[1]); + } else { + $save_as = basename($url); + } + if ($callback) { + $tmp = call_user_func($callback, 'saveas', $save_as); + if ($tmp) { + $save_as = $tmp; + } + } + $dest_file = $save_dir . DIRECTORY_SEPARATOR . $save_as; + if (!$wp = @fopen($dest_file, 'wb')) { + fclose($fp); + if ($callback) { + call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg)); + } + return PEAR::raiseError("could not open $dest_file for writing"); + } + if (isset($headers['content-length'])) { + $length = $headers['content-length']; + } else { + $length = -1; + } + $bytes = 0; + if ($callback) { + call_user_func($callback, 'start', array(basename($dest_file), $length)); + } + $start = 0; + while ($start < strlen($retrieved) - 1) { + $data = substr($retrieved, $start, 1024); + $start += 1024; + $bytes += strlen($data); + if ($callback) { + call_user_func($callback, 'bytesread', $bytes); + } + if (!@fwrite($wp, $data)) { + if ($callback) { + call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg)); + } + return PEAR::raiseError("$dest_file: write failed ($php_errormsg)"); + } + } + fclose($wp); + if ($callback) { + call_user_func($callback, 'done', $bytes); + } + return $dest_file; + } + + function log($level, $msg) + { + global $fakelog; + if (isset($fakelog)) { + $fakelog->log($level, $msg); + } else { + return parent::log($level, $msg); + } + } + + function &getDependency2($c, $i, $p, $s) + { + $a = &test_PEAR_Dependency2::singleton($c, $i, $p, $s); + return $a; + } + + /** + * For simpler unit-testing + * @param PEAR_Config + * @param array + * @param array + * @param int + */ + function &getDependency2Object(&$c, $i, $p, $s) + { + $z = &test_PEAR_Dependency2::singleton($c, $i, $p, $s); + return $z; + } +} ?> \ No newline at end of file
http://cvs.php.net/viewcvs.cgi/pear-core/tests/PEAR_Command/test_registerCommands_remoteinstall.phpt?r1=1.4&r2=1.5&diff_format=u Index: pear-core/tests/PEAR_Command/test_registerCommands_remoteinstall.phpt diff -u pear-core/tests/PEAR_Command/test_registerCommands_remoteinstall.phpt:1.4 pear-core/tests/PEAR_Command/test_registerCommands_remoteinstall.phpt:1.5 --- pear-core/tests/PEAR_Command/test_registerCommands_remoteinstall.phpt:1.4 Fri Feb 3 05:07:19 2006 +++ pear-core/tests/PEAR_Command/test_registerCommands_remoteinstall.phpt Wed Feb 22 22:04:08 2006 @@ -193,7 +193,7 @@ $phpunit->assertEquals('', $s, 'short info'); $phpunit->assertEquals(array(), $l, 'long info'); PEAR_Command::getGetoptArgs('install', $s, $l); -$phpunit->assertEquals('flnrsBZR:aoOp', $s, 'short install'); +$phpunit->assertEquals('flnrsBZR:P:aoOp', $s, 'short install'); $phpunit->assertEquals(array ( 0 => 'force', 1 => 'loose', @@ -203,11 +203,12 @@ 5 => 'nobuild', 6 => 'nocompress', 7 => 'installroot=', - 8 => 'ignore-errors', - 9 => 'alldeps', - 10 => 'onlyreqdeps', - 11 => 'offline', - 12 => 'pretend', + 'packagingroot=', + 'ignore-errors', + 'alldeps', + 'onlyreqdeps', + 'offline', + 'pretend', ), $l, 'long install'); PEAR_Command::getGetoptArgs('list', $s, $l); $phpunit->assertEquals('c:a', $s, 'short list'); @@ -310,8 +311,8 @@ 6 => 'remoteconfig=', ), $l, 'long remote-upgrade-all'); PEAR_Command::getGetoptArgs('run-tests', $s, $l); -$phpunit->assertEquals('ri:lqsp', $s, 'short run-tests'); -$phpunit->assertEquals(array ('recur', 'ini=', 'realtimelog', 'quiet', 'simple', 'package'), $l, 'long run-tests'); +$phpunit->assertEquals('ri:lqspu', $s, 'short run-tests'); +$phpunit->assertEquals(array ('recur', 'ini=', 'realtimelog', 'quiet', 'simple', 'package', 'phpunit'), $l, 'long run-tests'); PEAR_Command::getGetoptArgs('search', $s, $l); $phpunit->assertEquals('c:', $s, 'short search'); $phpunit->assertEquals(array ('channel='), $l, 'long search'); @@ -334,7 +335,7 @@ $phpunit->assertEquals('', $s, 'short update-channels'); $phpunit->assertEquals(array (), $l, 'long update-channels'); PEAR_Command::getGetoptArgs('upgrade', $s, $l); -$phpunit->assertEquals('flnrBZR:aoOp', $s, 'short upgrade'); +$phpunit->assertEquals('flnrBZR:P:aoOp', $s, 'short upgrade'); $phpunit->assertEquals(array ( 0 => 'force', 1 => 'loose', @@ -343,11 +344,12 @@ 4 => 'nobuild', 5 => 'nocompress', 6 => 'installroot=', - 7 => 'ignore-errors', - 8 => 'alldeps', - 9 => 'onlyreqdeps', - 10 => 'offline', - 11 => 'pretend', + 'packagingroot=', + 'ignore-errors', + 'alldeps', + 'onlyreqdeps', + 'offline', + 'pretend', ), $l, 'long upgrade'); PEAR_Command::getGetoptArgs('upgrade-all', $s, $l); $phpunit->assertEquals('nrBZR:', $s, 'short upgrade-all'); http://cvs.php.net/viewcvs.cgi/pear-core/tests/PEAR_Installer/ftp_test_files/FTP.php.inc?r1=1.1&r2=1.2&diff_format=u Index: pear-core/tests/PEAR_Installer/ftp_test_files/FTP.php.inc diff -u pear-core/tests/PEAR_Installer/ftp_test_files/FTP.php.inc:1.1 pear-core/tests/PEAR_Installer/ftp_test_files/FTP.php.inc:1.2 --- pear-core/tests/PEAR_Installer/ftp_test_files/FTP.php.inc:1.1 Wed Dec 29 06:19:12 2004 +++ pear-core/tests/PEAR_Installer/ftp_test_files/FTP.php.inc Wed Feb 22 22:04:08 2006 @@ -171,4 +171,166 @@ $f->_dirsExisting = array_flip($dirs); } } +require_once 'PEAR/RemoteInstaller.php'; +class test_PEAR_RemoteInstaller extends PEAR_RemoteInstaller { + function download($packages, $options, &$config, &$installpackages, + &$errors, $installed = false, $willinstall = false, $state = false) + { + // trickiness: initialize here + $this->PEAR_Downloader($this->ui, $options, $config); + $this->_remote = &new test_PEAR_Remote($config); + $ret = PEAR_Downloader::download($packages); + $errors = $this->getErrorMsgs(); + $installpackages = $this->getDownloadedPackages(); + trigger_error("PEAR Warning: PEAR_Installer::download() is deprecated " . + "in favor of PEAR_Downloader class", E_USER_WARNING); + return $ret; + } + + /** + * For simpler unit-testing + * @param PEAR_Config + * @param int + * @param string + */ + function &getPackagefileObject(&$c, $d, $dir = null) + { + $a = &new test_PEAR_PackageFile($c, $d, $dir); + return $a; + } + + function downloadHttp($url, &$ui, $save_dir = '.', $callback = null) + { +// return parent::downloadHttp($url, $ui, $save_dir, $callback); + if ($callback) { + call_user_func($callback, 'setup', array(&$ui)); + } + $info = parse_url($url); + if (!isset($info['scheme']) || $info['scheme'] != 'http') { + return PEAR::raiseError('Cannot download non-http URL "' . $url . '"'); + } + if (!isset($info['host'])) { + return PEAR::raiseError('Cannot download from non-URL "' . $url . '"'); + } else { + $host = @$info['host']; + $port = @$info['port']; + $path = @$info['path']; + } + if (isset($this)) { + $config = &$this->config; + } else { + $config = &PEAR_Config::singleton(); + } + $proxy_host = $proxy_port = $proxy_user = $proxy_pass = ''; + if ($proxy = parse_url($config->get('http_proxy'))) { + $proxy_host = @$proxy['host']; + $proxy_port = @$proxy['port']; + $proxy_user = @$proxy['user']; + $proxy_pass = @$proxy['pass']; + + if ($proxy_port == '') { + $proxy_port = 8080; + } + if ($callback) { + call_user_func($callback, 'message', "Using HTTP proxy $host:$port"); + } + } + if (empty($port)) { + $port = 80; + } + // use _pearweb to get file + $retrieved = explode("\n", $this->_remote->_pearweb->receiveHttp($url)); + $headers = array(); + $line = array_shift($retrieved); + while (strlen(trim($line))) { + if (preg_match('/^([^:]+):\s+(.*)\s*$/', $line, $matches)) { + $headers[strtolower($matches[1])] = trim($matches[2]); + } elseif (preg_match('|^HTTP/1.[01] ([0-9]{3}) |', $line, $matches)) { + if ($matches[1] != 200) { + return PEAR::raiseError("File http://$host:$port$path not valid (received: $line)"); + } + } + $line = array_shift($retrieved); + } + $retrieved = join("\n", $retrieved); + if (isset($headers['content-disposition']) && + preg_match('/\sfilename=\"([^;]*\S)\"\s*(;|$)/', $headers['content-disposition'], $matches)) { + $save_as = basename($matches[1]); + } else { + $save_as = basename($url); + } + if ($callback) { + $tmp = call_user_func($callback, 'saveas', $save_as); + if ($tmp) { + $save_as = $tmp; + } + } + $dest_file = $save_dir . DIRECTORY_SEPARATOR . $save_as; + if (!$wp = @fopen($dest_file, 'wb')) { + fclose($fp); + if ($callback) { + call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg)); + } + return PEAR::raiseError("could not open $dest_file for writing"); + } + if (isset($headers['content-length'])) { + $length = $headers['content-length']; + } else { + $length = -1; + } + $bytes = 0; + if ($callback) { + call_user_func($callback, 'start', array(basename($dest_file), $length)); + } + $start = 0; + while ($start < strlen($retrieved) - 1) { + $data = substr($retrieved, $start, 1024); + $start += 1024; + $bytes += strlen($data); + if ($callback) { + call_user_func($callback, 'bytesread', $bytes); + } + if (!@fwrite($wp, $data)) { + if ($callback) { + call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg)); + } + return PEAR::raiseError("$dest_file: write failed ($php_errormsg)"); + } + } + fclose($wp); + if ($callback) { + call_user_func($callback, 'done', $bytes); + } + return $dest_file; + } + + function log($level, $msg) + { + global $fakelog; + if (isset($fakelog)) { + $fakelog->log($level, $msg); + } else { + return parent::log($level, $msg); + } + } + + function &getDependency2($c, $i, $p, $s) + { + $a = &test_PEAR_Dependency2::singleton($c, $i, $p, $s); + return $a; + } + + /** + * For simpler unit-testing + * @param PEAR_Config + * @param array + * @param array + * @param int + */ + function &getDependency2Object(&$c, $i, $p, $s) + { + $z = &test_PEAR_Dependency2::singleton($c, $i, $p, $s); + return $z; + } +} ?> \ No newline at end of file