1--TEST--
2Phar::startBuffering()/setStub()/stopBuffering() zip-based
3--SKIPIF--
4<?php
5if (!extension_loaded("phar")) die("skip");
6?>
7--INI--
8phar.readonly=0
9--FILE--
10<?php
11$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar.zip', 0, 'brandnewphar.phar');
12var_dump($p->isFileFormat(Phar::ZIP));
13//var_dump($p->getStub());
14var_dump($p->isBuffering());
15$p->startBuffering();
16var_dump($p->isBuffering());
17$p['a.php'] = '<?php var_dump("Hello");';
18$p->setStub('<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
19include 'phar://brandnewphar.phar/a.php';
20var_dump($p->getStub());
21$p['b.php'] = '<?php var_dump("World");';
22$p->setStub('<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER();');
23include 'phar://brandnewphar.phar/b.php';
24var_dump($p->getStub());
25$p->stopBuffering();
26echo "===COMMIT===\n";
27var_dump($p->isBuffering());
28include 'phar://brandnewphar.phar/a.php';
29include 'phar://brandnewphar.phar/b.php';
30var_dump($p->getStub());
31
32// add portion to test setting stub from resource
33file_put_contents(dirname(__FILE__) . '/myfakestub.php', '<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
34$a = fopen(dirname(__FILE__) . '/myfakestub.php', 'rb');
35$p->setStub($a);
36var_dump($p->getStub());
37$c = strlen('<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
38file_put_contents(dirname(__FILE__) . '/myfakestub.php', '<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>' . 'extra stuff');
39fseek($a, 0);
40$p->setStub($a, $c);
41var_dump($p->getStub());
42fclose($a);
43?>
44===DONE===
45--CLEAN--
46<?php
47unlink(dirname(__FILE__) . '/brandnewphar.phar.zip');
48unlink(dirname(__FILE__) . '/myfakestub.php');
49?>
50--EXPECT--
51bool(true)
52bool(false)
53bool(true)
54string(5) "Hello"
55string(84) "<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
56"
57string(5) "World"
58string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
59"
60===COMMIT===
61bool(false)
62string(5) "Hello"
63string(5) "World"
64string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
65"
66string(93) "<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
67"
68string(93) "<?php var_dump("First resource"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>
69"
70===DONE===
71