Skip to content

Commit ef93563

Browse files
committed
add more tests and TODO tests
1 parent 4516236 commit ef93563

19 files changed

+235
-0
lines changed

TODO/test_base_convert_ref.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
$a = 20;
4+
var_dump(base_convert(&$a, 10, 2));

TODO/test_class_method_ref.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
class Data {
4+
public function &data() {
5+
$a = new stdClass;
6+
$a->hi = "hello world!";
7+
return $a;
8+
}
9+
}
10+
11+
$d = new Data;
12+
$b = &$d->data();
13+
var_dump($b);
14+
15+
$c = &Data::data();
16+
var_dump($c);
17+

TODO/test_create_function_error.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
create_function("$a, $b)", "return 12;");
4+

TODO/test_error_log.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
date_default_timezone_set("UTC");
4+
5+
ini_set("error_log", "");
6+
7+
// sent to SAPI
8+
error_log("this is an error", 0);
9+
error_log("this is another one", 4);
10+
error_log("this is an error via email", 1, "[email protected]");
11+
error_log("this is an error via email", 1, "[email protected]", "X-Sent: PHP");
12+
13+
ini_set("error_log", "file.log");
14+
15+
// sent to file
16+
error_log("this is an error", 0);
17+
error_log("this is an error for destination", 3, "file.log");
18+
19+
ini_set("error_log", "syslog");
20+
21+
// sent to syslog
22+
error_log("this is a system error", 0);

TODO/test_exit_code.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
exit(2);
4+

TODO/test_html.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
4+
5+
// Not looking at all comments.
6+
if ( $comment_status && 'all' != $comment_status ) {
7+
if ( 'approved' === $the_comment_status ) {
8+
$actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved' class='vim-u vim-destructive' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
9+
} elseif ( 'unapproved' === $the_comment_status ) {
10+
$actions['approve'] = "<a href='$approve_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved' class='vim-a vim-destructive' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
11+
}
12+
}
13+

TODO/test_memory_usage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Memory usage
2+
3+
Currently = <?=memory_get_usage()?>
4+
Currently (+unused) = <?=memory_get_usage(true)?>
5+
6+
Max = <?=memory_get_peak_usage()?>
7+
Max (+unused) = <?=memory_get_peak_usage(true)?>
8+

TODO/test_pcre.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
print PCRE_VERSION . "\n";

TODO/test_phpinfo.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php phpinfo();

TODO/test_stream.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
3+
4+
switch($notification_code) {
5+
case STREAM_NOTIFY_RESOLVE:
6+
case STREAM_NOTIFY_AUTH_REQUIRED:
7+
case STREAM_NOTIFY_COMPLETED:
8+
case STREAM_NOTIFY_FAILURE:
9+
case STREAM_NOTIFY_AUTH_RESULT:
10+
var_dump($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max);
11+
/* Ignore */
12+
break;
13+
14+
case STREAM_NOTIFY_REDIRECTED:
15+
echo "Being redirected to: ", $message;
16+
break;
17+
18+
case STREAM_NOTIFY_CONNECT:
19+
echo "Connected...";
20+
break;
21+
22+
case STREAM_NOTIFY_FILE_SIZE_IS:
23+
echo "Got the filesize: ", $bytes_max;
24+
break;
25+
26+
case STREAM_NOTIFY_MIME_TYPE_IS:
27+
echo "Found the mime-type: ", $message;
28+
break;
29+
30+
case STREAM_NOTIFY_PROGRESS:
31+
echo "Made some progress, downloaded ", $bytes_transferred, " so far";
32+
break;
33+
}
34+
echo "\n";
35+
}
36+
37+
$ctx = stream_context_create();
38+
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
39+
40+
file_get_contents("http://php.net/contact", false, $ctx);
41+

TODO/test_stream_callback.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
function usage($argv) {
3+
echo "Usage:\n";
4+
printf("\tphp %s <http://example.com/file> <localfile>\n", $argv[0]);
5+
exit(1);
6+
}
7+
8+
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
9+
static $filesize = null;
10+
11+
switch($notification_code) {
12+
case STREAM_NOTIFY_RESOLVE:
13+
case STREAM_NOTIFY_AUTH_REQUIRED:
14+
case STREAM_NOTIFY_COMPLETED:
15+
case STREAM_NOTIFY_FAILURE:
16+
case STREAM_NOTIFY_AUTH_RESULT:
17+
/* Ignore */
18+
break;
19+
20+
case STREAM_NOTIFY_REDIRECTED:
21+
echo "Being redirected to: ", $message, "\n";
22+
break;
23+
24+
case STREAM_NOTIFY_CONNECT:
25+
echo "Connected...\n";
26+
break;
27+
28+
case STREAM_NOTIFY_FILE_SIZE_IS:
29+
$filesize = $bytes_max;
30+
echo "Filesize: ", $filesize, "\n";
31+
break;
32+
33+
case STREAM_NOTIFY_MIME_TYPE_IS:
34+
echo "Mime-type: ", $message, "\n";
35+
break;
36+
37+
case STREAM_NOTIFY_PROGRESS:
38+
if ($bytes_transferred > 0) {
39+
if (!isset($filesize)) {
40+
printf("\rUnknown filesize.. %2d kb done..", $bytes_transferred/1024);
41+
} else {
42+
$length = (int)(($bytes_transferred/$filesize)*50);
43+
printf("\r[%-50s] %d%% (%2d/%2d kb)", str_repeat("=", $length). ">", $length * 2, ($bytes_transferred/1024), $filesize/1024);
44+
}
45+
}
46+
break;
47+
}
48+
}
49+
50+
isset($argv[1], $argv[2]) or usage($argv);
51+
52+
$ctx = stream_context_create();
53+
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
54+
55+
$fp = fopen($argv[1], "r", false, $ctx);
56+
if (is_resource($fp) && file_put_contents($argv[2], $fp)) {
57+
echo "\nDone!\n";
58+
exit(0);
59+
}
60+
61+
$err = error_get_last();
62+
echo "\nErrrrrorr..\n", $err["message"], "\n";
63+
exit(1);
64+

test/code/test_func_object.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object(stdClass)#1 (1) {
2+
["hi"]=>
3+
string(12) "hello world!"
4+
}

test/code/test_func_object.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
function data() {
4+
$a = new stdClass;
5+
$a->hi = "hello world!";
6+
return $a;
7+
}
8+
9+
$b = data();
10+
var_dump($b);
11+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object(stdClass)#1 (1) {
2+
["data"]=>
3+
int(10)
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
function &data() {
4+
$a = new stdClass();
5+
$a->data = 10;
6+
return $a;
7+
}
8+
9+
$d = &data();
10+
$e = &$d;
11+
var_dump($e);
12+

test/code/test_index_offset_error.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Notice: Undefined offset 100 in {{CWD}}/test/code/test_index_offset_error.php on line 6

test/code/test_index_offset_error.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
error_reporting(E_ALL);
4+
5+
$wp_filter = [];
6+
print $wp_filter[100];

test/code/test_preg_match2.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
array(3) {
2+
[0]=>
3+
string(26) "nplurals=2; plural=n != 1;"
4+
[1]=>
5+
string(1) "2"
6+
[2]=>
7+
string(7) "n != 1;"
8+
}

test/code/test_preg_match2.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$header = "nplurals=2; plural=n != 1;";
4+
preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches);
5+
6+
var_dump($matches);
7+

0 commit comments

Comments
 (0)