xref: /PHP-8.1/ext/phar/tests/badparameters.phpt (revision 74859783)
1--TEST--
2Phar: bad parameters to various methods
3--EXTENSIONS--
4phar
5--INI--
6phar.readonly=0
7--FILE--
8<?php
9ini_set('phar.readonly', 1);
10
11try {
12    Phar::mungServer('hi');
13} catch (TypeError $e) {
14    echo $e->getMessage(), "\n";
15}
16try {
17    Phar::createDefaultStub(array());
18} catch (TypeError $e) {
19    echo $e->getMessage(), "\n";
20}
21try {
22    Phar::loadPhar(array());
23} catch (TypeError $e) {
24    echo $e->getMessage(), "\n";
25}
26try {
27    Phar::canCompress('hi');
28} catch (TypeError $e) {
29    echo $e->getMessage(), "\n";
30}
31try {
32    $a = new Phar(array());
33} catch (TypeError $e) {
34    echo $e->getMessage(), "\n";
35}
36try {
37    $a = new Phar(__DIR__ . '/files/frontcontroller10.phar');
38} catch (PharException $e) {
39    echo $e->getMessage(), "\n";
40}
41try {
42    $a->convertToExecutable(array());
43} catch (TypeError $e) {
44    echo $e->getMessage(), "\n";
45}
46try {
47    $a->convertToData(array());
48} catch (TypeError $e) {
49    echo $e->getMessage(), "\n";
50}
51try {
52    $b = new PharData(__DIR__ . '/whatever.tar');
53} catch (PharException $e) {
54    echo $e->getMessage(), "\n";
55}
56try {
57    $c = new PharData(__DIR__ . '/whatever.zip');
58} catch (PharException $e) {
59    echo $e->getMessage(), "\n";
60}
61try {
62    $b->delete(array());
63} catch (TypeError $e) {
64    echo $e->getMessage(), "\n";
65}
66try {
67    $a->delete('oops');
68} catch (Exception $e) {
69    echo $e->getMessage() . "\n";
70}
71try {
72    $b->delete('oops');
73} catch (Exception $e) {
74    echo $e->getMessage() . "\n";
75}
76try {
77    echo $a->getPath() . "\n";
78} catch (TypeError $e) {
79    echo $e->getMessage(), "\n";
80}
81try {
82    $a->setAlias('oops');
83} catch (Exception $e) {
84    echo $e->getMessage() . "\n";
85}
86try {
87    $b->setAlias('oops');
88} catch (Exception $e) {
89    echo $e->getMessage() . "\n";
90}
91ini_set('phar.readonly', 0);
92try {
93    $a->setAlias(array());
94} catch (TypeError $e) {
95    echo $e->getMessage(), "\n";
96}
97ini_set('phar.readonly', 1);
98try {
99    $b->stopBuffering();
100} catch (Exception $e) {
101    echo $e->getMessage() . "\n";
102}
103try {
104    $a->setStub('oops');
105} catch (Exception $e) {
106    echo $e->getMessage() . "\n";
107}
108try {
109    $b->setStub('oops');
110} catch (Exception $e) {
111    echo $e->getMessage() . "\n";
112}
113ini_set('phar.readonly', 0);
114try {
115    $a->setStub(array());
116} catch (TypeError $e) {
117    echo $e->getMessage(), "\n";
118}
119ini_set('phar.readonly', 1);
120try {
121    $b->setDefaultStub('oops');
122} catch (Exception $e) {
123    echo $e->getMessage() . "\n";
124}
125try {
126    $a->setDefaultStub(array());
127} catch (TypeError $e) {
128    echo $e->getMessage(), "\n";
129}
130try {
131    $a->setDefaultStub('oops');
132} catch (Exception $e) {
133    echo $e->getMessage() . "\n";
134}
135try {
136    $a->setSignatureAlgorithm(Phar::MD5);
137} catch (Exception $e) {
138    echo $e->getMessage() . "\n";
139}
140try {
141    $a->compress(array());
142} catch (TypeError $e) {
143    echo $e->getMessage(), "\n";
144}
145try {
146    $a->compress(1);
147} catch (Exception $e) {
148    echo $e->getMessage() . "\n";
149}
150try {
151    $a->compressFiles(array());
152} catch (TypeError $e) {
153    echo $e->getMessage(), "\n";
154}
155try {
156    $a->decompressFiles();
157} catch (Exception $e) {
158    echo $e->getMessage() . "\n";
159}
160try {
161    $a->copy(array());
162} catch (TypeError $e) {
163    echo $e->getMessage(), "\n";
164}
165try {
166    $a->copy('a', 'b');
167} catch (Exception $e) {
168    echo $e->getMessage() . "\n";
169}
170try {
171    $a->offsetExists(array());
172} catch (TypeError $e) {
173    echo $e->getMessage(), "\n";
174}
175try {
176    $a->offsetGet(array());
177} catch (TypeError $e) {
178    echo $e->getMessage(), "\n";
179}
180ini_set('phar.readonly', 0);
181try {
182    $a->offsetSet(array());
183} catch (TypeError $e) {
184    echo $e->getMessage(), "\n";
185}
186ini_set('phar.readonly', 1);
187try {
188    $b->offsetUnset(array());
189} catch (TypeError $e) {
190    echo $e->getMessage(), "\n";
191}
192try {
193    $a->offsetUnset('a');
194} catch (Exception $e) {
195    echo $e->getMessage() . "\n";
196}
197try {
198    $a->addEmptyDir(array());
199} catch (TypeError $e) {
200    echo $e->getMessage(), "\n";
201}
202try {
203    $a->addFile(array());
204} catch (TypeError $e) {
205    echo $e->getMessage(), "\n";
206}
207try {
208    $a->addFromString(array());
209} catch (TypeError $e) {
210    echo $e->getMessage(), "\n";
211}
212try {
213    $a->setMetadata('a');
214} catch (Exception $e) {
215    echo $e->getMessage() . "\n";
216}
217ini_set('phar.readonly', 0);
218try {
219    $a->setMetadata(1,2);
220} catch (TypeError $e) {
221    echo $e->getMessage(), "\n";
222}
223ini_set('phar.readonly', 1);
224try {
225    $a->delMetadata();
226} catch (Exception $e) {
227    echo $e->getMessage() . "\n";
228}
229?>
230--EXPECTF--
231Phar::mungServer(): Argument #1 ($variables) must be of type array, string given
232Phar::createDefaultStub(): Argument #1 ($index) must be of type ?string, array given
233Phar::loadPhar(): Argument #1 ($filename) must be of type string, array given
234Phar::canCompress(): Argument #1 ($compression) must be of type int, string given
235Phar::__construct(): Argument #1 ($filename) must be of type string, array given
236Phar::convertToExecutable(): Argument #1 ($format) must be of type ?int, array given
237Phar::convertToData(): Argument #1 ($format) must be of type ?int, array given
238PharData::delete(): Argument #1 ($localName) must be of type string, array given
239Cannot write out phar archive, phar is read-only
240Entry oops does not exist and cannot be deleted
241%sfrontcontroller10.phar
242Cannot write out phar archive, phar is read-only
243A Phar alias cannot be set in a plain tar archive
244Phar::setAlias(): Argument #1 ($alias) must be of type string, array given
245Cannot change stub, phar is read-only
246A Phar stub cannot be set in a plain tar archive
247Phar::setStub(): Argument #1 ($stub) must be of type string, array given
248A Phar stub cannot be set in a plain tar archive
249Phar::setDefaultStub(): Argument #1 ($index) must be of type ?string, array given
250Cannot change stub: phar.readonly=1
251Cannot set signature algorithm, phar is read-only
252Phar::compress(): Argument #1 ($compression) must be of type int, array given
253Cannot compress phar archive, phar is read-only
254Phar::compressFiles(): Argument #1 ($compression) must be of type int, array given
255Phar is readonly, cannot change compression
256Phar::copy() expects exactly 2 arguments, 1 given
257Cannot copy "a" to "b", phar is read-only
258Phar::offsetExists(): Argument #1 ($localName) must be of type string, array given
259Phar::offsetGet(): Argument #1 ($localName) must be of type string, array given
260Phar::offsetSet() expects exactly 2 arguments, 1 given
261PharData::offsetUnset(): Argument #1 ($localName) must be of type string, array given
262Write operations disabled by the php.ini setting phar.readonly
263Phar::addEmptyDir(): Argument #1 ($directory) must be of type string, array given
264Phar::addFile(): Argument #1 ($filename) must be of type string, array given
265Phar::addFromString() expects exactly 2 arguments, 1 given
266Write operations disabled by the php.ini setting phar.readonly
267Phar::setMetadata() expects exactly 1 argument, 2 given
268Write operations disabled by the php.ini setting phar.readonly
269