cvs: pear /PHP_Compat/tests loadconstant.phpt loadfunction.phpt /PHP_Compat/tests/function file_put_contents.phpt str_ireplace.phpt str_split.phpt
strripos.phpt var_export.phpt
| From: | Aidan Lister | Date: | Sun, 13 Jun 2004 18:08:59 +0000 |
| Subject: | cvs: pear /PHP_Compat/tests loadconstant.phpt loadfunction.phpt /PHP_Compat/tests/function file_put_contents.phpt str_ireplace.phpt str_split.phpt strripos.phpt var_export.phpt |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-20605@lists.php.net to get a copy of this message | ||
aidan Sun Jun 13 14:08:59 2004 EDT
Modified files:
/pear/PHP_Compat/tests/function file_put_contents.phpt
str_ireplace.phpt str_split.phpt
strripos.phpt var_export.phpt
/pear/PHP_Compat/tests loadconstant.phpt loadfunction.phpt
Log:
Improved testing method / Reduced code
http://cvs.php.net/diff.php/pear/PHP_Compat/tests/function/file_put_contents.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/function/file_put_contents.phpt diff -u pear/PHP_Compat/tests/function/file_put_contents.phpt:1.1 pear/PHP_Compat/tests/function/file_put_contents.phpt:1.2 --- pear/PHP_Compat/tests/function/file_put_contents.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/function/file_put_contents.phpt Sun Jun 13 14:08:58 2004 @@ -7,29 +7,20 @@ require_once ('PHP/Compat.php'); PHP_Compat::loadFunction('file_put_contents'); +// Create a temp file +$tmpfname = tempnam('/tmp', 'phpcompat'); + // With a string $string = "abcd"; -$tmpfname = tempnam('/tmp', 'php'); - -$res = file_put_contents($tmpfname, $string); -$data = implode('', file($tmpfname)); - -unlink($tmpfname); -echo $res, "\n"; -echo $data, "\n"; +echo file_put_contents($tmpfname, $string), "\n"; +echo implode('', file($tmpfname)), "\n"; // With an array $string = array('foo', 'bar'); -$tmpfname = tempnam('/tmp', 'php'); - -$res = file_put_contents($tmpfname, $string); -$data = implode('', file($tmpfname)); - -unlink($tmpfname); -echo $res, "\n"; -echo $data, "n"; +echo file_put_contents($tmpfname, $string), "\n"; +echo implode('', file($tmpfname)), "\n"; // Test append $string = 'foobar'; http://cvs.php.net/diff.php/pear/PHP_Compat/tests/function/str_ireplace.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/function/str_ireplace.phpt diff -u pear/PHP_Compat/tests/function/str_ireplace.phpt:1.1 pear/PHP_Compat/tests/function/str_ireplace.phpt:1.2 --- pear/PHP_Compat/tests/function/str_ireplace.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/function/str_ireplace.phpt Sun Jun 13 14:08:58 2004 @@ -18,7 +18,7 @@ echo str_ireplace($search, $replace, $subject), "\n"; // -// With subject as array +// Test 1: With subject as array // // As a full array @@ -33,29 +33,30 @@ $subject = array('The dog jumped over the {object}'); print_r(str_ireplace($search, $replace, $subject)); + // -// Search as string, replace as array +// Test 2: Search as string, replace as array // $search = '{object}'; $replace = array('cat', 'dog', 'tiger'); $subject = 'The dog jumped over the {object}'; - // Supress the error, no way of knowing how it'll turn out on the users machine echo @str_ireplace($search, $replace, $subject), "\n"; + // -// Search as array, Replace as string +// Test 3: Search as array, Replace as string // $search = array('{ANIMAL}', '{OBJECT}', '{THING}'); $replace = 'frog'; $subject = 'The {animal} jumped over the {object} and the {thing}...'; - echo str_ireplace($search, $replace, $subject), "\n"; + // -// Search and Replace as arrays +// Test 4: Search and Replace as arrays // // Simple @@ -76,14 +77,14 @@ $subject = 'The {animal} jumped over the {object} and the {thing}...'; echo str_ireplace($search, $replace, $subject), "\n"; + // -// All arrays +// Test 5: All arrays // $search = array('{ANIMAL}', '{OBJECT}', '{THING}'); $replace = array('frog', 'gate', 'beer'); $subject = array('A {animal}', 'The {object}', 'My {thing}'); - print_r(str_ireplace($search, $replace, $subject)); ?> http://cvs.php.net/diff.php/pear/PHP_Compat/tests/function/str_split.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/function/str_split.phpt diff -u pear/PHP_Compat/tests/function/str_split.phpt:1.1 pear/PHP_Compat/tests/function/str_split.phpt:1.2 --- pear/PHP_Compat/tests/function/str_split.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/function/str_split.phpt Sun Jun 13 14:08:58 2004 @@ -7,28 +7,22 @@ require_once ('PHP/Compat.php'); PHP_Compat::loadFunction('str_split'); -// Simple $str = "Hello Friend"; -$arr = str_split($str); +// Simple +$arr = str_split($str); print_r($arr); // With a chunk size specified -$str = "Hello Friend"; $arr = str_split($str, 3); - print_r($arr); // With chunk size bigger than the string -$str = "abcd"; -$arr = str_split($str, 3); - +$arr = str_split($str, 60); print_r($arr); // String that has a remainder less than the chunk size -$str = "abcd"; -$arr = str_split($str, 3); - +$arr = str_split($str, 11); print_r($arr); ?> --EXPECT-- @@ -56,11 +50,10 @@ ) Array ( - [0] => abc - [1] => d + [0] => Hello Friend ) Array ( - [0] => abc + [0] => Hello Frien [1] => d ) http://cvs.php.net/diff.php/pear/PHP_Compat/tests/function/strripos.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/function/strripos.phpt diff -u pear/PHP_Compat/tests/function/strripos.phpt:1.1 pear/PHP_Compat/tests/function/strripos.phpt:1.2 --- pear/PHP_Compat/tests/function/strripos.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/function/strripos.phpt Sun Jun 13 14:08:58 2004 @@ -7,16 +7,13 @@ require_once ('PHP/Compat.php'); PHP_Compat::loadFunction('strripos'); -// Simple -$haystack = 'Cat Dog Lion Mouse Sheep Wolf Cat Dog'; +$haystack = 'Cat Dinner Dog Lion Mouse Sheep Wolf Cat Dog Donut'; $needle = 'DOG'; +// Simple var_dump(strripos($haystack, $needle)); // With offset -$haystack = 'Cat Dinner Dog Lion Mouse Sheep Wolf Cat Dog Donut'; -$needle = 'DOG'; - var_dump(strripos($haystack, $needle, 3)); var_dump(strripos($haystack, $needle, 30)); var_dump(strripos($haystack, $needle, 50)); @@ -26,7 +23,7 @@ var_dump(strripos($haystack, $needle, -50)); ?> --EXPECT-- -int(34) +int(41) int(41) int(41) bool(false) http://cvs.php.net/diff.php/pear/PHP_Compat/tests/function/var_export.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/function/var_export.phpt diff -u pear/PHP_Compat/tests/function/var_export.phpt:1.1 pear/PHP_Compat/tests/function/var_export.phpt:1.2 --- pear/PHP_Compat/tests/function/var_export.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/function/var_export.phpt Sun Jun 13 14:08:58 2004 @@ -7,9 +7,12 @@ require_once ('PHP/Compat.php'); PHP_Compat::loadFunction('var_export'); +// Simple $a = array (1, 2, array ("a", "b", "c")); var_export($a); echo "\n"; + +// With return echo var_export($a, true); ?> --EXPECT-- http://cvs.php.net/diff.php/pear/PHP_Compat/tests/loadconstant.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/loadconstant.phpt diff -u pear/PHP_Compat/tests/loadconstant.phpt:1.1 pear/PHP_Compat/tests/loadconstant.phpt:1.2 --- pear/PHP_Compat/tests/loadconstant.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/loadconstant.phpt Sun Jun 13 14:08:59 2004 @@ -1,5 +1,5 @@ --TEST-- -Method -- PHP_Compat::loadConstant -- load invalid and valid constants +Method -- PHP_Compat::loadConstant --SKIPIF-- <?php if (defined('E_STRICT')) { echo 'skip'; } ?> --FILE-- @@ -7,19 +7,18 @@ require_once ('PHP/Compat.php'); // Singular -$res = PHP_Compat::loadConstant('invalid'); -echo ($res === false) ? 'false' : 'true', "\n"; - -$res = PHP_Compat::loadConstant('E_STRICT'); -echo ($res === false) ? 'false' : 'true'; +$test1 = array (); +$test1[] = PHP_Compat::loadConstant('invalid'); +$test1[] = PHP_Compat::loadConstant('E_STRICT'); // With an array -$comps = array('invalid', 'also-invalid', 'more-invalid', 'E_STRICT'); -$res = PHP_Compat::loadConstant($comps); -foreach ($res as $value) { - echo ($value === false) ? 'false' : 'true', "\n"; -} +$components = array('invalid', 'also-invalid', 'more-invalid', 'E_STRICT'); +$test2 = PHP_Compat::loadConstant($components); +$results = array_merge($test1, $test2); +foreach ($results as $result) { + echo ($result === true) ? 'true' : 'false', "\n"; +} ?> --EXPECT-- false @@ -27,4 +26,4 @@ false false false -true \ No newline at end of file +false \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Compat/tests/loadfunction.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/loadfunction.phpt diff -u pear/PHP_Compat/tests/loadfunction.phpt:1.1 pear/PHP_Compat/tests/loadfunction.phpt:1.2 --- pear/PHP_Compat/tests/loadfunction.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/loadfunction.phpt Sun Jun 13 14:08:59 2004 @@ -1,23 +1,23 @@ --TEST-- -Method -- PHP_Compat::loadFunction -- load invalid and valid function +Method -- PHP_Compat::loadFunction --SKIPIF-- -<?php if (function_exists('str_split')) { echo 'skip'; } ?> +<?php if (function_exists('str_split') || function_exists('scandir')) { echo 'skip'; } ?> --FILE-- <?php require_once ('PHP/Compat.php'); // Singular -$res = PHP_Compat::loadFunction('invalid'); -echo ($res === false) ? 'false' : 'true', "\n"; - -$res = PHP_Compat::loadFunction('str_split'); -echo ($res === false) ? 'false' : 'true'; +$test1 = array (); +$test1[] = PHP_Compat::loadFunction('invalid'); +$test1[] = PHP_Compat::loadFunction('str_split'); // With an array -$comps = array('invalid', 'also-invalid', 'more-invalid', 'str_split'); -$res = PHP_Compat::loadFunction($comps); -foreach ($res as $value) { - echo ($value === false) ? 'false' : 'true', "\n"; +$components = array('invalid', 'also-invalid', 'more-invalid', 'scandir'); +$test2 = PHP_Compat::loadFunction($components); + +$results = array_merge($test1, $test2); +foreach ($results as $result) { + echo ($result === true) ? 'true' : 'false', "\n"; } ?> --EXPECT--
http://cvs.php.net/diff.php/pear/PHP_Compat/tests/function/file_put_contents.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/function/file_put_contents.phpt diff -u pear/PHP_Compat/tests/function/file_put_contents.phpt:1.1 pear/PHP_Compat/tests/function/file_put_contents.phpt:1.2 --- pear/PHP_Compat/tests/function/file_put_contents.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/function/file_put_contents.phpt Sun Jun 13 14:08:58 2004 @@ -7,29 +7,20 @@ require_once ('PHP/Compat.php'); PHP_Compat::loadFunction('file_put_contents'); +// Create a temp file +$tmpfname = tempnam('/tmp', 'phpcompat'); + // With a string $string = "abcd"; -$tmpfname = tempnam('/tmp', 'php'); - -$res = file_put_contents($tmpfname, $string); -$data = implode('', file($tmpfname)); - -unlink($tmpfname); -echo $res, "\n"; -echo $data, "\n"; +echo file_put_contents($tmpfname, $string), "\n"; +echo implode('', file($tmpfname)), "\n"; // With an array $string = array('foo', 'bar'); -$tmpfname = tempnam('/tmp', 'php'); - -$res = file_put_contents($tmpfname, $string); -$data = implode('', file($tmpfname)); - -unlink($tmpfname); -echo $res, "\n"; -echo $data, "n"; +echo file_put_contents($tmpfname, $string), "\n"; +echo implode('', file($tmpfname)), "\n"; // Test append $string = 'foobar'; http://cvs.php.net/diff.php/pear/PHP_Compat/tests/function/str_ireplace.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/function/str_ireplace.phpt diff -u pear/PHP_Compat/tests/function/str_ireplace.phpt:1.1 pear/PHP_Compat/tests/function/str_ireplace.phpt:1.2 --- pear/PHP_Compat/tests/function/str_ireplace.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/function/str_ireplace.phpt Sun Jun 13 14:08:58 2004 @@ -18,7 +18,7 @@ echo str_ireplace($search, $replace, $subject), "\n"; // -// With subject as array +// Test 1: With subject as array // // As a full array @@ -33,29 +33,30 @@ $subject = array('The dog jumped over the {object}'); print_r(str_ireplace($search, $replace, $subject)); + // -// Search as string, replace as array +// Test 2: Search as string, replace as array // $search = '{object}'; $replace = array('cat', 'dog', 'tiger'); $subject = 'The dog jumped over the {object}'; - // Supress the error, no way of knowing how it'll turn out on the users machine echo @str_ireplace($search, $replace, $subject), "\n"; + // -// Search as array, Replace as string +// Test 3: Search as array, Replace as string // $search = array('{ANIMAL}', '{OBJECT}', '{THING}'); $replace = 'frog'; $subject = 'The {animal} jumped over the {object} and the {thing}...'; - echo str_ireplace($search, $replace, $subject), "\n"; + // -// Search and Replace as arrays +// Test 4: Search and Replace as arrays // // Simple @@ -76,14 +77,14 @@ $subject = 'The {animal} jumped over the {object} and the {thing}...'; echo str_ireplace($search, $replace, $subject), "\n"; + // -// All arrays +// Test 5: All arrays // $search = array('{ANIMAL}', '{OBJECT}', '{THING}'); $replace = array('frog', 'gate', 'beer'); $subject = array('A {animal}', 'The {object}', 'My {thing}'); - print_r(str_ireplace($search, $replace, $subject)); ?> http://cvs.php.net/diff.php/pear/PHP_Compat/tests/function/str_split.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/function/str_split.phpt diff -u pear/PHP_Compat/tests/function/str_split.phpt:1.1 pear/PHP_Compat/tests/function/str_split.phpt:1.2 --- pear/PHP_Compat/tests/function/str_split.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/function/str_split.phpt Sun Jun 13 14:08:58 2004 @@ -7,28 +7,22 @@ require_once ('PHP/Compat.php'); PHP_Compat::loadFunction('str_split'); -// Simple $str = "Hello Friend"; -$arr = str_split($str); +// Simple +$arr = str_split($str); print_r($arr); // With a chunk size specified -$str = "Hello Friend"; $arr = str_split($str, 3); - print_r($arr); // With chunk size bigger than the string -$str = "abcd"; -$arr = str_split($str, 3); - +$arr = str_split($str, 60); print_r($arr); // String that has a remainder less than the chunk size -$str = "abcd"; -$arr = str_split($str, 3); - +$arr = str_split($str, 11); print_r($arr); ?> --EXPECT-- @@ -56,11 +50,10 @@ ) Array ( - [0] => abc - [1] => d + [0] => Hello Friend ) Array ( - [0] => abc + [0] => Hello Frien [1] => d ) http://cvs.php.net/diff.php/pear/PHP_Compat/tests/function/strripos.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/function/strripos.phpt diff -u pear/PHP_Compat/tests/function/strripos.phpt:1.1 pear/PHP_Compat/tests/function/strripos.phpt:1.2 --- pear/PHP_Compat/tests/function/strripos.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/function/strripos.phpt Sun Jun 13 14:08:58 2004 @@ -7,16 +7,13 @@ require_once ('PHP/Compat.php'); PHP_Compat::loadFunction('strripos'); -// Simple -$haystack = 'Cat Dog Lion Mouse Sheep Wolf Cat Dog'; +$haystack = 'Cat Dinner Dog Lion Mouse Sheep Wolf Cat Dog Donut'; $needle = 'DOG'; +// Simple var_dump(strripos($haystack, $needle)); // With offset -$haystack = 'Cat Dinner Dog Lion Mouse Sheep Wolf Cat Dog Donut'; -$needle = 'DOG'; - var_dump(strripos($haystack, $needle, 3)); var_dump(strripos($haystack, $needle, 30)); var_dump(strripos($haystack, $needle, 50)); @@ -26,7 +23,7 @@ var_dump(strripos($haystack, $needle, -50)); ?> --EXPECT-- -int(34) +int(41) int(41) int(41) bool(false) http://cvs.php.net/diff.php/pear/PHP_Compat/tests/function/var_export.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/function/var_export.phpt diff -u pear/PHP_Compat/tests/function/var_export.phpt:1.1 pear/PHP_Compat/tests/function/var_export.phpt:1.2 --- pear/PHP_Compat/tests/function/var_export.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/function/var_export.phpt Sun Jun 13 14:08:58 2004 @@ -7,9 +7,12 @@ require_once ('PHP/Compat.php'); PHP_Compat::loadFunction('var_export'); +// Simple $a = array (1, 2, array ("a", "b", "c")); var_export($a); echo "\n"; + +// With return echo var_export($a, true); ?> --EXPECT-- http://cvs.php.net/diff.php/pear/PHP_Compat/tests/loadconstant.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/loadconstant.phpt diff -u pear/PHP_Compat/tests/loadconstant.phpt:1.1 pear/PHP_Compat/tests/loadconstant.phpt:1.2 --- pear/PHP_Compat/tests/loadconstant.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/loadconstant.phpt Sun Jun 13 14:08:59 2004 @@ -1,5 +1,5 @@ --TEST-- -Method -- PHP_Compat::loadConstant -- load invalid and valid constants +Method -- PHP_Compat::loadConstant --SKIPIF-- <?php if (defined('E_STRICT')) { echo 'skip'; } ?> --FILE-- @@ -7,19 +7,18 @@ require_once ('PHP/Compat.php'); // Singular -$res = PHP_Compat::loadConstant('invalid'); -echo ($res === false) ? 'false' : 'true', "\n"; - -$res = PHP_Compat::loadConstant('E_STRICT'); -echo ($res === false) ? 'false' : 'true'; +$test1 = array (); +$test1[] = PHP_Compat::loadConstant('invalid'); +$test1[] = PHP_Compat::loadConstant('E_STRICT'); // With an array -$comps = array('invalid', 'also-invalid', 'more-invalid', 'E_STRICT'); -$res = PHP_Compat::loadConstant($comps); -foreach ($res as $value) { - echo ($value === false) ? 'false' : 'true', "\n"; -} +$components = array('invalid', 'also-invalid', 'more-invalid', 'E_STRICT'); +$test2 = PHP_Compat::loadConstant($components); +$results = array_merge($test1, $test2); +foreach ($results as $result) { + echo ($result === true) ? 'true' : 'false', "\n"; +} ?> --EXPECT-- false @@ -27,4 +26,4 @@ false false false -true \ No newline at end of file +false \ No newline at end of file http://cvs.php.net/diff.php/pear/PHP_Compat/tests/loadfunction.phpt?r1=1.1&r2=1.2&ty=u Index: pear/PHP_Compat/tests/loadfunction.phpt diff -u pear/PHP_Compat/tests/loadfunction.phpt:1.1 pear/PHP_Compat/tests/loadfunction.phpt:1.2 --- pear/PHP_Compat/tests/loadfunction.phpt:1.1 Sun Jun 13 13:21:11 2004 +++ pear/PHP_Compat/tests/loadfunction.phpt Sun Jun 13 14:08:59 2004 @@ -1,23 +1,23 @@ --TEST-- -Method -- PHP_Compat::loadFunction -- load invalid and valid function +Method -- PHP_Compat::loadFunction --SKIPIF-- -<?php if (function_exists('str_split')) { echo 'skip'; } ?> +<?php if (function_exists('str_split') || function_exists('scandir')) { echo 'skip'; } ?> --FILE-- <?php require_once ('PHP/Compat.php'); // Singular -$res = PHP_Compat::loadFunction('invalid'); -echo ($res === false) ? 'false' : 'true', "\n"; - -$res = PHP_Compat::loadFunction('str_split'); -echo ($res === false) ? 'false' : 'true'; +$test1 = array (); +$test1[] = PHP_Compat::loadFunction('invalid'); +$test1[] = PHP_Compat::loadFunction('str_split'); // With an array -$comps = array('invalid', 'also-invalid', 'more-invalid', 'str_split'); -$res = PHP_Compat::loadFunction($comps); -foreach ($res as $value) { - echo ($value === false) ? 'false' : 'true', "\n"; +$components = array('invalid', 'also-invalid', 'more-invalid', 'scandir'); +$test2 = PHP_Compat::loadFunction($components); + +$results = array_merge($test1, $test2); +foreach ($results as $result) { + echo ($result === true) ? 'true' : 'false', "\n"; } ?> --EXPECT--