* PEAR_Registry: renamed "upgradePackage" to "updatePackage"

* added tests for PEAR_Config and PEAR_Registry
This commit is contained in:
Stig Bakken 2001-10-29 12:17:37 +00:00
parent f8055473a4
commit b60aedc275
5 changed files with 184 additions and 6 deletions

View File

@ -19,7 +19,7 @@
//
// $Id$
require_once "Experimental/System.php";
require_once "System.php";
/**
* Administration class used to maintain the installed package database.
@ -97,7 +97,13 @@ class PEAR_Registry
if ($this->packageExists($package)) {
return false;
}
return $this->upgradePackage($package, $info);
$fp = $this->_openPackageFile($package, "w");
if ($fp === null) {
return false;
}
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
return true;
}
// }}}
@ -110,6 +116,9 @@ class PEAR_Registry
$this->listPackages());
}
$fp = $this->_openPackageFile($package, "r");
if ($fp === null) {
return null;
}
$data = fread($fp, filesize($this->_packageFileName($package)));
$this->_closePackageFile($fp);
return unserialize($data);
@ -121,19 +130,23 @@ class PEAR_Registry
function deletePackage($package)
{
$file = $this->_packageFileName($package);
unlink($file);
return @unlink($file);
}
// }}}
// {{{ upgradePackage()
// {{{ updatePackage()
function upgradePackage($package, $info)
function updatePackage($package, $info)
{
$oldinfo = $this->packageInfo($package);
if (empty($oldinfo)) {
return false;
}
$fp = $this->_openPackageFile($package, "w");
if ($fp === null) {
return false;
}
fwrite($fp, serialize($info));
fwrite($fp, serialize(array_merge($oldinfo, $info)));
$this->_closePackageFile($fp);
return true;
}

View File

@ -0,0 +1,72 @@
--TEST--
PEAR_Config
--FILE--
<?php
error_reporting(E_ALL);
include "../PEAR/Config.php";
copy("system.input", "system.conf");
copy("user.input", "user.conf");
PEAR::setErrorHandling(PEAR_ERROR_DIE, "%s\n");
dumpall();
print "creating config object\n";
$config = new PEAR_Config("user.conf", "system.conf");
// overriding system values
$config->set("master_server", "pear.localdomain");
$config->writeConfigFile();
dumpall();
var_dump($config->get("master_server"));
// going back to defaults
$config->toDefault("master_server");
$config->writeConfigFile();
dumpall();
//
print "done\n";
unlink("user.conf");
unlink("system.conf");
// ------------------------------------------------------------------------- //
function dumpit($file)
{
$fp = fopen($file, "r");
print "$file:";
$data = unserialize(fread($fp, filesize($file)));
fclose($fp);
if (!is_array($data)) {
print " <empty>\n";
return;
}
foreach ($data as $k => $v) {
print " $k=\"$v\"";
}
print "\n";
}
function dumpall()
{
print "dumping...\n";
dumpit("system.conf");
dumpit("user.conf");
}
?>
--EXPECT--
dumping...
system.conf: master_server="pear.php.net"
user.conf: <empty>
creating config object
dumping...
system.conf: master_server="pear.php.net"
user.conf: master_server="pear.localdomain"
string(16) "pear.localdomain"
dumping...
system.conf: master_server="pear.php.net"
user.conf:
done

View File

@ -0,0 +1,92 @@
--TEST--
PEAR_Registry
--FILE--
<?php
error_reporting(E_ALL);
include "../PEAR/Registry.php";
PEAR::setErrorHandling(PEAR_ERROR_DIE, "%s\n");
cleanall();
print "creating registry object\n";
$reg = new PEAR_Registry;
$reg->statedir = getcwd();
dumpall($reg);
$reg->addPackage("pkg1", array("name" => "pkg1", "version" => "1.0"));
dumpall($reg);
$reg->addPackage("pkg2", array("name" => "pkg2", "version" => "2.0"));
$reg->addPackage("pkg3", array("name" => "pkg3", "version" => "3.0"));
dumpall($reg);
$reg->updatePackage("pkg2", array("version" => "2.1"));
dumpall($reg);
var_dump($reg->deletePackage("pkg2"));
dumpall($reg);
var_dump($reg->deletePackage("pkg2"));
dumpall($reg);
$reg->updatePackage("pkg3", array("version" => "3.1b1", "status" => "beta"));
dumpall($reg);
print "tests done\n";
cleanall();
// ------------------------------------------------------------------------- //
function cleanall()
{
$dp = opendir(".");
while ($ent = readdir($dp)) {
if (substr($ent, -4) == ".inf") {
unlink($ent);
}
}
}
function dumpall(&$reg)
{
print "dumping registry...\n";
$info = $reg->packageInfo();
foreach ($info as $pkg) {
print $pkg["name"] . ":";
unset($pkg["name"]);
foreach ($pkg as $k => $v) {
print " $k=\"$v\"";
}
print "\n";
}
print "dump done\n";
}
?>
--EXPECT--
creating registry object
dumping registry...
dump done
dumping registry...
pkg1: version="1.0"
dump done
dumping registry...
pkg1: version="1.0"
pkg2: version="2.0"
pkg3: version="3.0"
dump done
dumping registry...
pkg1: version="1.0"
pkg2: version="2.1"
pkg3: version="3.0"
dump done
bool(true)
dumping registry...
pkg1: version="1.0"
pkg3: version="3.0"
dump done
bool(false)
dumping registry...
pkg1: version="1.0"
pkg3: version="3.0"
dump done
dumping registry...
pkg1: version="1.0"
pkg3: version="3.1b1" status="beta"
dump done
tests done

1
pear/tests/system.input Normal file
View File

@ -0,0 +1 @@
a:1:{s:13:"master_server";s:12:"pear.php.net";}

0
pear/tests/user.input Normal file
View File