summaryrefslogtreecommitdiff
path: root/ext/phar/tests/phar_offset_check.phpt
blob: fe12534915d07e2fde28814b75d9c03125f7a96c (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
--TEST--
Phar: disallow stub and alias setting via offset*() methods
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
--INI--
phar.readonly=0
phar.require_hash=1
--FILE--
<?php

$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
$pname = 'phar://'.$fname;

$phar = new Phar($fname);
$phar->setDefaultStub();
$phar->setAlias('susan');
$phar['a.txt'] = "first file\n";
$phar['b.txt'] = "second file\n";

try {
	$phar->offsetGet('.phar/stub.php');
} catch (Exception $e) {
	echo $e->getMessage()."\n";
}

try {
	$phar->offsetGet('.phar/alias.txt');
} catch (Exception $e) {
	echo $e->getMessage()."\n";
}

try {
	$phar->offsetSet('.phar/stub.php', '<?php __HALT_COMPILER(); ?>');
} catch (Exception $e) {
	echo $e->getMessage()."\n";
}

var_dump(strlen($phar->getStub()));

try {
	$phar->offsetUnset('.phar/stub.php');
} catch (Exception $e) {
	echo $e->getMessage()."\n";
}

var_dump(strlen($phar->getStub()));

try {
	$phar->offsetSet('.phar/alias.txt', 'dolly');
} catch (Exception $e) {
	echo $e->getMessage()."\n";
}

var_dump($phar->getAlias());

try {
	$phar->offsetUnset('.phar/alias.txt');
} catch (Exception $e) {
	echo $e->getMessage()."\n";
}

var_dump($phar->getAlias());

?>
===DONE===
--CLEAN--
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
--EXPECTF--
Entry .phar/stub.php does not exist
Entry .phar/alias.txt does not exist
Cannot set stub ".phar/stub.php" directly in phar "%sphar_offset_check.phar.php", use setStub
int(6685)
int(6685)
Cannot set alias ".phar/alias.txt" directly in phar "%sphar_offset_check.phar.php", use setAlias
string(5) "susan"
string(5) "susan"
===DONE===