summaryrefslogtreecommitdiff
path: root/pear/tests/pear_dependency_checkPackage.phpt
blob: 90dfb556f6c2eb0f0eaaff95ad91d34e32b1c361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
--TEST--
PEAR_Dependency::checkPackage() test
--SKIPIF--
<?php
if (!getenv('PHP_PEAR_RUNTESTS')) {
    echo 'skip';
}
?>
--FILE--
<?php
require_once "PEAR/Registry.php";
require_once "PEAR/Dependency.php";

mkdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp');
// snarfed from pear_registry.phpt
$reg = new PEAR_Registry;
$reg->statedir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp';

$files1 = array(
    "pkg1-1.php" => array(
        "role" => "php",
        ),
    "pkg1-2.php" => array(
        "role" => "php",
        "baseinstalldir" => "pkg1",
        ),
    );
$reg->addPackage("pkg1", array("name" => "pkg1", "version" => "1.0", "filelist" => $files1));

$dep = new PEAR_Dependency($reg);
$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1');
echo 'has works? ';
echo $ret ? "no\n" : "yes\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'eq');
echo 'eq 1.0 works? ';
echo $ret ? "no\n" : "yes\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'le');
echo 'le 1.0 works? ';
echo $ret ? "no\n" : "yes\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '1.1', 'lt');
echo 'lt 1.1 works? ';
echo $ret ? "no\n" : "yes\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '1.1', 'ne');
echo 'ne 1.1 works? ';
echo $ret ? "no\n" : "yes\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'ge');
echo 'ge 1.0 works? ';
echo $ret ? "no\n" : "yes\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '0.9', 'gt');
echo 'ge 0.9 works? ';
echo $ret ? "no\n" : "yes\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg2', null, 'not');
echo 'not pkg2 works? ';
echo $ret ? "no\n" : "yes\n";
echo $msg . "\n";

// error conditions

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg2', null, 'has');
echo 'has pkg2 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_MISSING? ';
echo ($ret == PEAR_DEPENDENCY_MISSING) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg2', null, 'has', true);
echo 'has optional pkg2 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_MISSING_OPTIONAL? ';
echo ($ret == PEAR_DEPENDENCY_MISSING_OPTIONAL) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '0.9', 'le');
echo 'le 0.9 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_CONFLICT? ';
echo ($ret == PEAR_DEPENDENCY_CONFLICT) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '0.9', 'le', true);
echo 'optional le 0.9 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_CONFLICT_OPTIONAL? ';
echo ($ret == PEAR_DEPENDENCY_CONFLICT_OPTIONAL) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'ne');
echo 'ne 1.0 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_CONFLICT? ';
echo ($ret == PEAR_DEPENDENCY_CONFLICT) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'ne', true);
echo 'optional ne 1.0 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_CONFLICT_OPTIONAL? ';
echo ($ret == PEAR_DEPENDENCY_CONFLICT_OPTIONAL) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '1.1', 'ge');
echo 'ge 1.1 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_UPGRADE_MINOR? ';
echo ($ret == PEAR_DEPENDENCY_UPGRADE_MINOR) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '1.1', 'ge', true);
echo 'optional ge 1.1 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL? ';
echo ($ret == PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '2.0', 'ge');
echo 'ge 2.0 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_UPGRADE_MAJOR? ';
echo ($ret == PEAR_DEPENDENCY_UPGRADE_MAJOR) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '2.0', 'ge', true);
echo 'optional ge 2.0 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_UPGRADE_MAJOR_OPTIONAL? ';
echo ($ret == PEAR_DEPENDENCY_UPGRADE_MAJOR_OPTIONAL) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'gt');
echo 'gt 1.0 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_UPGRADE_MINOR? ';
echo ($ret == PEAR_DEPENDENCY_UPGRADE_MINOR) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', '1.0', 'gt', true);
echo 'optional gt 1.0 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL? ';
echo ($ret == PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', null, 'not');
echo 'not pkg1 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_CONFLICT? ';
echo ($ret == PEAR_DEPENDENCY_CONFLICT) ? "yes\n" : "no\n";
echo $msg . "\n";

$msg = 'no error';
$ret = $dep->checkPackage($msg, 'pkg1', null, 'foobar');
echo 'foobar pkg1 works? ';
echo $ret ? "no\n" : "yes\n";
echo '$ret is PEAR_DEPENDENCY_BAD_DEPENDENCY? ';
echo ($ret == PEAR_DEPENDENCY_BAD_DEPENDENCY) ? "yes\n" : "no\n";
echo $msg . "\n";
cleanall();

// ------------------------------------------------------------------------- //

function cleanall()
{
    $dp = opendir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp');
    while ($ent = readdir($dp)) {
        if (substr($ent, -4) == ".reg") {
            unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp' . DIRECTORY_SEPARATOR . $ent);
        }
    }
    closedir($dp);
    rmdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'checkPackagetmp');
}

?>
--EXPECT--
has works? yes
no error
eq 1.0 works? yes
no error
le 1.0 works? yes
no error
lt 1.1 works? yes
no error
ne 1.1 works? yes
no error
ge 1.0 works? yes
no error
ge 0.9 works? yes
no error
not pkg2 works? yes
no error
has pkg2 works? no
$ret is PEAR_DEPENDENCY_MISSING? yes
requires package `pear::pkg2'
has optional pkg2 works? no
$ret is PEAR_DEPENDENCY_MISSING_OPTIONAL? yes
package `pear::pkg2' is recommended to utilize some features.
le 0.9 works? no
$ret is PEAR_DEPENDENCY_CONFLICT? yes
requires package `pear::pkg1' <= 0.9
optional le 0.9 works? no
$ret is PEAR_DEPENDENCY_CONFLICT_OPTIONAL? yes
package `pear::pkg1' version <= 0.9 is recommended to utilize some features.  Installed version is 1.0
ne 1.0 works? no
$ret is PEAR_DEPENDENCY_CONFLICT? yes
requires package `pear::pkg1' != 1.0
optional ne 1.0 works? no
$ret is PEAR_DEPENDENCY_CONFLICT_OPTIONAL? yes
package `pear::pkg1' version != 1.0 is recommended to utilize some features.  Installed version is 1.0
ge 1.1 works? no
$ret is PEAR_DEPENDENCY_UPGRADE_MINOR? yes
requires package `pear::pkg1' >= 1.1
optional ge 1.1 works? no
$ret is PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL? yes
package `pear::pkg1' version >= 1.1 is recommended to utilize some features.  Installed version is 1.0
ge 2.0 works? no
$ret is PEAR_DEPENDENCY_UPGRADE_MAJOR? yes
requires package `pear::pkg1' >= 2.0
optional ge 2.0 works? no
$ret is PEAR_DEPENDENCY_UPGRADE_MAJOR_OPTIONAL? yes
package `pear::pkg1' version >= 2.0 is recommended to utilize some features.  Installed version is 1.0
gt 1.0 works? no
$ret is PEAR_DEPENDENCY_UPGRADE_MINOR? yes
requires package `pear::pkg1' > 1.0
optional gt 1.0 works? no
$ret is PEAR_DEPENDENCY_UPGRADE_MINOR_OPTIONAL? yes
package `pear::pkg1' version > 1.0 is recommended to utilize some features.  Installed version is 1.0
not pkg1 works? no
$ret is PEAR_DEPENDENCY_CONFLICT? yes
conflicts with package `pear::pkg1'
foobar pkg1 works? no
$ret is PEAR_DEPENDENCY_BAD_DEPENDENCY? yes
relation 'foobar' with requirement '' is not supported (name=pear::pkg1)