xref: /PHP-7.1/ext/phar/tests/badparameters.phpt (revision 72281f29)
1--TEST--
2Phar: bad parameters to various methods
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.readonly=0
7--FILE--
8<?php
9ini_set('phar.readonly', 1);
10
11function print_exception($e) {
12	echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
13}
14
15Phar::mungServer('hi');
16Phar::createDefaultStub(array());
17Phar::loadPhar(array());
18Phar::canCompress('hi');
19try {
20	$a = new Phar(array());
21} catch (TypeError $e) {
22	print_exception($e);
23}
24try {
25	$a = new Phar(dirname(__FILE__) . '/files/frontcontroller10.phar');
26} catch (PharException $e) {
27	print_exception($e);
28}
29$a->convertToExecutable(array());
30$a->convertToData(array());
31try {
32	$b = new PharData(dirname(__FILE__) . '/whatever.tar');
33} catch (PharException $e) {
34	print_exception($e);
35}
36try {
37	$c = new PharData(dirname(__FILE__) . '/whatever.zip');
38} catch (PharException $e) {
39	print_exception($e);
40}
41$b->delete(array());
42try {
43$a->delete('oops');
44} catch (Exception $e) {
45echo $e->getMessage() . "\n";
46}
47try {
48$b->delete('oops');
49} catch (Exception $e) {
50echo $e->getMessage() . "\n";
51}
52echo $a->getPath() . "\n";
53try {
54$a->setAlias('oops');
55} catch (Exception $e) {
56echo $e->getMessage() . "\n";
57}
58try {
59$b->setAlias('oops');
60} catch (Exception $e) {
61echo $e->getMessage() . "\n";
62}
63ini_set('phar.readonly', 0);
64$a->setAlias(array());
65ini_set('phar.readonly', 1);
66try {
67$b->stopBuffering();
68} catch (Exception $e) {
69echo $e->getMessage() . "\n";
70}
71try {
72$a->setStub('oops');
73} catch (Exception $e) {
74echo $e->getMessage() . "\n";
75}
76try {
77$b->setStub('oops');
78} catch (Exception $e) {
79echo $e->getMessage() . "\n";
80}
81ini_set('phar.readonly', 0);
82$a->setStub(array());
83ini_set('phar.readonly', 1);
84try {
85$b->setDefaultStub('oops');
86} catch (Exception $e) {
87echo $e->getMessage() . "\n";
88}
89$a->setDefaultStub(array());
90try {
91$a->setDefaultStub('oops');
92} catch (Exception $e) {
93echo $e->getMessage() . "\n";
94}
95try {
96$a->setSignatureAlgorithm(Phar::MD5);
97} catch (Exception $e) {
98echo $e->getMessage() . "\n";
99}
100$a->compress(array());
101try {
102$a->compress(1);
103} catch (Exception $e) {
104echo $e->getMessage() . "\n";
105}
106$a->compressFiles(array());
107try {
108$a->decompressFiles();
109} catch (Exception $e) {
110echo $e->getMessage() . "\n";
111}
112$a->copy(array());
113try {
114$a->copy('a', 'b');
115} catch (Exception $e) {
116echo $e->getMessage() . "\n";
117}
118$a->offsetExists(array());
119$a->offsetGet(array());
120ini_set('phar.readonly', 0);
121$a->offsetSet(array());
122ini_set('phar.readonly', 1);
123$b->offsetUnset(array());
124try {
125$a->offsetUnset('a');
126} catch (Exception $e) {
127echo $e->getMessage() . "\n";
128}
129$a->addEmptyDir(array());
130$a->addFile(array());
131$a->addFromString(array());
132try {
133$a->setMetadata('a');
134} catch (Exception $e) {
135echo $e->getMessage() . "\n";
136}
137ini_set('phar.readonly', 0);
138$a->setMetadata(1,2);
139ini_set('phar.readonly', 1);
140try {
141$a->delMetadata();
142} catch (Exception $e) {
143echo $e->getMessage() . "\n";
144}
145?>
146===DONE===
147--EXPECTF--
148Warning: Phar::mungServer() expects parameter 1 to be array, %string given in %sbadparameters.php on line %d
149
150Warning: Phar::createDefaultStub() expects parameter 1 to be a valid path, array given in %sbadparameters.php on line %d
151
152Warning: Phar::loadPhar() expects parameter 1 to be a valid path, array given in %sbadparameters.php on line %d
153
154Warning: Phar::canCompress() expects parameter 1 to be integer, %string given in %sbadparameters.php on line %d
155
156Exception: Phar::__construct() expects parameter 1 to be a valid path, array given in %sbadparameters.php on line %d
157
158Warning: Phar::convertToExecutable() expects parameter 1 to be integer, array given in %sbadparameters.php on line %d
159
160Warning: Phar::convertToData() expects parameter 1 to be integer, array given in %sbadparameters.php on line %d
161
162Warning: PharData::delete() expects parameter 1 to be a valid path, array given in %sbadparameters.php on line %d
163Cannot write out phar archive, phar is read-only
164Entry oops does not exist and cannot be deleted
165%sfiles/frontcontroller10.phar
166Cannot write out phar archive, phar is read-only
167A Phar alias cannot be set in a plain tar archive
168
169Warning: Phar::setAlias() expects parameter 1 to be %string, array given in %sbadparameters.php on line %d
170Cannot change stub, phar is read-only
171A Phar stub cannot be set in a plain tar archive
172
173Warning: Phar::setStub() expects parameter 1 to be %string, array given in %sbadparameters.php on line %d
174A Phar stub cannot be set in a plain tar archive
175
176Warning: Phar::setDefaultStub() expects parameter 1 to be %string, array given in %sbadparameters.php on line %d
177Cannot change stub: phar.readonly=1
178Cannot set signature algorithm, phar is read-only
179
180Warning: Phar::compress() expects parameter 1 to be integer, array given in %sbadparameters.php on line %d
181Cannot compress phar archive, phar is read-only
182
183Warning: Phar::compressFiles() expects parameter 1 to be integer, array given in %sbadparameters.php on line %d
184Phar is readonly, cannot change compression
185
186Warning: Phar::copy() expects exactly 2 parameters, 1 given in %sbadparameters.php on line %d
187Cannot copy "a" to "b", phar is read-only
188
189Warning: Phar::offsetExists() expects parameter 1 to be a valid path, array given in %sbadparameters.php on line %d
190
191Warning: Phar::offsetGet() expects parameter 1 to be a valid path, array given in %sbadparameters.php on line %d
192
193Warning: Phar::offsetSet() expects exactly 2 parameters, 1 given in %sbadparameters.php on line %d
194
195Warning: PharData::offsetUnset() expects parameter 1 to be a valid path, array given in %sbadparameters.php on line %d
196Write operations disabled by the php.ini setting phar.readonly
197
198Warning: Phar::addEmptyDir() expects parameter 1 to be a valid path, array given in %sbadparameters.php on line %d
199
200Warning: Phar::addFile() expects parameter 1 to be a valid path, array given in %sbadparameters.php on line %d
201
202Warning: Phar::addFromString() expects exactly 2 parameters, 1 given in %sbadparameters.php on line %d
203Write operations disabled by the php.ini setting phar.readonly
204
205Warning: Phar::setMetadata() expects exactly 1 parameter, 2 given in %sbadparameters.php on line %d
206Write operations disabled by the php.ini setting phar.readonly
207===DONE===
208