xref: /PHP-8.3/ext/phar/tests/addfuncs.phpt (revision 74859783)
1--TEST--
2Phar: addFile/addFromString
3--EXTENSIONS--
4phar
5--INI--
6phar.readonly=0
7--FILE--
8<?php
9$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
10$pname = 'phar://' . $fname;
11$phar = new Phar($fname);
12$phar->addFromString('a', 'hi');
13echo file_get_contents($pname . '/a') . "\n";
14$phar->addFile($pname . '/a', 'b');
15echo file_get_contents($pname . '/b') . "\n";
16try {
17$phar->addFile($pname . '/a');
18} catch (Exception $e) {
19echo $e->getMessage() . "\n";
20}
21try {
22$phar->addFile($pname . '/a', 'a');
23} catch (Exception $e) {
24echo $e->getMessage() . "\n";
25}
26try {
27$phar->addFile(__DIR__ . '/does/not/exist');
28} catch (Exception $e) {
29echo $e->getMessage() . "\n";
30}
31try {
32$phar->addFile($pname . '/a', '.phar/stub.php');
33} catch (Exception $e) {
34echo $e->getMessage() . "\n";
35}
36try {
37$phar->addFromString('.phar/stub.php', 'hi');
38} catch (Exception $e) {
39echo $e->getMessage() . "\n";
40}
41?>
42--CLEAN--
43<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
44--EXPECTF--
45hi
46hi
47Entry phar://%saddfuncs.phar.php/a does not exist and cannot be created: phar error: invalid path "phar://%saddfuncs.phar.php/a" contains double slash
48Entry a does not exist and cannot be created: phar error: file "a" in phar "%saddfuncs.phar.php" cannot be opened for writing, readable file pointers are open
49phar error: unable to open file "%s/does/not/exist" to add to phar archive
50Cannot create any files in magic ".phar" directory
51Cannot create any files in magic ".phar" directory
52