com php-src: Added tests for PHAR/OPCahce incompatibilities: ext/opcache/tests/issue0115.phpt ext/opcache/tests/issue0149.phpt
ext/opcache/tests/php_cli_server.inc
| From: | Dmitry Stogov | Date: | Fri, 08 Nov 2013 09:50:57 +0000 |
| Subject: | com php-src: Added tests for PHAR/OPCahce incompatibilities: ext/opcache/tests/issue0115.phpt ext/opcache/tests/issue0149.phpt ext/opcache/tests/php_cli_server.inc |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-73898@lists.php.net to get a copy of this message | ||
Commit: 49fbe2579e9cbb4314346c8eaf959c670de0abdb
Author: Dmitry Stogov <dmitry@zend.com> Fri, 8 Nov 2013 13:50:57 +0400
Parents: 717268cb1e689fff793fa0ceb36133394fd9a75b
Branches: PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=49fbe2579e9cbb4314346c8eaf959c670de0abdb
Log:
Added tests for PHAR/OPCahce incompatibilities
Changed paths:
A ext/opcache/tests/issue0115.phpt
A ext/opcache/tests/issue0149.phpt
A ext/opcache/tests/php_cli_server.inc
Diff:
diff --git a/ext/opcache/tests/issue0115.phpt b/ext/opcache/tests/issue0115.phpt
new file mode 100644
index 0000000..a1e469f
--- /dev/null
+++ b/ext/opcache/tests/issue0115.phpt
@@ -0,0 +1,48 @@
+--TEST--
+ISSUE #115 (path issue when using phar)
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+phar.readonly=0
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (php_sapi_name() != "cli") die("skip CLI only"); ?>
+--FILE--
+<?php
+$stub = '<?php
+Phar::interceptFileFuncs();
+require "phar://this/index.php";
+__HALT_COMPILER(); ?>';
+$p = new Phar(__DIR__ . '/issue0115_1.phar.php', 0, 'this');
+$p['index.php'] = '<?php
+echo "Hello from Index 1.\n";
+require_once "phar://this/hello.php";
+';
+$p['hello.php'] = "Hello World 1!\n";
+$p->setStub($stub);
+unset($p);
+$p = new Phar(__DIR__ . '/issue0115_2.phar.php', 0, 'this');
+$p['index.php'] = '<?php
+echo "Hello from Index 2.\n";
+require_once "phar://this/hello.php";
+';
+$p['hello.php'] = "Hello World 2!\n";
+$p->setStub($stub);
+unset($p);
+
+include "php_cli_server.inc";
+php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1');
+echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS .
'/issue0115_1.phar.php');
+echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS .
'/issue0115_2.phar.php');
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/issue0115_1.phar.php');
+@unlink(__DIR__ . '/issue0115_2.phar.php');
+?>
+--EXPECT--
+Hello from Index 1.
+Hello World 1!
+Hello from Index 2.
+Hello World 2!
diff --git a/ext/opcache/tests/issue0149.phpt b/ext/opcache/tests/issue0149..phpt
new file mode 100644
index 0000000..7044d39
--- /dev/null
+++ b/ext/opcache/tests/issue0149.phpt
@@ -0,0 +1,35 @@
+--TEST--
+ISSUE #149 (Phar mount points not working this OPcache enabled)
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+phar.readonly=0
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (php_sapi_name() != "cli") die("skip CLI only"); ?>
+--FILE--
+<?php
+$stub = "<?php header('Content-Type: text/plain;');
+Phar::mount('this.file', '". __FILE__ . "');
+echo 'OK\n';
+__HALT_COMPILER(); ?>";
+$p = new Phar(__DIR__ . '/issue0149.phar.php', 0, 'this');
+$p['index.php'] = ""; # A Phar must have at least one file, hence this dummy
+$p->setStub($stub);
+unset($p);
+
+include "php_cli_server.inc";
+php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1');
+echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS .
'/issue0149.phar.php');
+echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS .
'/issue0149.phar.php');
+echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS .
'/issue0149.phar.php');
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/issue0149.phar.php');
+?>
+--EXPECT--
+OK
+OK
+OK
diff --git a/ext/opcache/tests/php_cli_server.inc b/ext/opcache/tests/php_cli_server.inc
new file mode 100644
index 0000000..0878bfa
--- /dev/null
+++ b/ext/opcache/tests/php_cli_server.inc
@@ -0,0 +1,47 @@
+<?php
+define ("PHP_CLI_SERVER_HOSTNAME", "localhost");
+define ("PHP_CLI_SERVER_PORT", 8964);
+define ("PHP_CLI_SERVER_ADDRESS",
PHP_CLI_SERVER_HOSTNAME.":".PHP_CLI_SERVER_PORT);
+
+function php_cli_server_start($ini = "") {
+ $php_executable = getenv('TEST_PHP_EXECUTABLE');
+ $doc_root = __DIR__;
+
+ $descriptorspec = array(
+ 0 => STDIN,
+ 1 => STDOUT,
+ 2 => STDERR,
+ );
+
+ if (substr(PHP_OS, 0, 3) == 'WIN') {
+ $cmd = "{$php_executable} -t {$doc_root} $ini -S " . PHP_CLI_SERVER_ADDRESS;
+ $handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL,
array("bypass_shell" => true, "suppress_errors" => true));
+ } else {
+ $cmd = "exec {$php_executable} -t {$doc_root} $ini -S " . PHP_CLI_SERVER_ADDRESS .
" 2>/dev/null";
+ $handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root);
+ }
+
+ // note: even when server prints 'Listening on localhost:8964...Press Ctrl-C to quit.'
+ // it might not be listening yet...need to wait until fsockopen() call returns
+ $i = 0;
+ while (($i++ < 30) && !($fp = @fsockopen(PHP_CLI_SERVER_HOSTNAME,
PHP_CLI_SERVER_PORT))) {
+ usleep(10000);
+ }
+
+ if ($fp) {
+ fclose($fp);
+ }
+
+ register_shutdown_function(
+ function($handle) {
+ proc_terminate($handle);
+ },
+ $handle
+ );
+ // don't bother sleeping, server is already up
+ // server can take a variable amount of time to be up, so just sleeping a guessed amount of time
+ // does not work. this is why tests sometimes pass and sometimes fail. to get a reliable pass
+ // sleeping doesn't work.
+}
+?>
+