You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Sriskanthaverl <sk...@gmail.com> on 2007/03/09 23:17:34 UTC

A patch to perl-framework test scripts for php

Hi,

I have come across a number of test scripts for php in perl-framework,
which get skipped for php5, as it is explicitly said those test cases
are for php4. However I didn't see any good reason for those test cases
designed to get skipped for php5.
Therefore I modified the php scripts such a way that it runs in php4 and
php5 as well. I had to change the old_function syntax in the php scripts
as follows, to ensure the syntax is comply with php5 as well.

-old_function F $a (
+function F ($a) {
         eval($a);
-);
+};

Further it required the *.t files to be changed, to make it run for php5
as well ( otherwise it get skipped).
	instead calling 'need_php4', call 'need_php' function which return true if either php4 or php5 is defined.

I attached herewith the patch as a tar.gz, and the changes i made as a
diff file.

Would like to see your comments.

Regards
Sris


Re: A patch to perl-framework test scripts for php

Posted by Sriskanthaverl <sk...@gmail.com>.
Hi,
there is another test case, t/php/construct.t which get skipped for
php5. If it is enabled for php5, it failed.
In my understanding, the reason could be due to the difference in output
format in php4 and php5, when it is dumping a class variable to output
buffer.
the code htdocs/php/construct.php gives slightly diff output in php4 & 5.

o/p in php5: "x = object(stdClass)#2 (1) { ["root"]=> object(obj)#1 (0)
{ } }"
o/p in php4: "x = object(stdClass)(1) { ["root"]=> object(obj) (0) { } }"

therefore I decided to leave this as for php4. I am a newbie to php, and
appreciate your comments.

Thanks & Regards
Sris


Sriskanthaverl wrote:
> Hi,
>
> I have come across a number of test scripts for php in perl-framework,
> which get skipped for php5, as it is explicitly said those test cases
> are for php4. However I didn't see any good reason for those test cases
> designed to get skipped for php5.
> Therefore I modified the php scripts such a way that it runs in php4 and
> php5 as well. I had to change the old_function syntax in the php scripts
> as follows, to ensure the syntax is comply with php5 as well.
>
> -old_function F $a (
> +function F ($a) {
>          eval($a);
> -);
> +};
>
> Further it required the *.t files to be changed, to make it run for php5
> as well ( otherwise it get skipped).
> 	instead calling 'need_php4', call 'need_php' function which return true if either php4 or php5 is defined.
>
> I attached herewith the patch as a tar.gz, and the changes i made as a
> diff file.
>
> Would like to see your comments.
>
> Regards
> Sris
>
>   
> ------------------------------------------------------------------------
>
> Index: t/htdocs/php/regression3.php
> ===================================================================
> --- t/htdocs/php/regression3.php	(revision 516579)
> +++ t/htdocs/php/regression3.php	(working copy)
> @@ -1,22 +1,17 @@
>  <?php 
> -old_function RekTest $nr (
> +function RekTest ($nr) {
> +	echo " $nr ";
>  
> -echo " $nr ";
> -
> -
> -$j=$nr+1;
> -while ($j < 10)
> -{
> -  echo " a ";
> -  RekTest($j);
> -  $j++;
> -  echo " b $j ";
> +	$j=$nr+1;
> +	while ($j < 10)
> +	{
> +		echo " a ";
> +		RekTest($j);
> +		$j++;
> +		echo " b $j ";
> +	};
> +	echo "\n";
>  };
> -echo "\n";
>  
> -
> -
> -);
> -
>  RekTest(0);
>  ?>
> Index: t/htdocs/php/eval2.php
> ===================================================================
> --- t/htdocs/php/eval2.php	(revision 516579)
> +++ t/htdocs/php/eval2.php	(working copy)
> @@ -1,7 +1,7 @@
>  <?php
> -old_function F $a (
> +function F ($a) {
>          eval($a);
> -);
> +};
>  
>  error_reporting(0);
>  F("echo \"Hello\";");
> Index: t/htdocs/php/param2.php
> ===================================================================
> --- t/htdocs/php/param2.php	(revision 516579)
> +++ t/htdocs/php/param2.php	(working copy)
> @@ -1,7 +1,7 @@
> -<?php  old_function Test $b (
> +<?php  function Test ($b) {
>                  $b++;
>                  return($b);
> -        );
> +        };
>          $a = Test(1);
>          echo $a?>
>  
> Index: t/htdocs/php/if2.php
> ===================================================================
> --- t/htdocs/php/if2.php	(revision 516579)
> +++ t/htdocs/php/if2.php	(working copy)
> @@ -1,9 +1,9 @@
>  <?php $a = 1;
> -old_function Test $a (
> +function Test ($a) {
>          if($a<3):
>                  return(3);
>          endif;
> -);
> +};
>  
>  if($a < Test($a)):
>          echo "$a\n";
> Index: t/htdocs/php/param.php
> ===================================================================
> --- t/htdocs/php/param.php	(revision 516579)
> +++ t/htdocs/php/param.php	(working copy)
> @@ -1,5 +1,5 @@
> -<?php  old_function Test $a,$b (
> +<?php  function Test ($a,$b) {
>                  echo $a+$b;
> -        );
> +        };
>          Test(1,2)?>
>  
> Index: t/htdocs/php/func2.php
> ===================================================================
> --- t/htdocs/php/func2.php	(revision 516579)
> +++ t/htdocs/php/func2.php	(working copy)
> @@ -1,13 +1,13 @@
>  <?php
> -old_function blah (
> +function blah() {
>    static $hey=0,$yo=0;
>  
>    echo "hey=".$hey++.", ",$yo--."\n";
> -);
> +};
>  
>  blah();
>  blah();
>  blah();
>  if (isset($hey) || isset($yo)) {
>    echo "Local variables became global :(\n";
> -}
> +}?>
> Index: t/htdocs/php/func3.php
> ===================================================================
> --- t/htdocs/php/func3.php	(revision 516579)
> +++ t/htdocs/php/func3.php	(working copy)
> @@ -1,8 +1,8 @@
>  <?php
>  
> -old_function a (
> +function a() {
>    echo "hey\n";
> -);
> +};
>  
>  function b($i)
>  {
> @@ -27,13 +27,13 @@
>  a();
>  
>  
> -old_function factorial $n (
> +function factorial ($n) {
>    if ($n==0 || $n==1) {
>      return 1;
>    } else {
>      return factorial($n-1)*$n;
>    }
> -);
> +};
>  
>  function factorial2($start, $n)
>  {
> @@ -55,17 +55,17 @@
>  
>  echo "and now, from a function...\n";
>  
> -old_function call_fact (
> +function call_fact() {
>    echo "(it should break at 5...)\n";
>    for ($i=0; $i<=10; $i++) {
>      if ($i == 5) break;
>      $n=factorial($i);
>      echo "factorial($i) = $n\n";
>    }
> -);
> +};
>  
> -old_function return4 ( return 4; );
> -old_function return7 ( return 7; );
> +function return4 () { return 4; };
> +function return7 () { return 7; };
>  
>  for ($k=0; $k<10; $k++) {
>    call_fact();
> @@ -78,12 +78,12 @@
>  $result=factorial2(return4(),return7());
>  echo "$result\n";
>  
> -old_function andi $i, $j (
> +function andi ($i, $j) {
>          for ($k=$i ; $k<=$j ; $k++) {
>                  if ($k >5) continue;
>                  echo "$k\n";
>          }
> -);
> +};
>  
>  andi (3,10);
>  
> Index: t/htdocs/php/func4.php
> ===================================================================
> --- t/htdocs/php/func4.php	(revision 516579)
> +++ t/htdocs/php/func4.php	(working copy)
> @@ -2,17 +2,17 @@
>  
>  echo "Before function declaration...\n";
>  
> -old_function print_something_multiple_times $something,$times (
> +function print_something_multiple_times ($something,$times) {
>    echo "----\nIn function, printing the string \"$something\" $times times\n";
>    for ($i=0; $i<$times; $i++) {
>      echo "$i) $something\n";
>    }
>    echo "Done with function...\n-----\n";
> -);
> +};
>  
> -old_function some_other_function (
> +function some_other_function() {
>    echo "This is some other function, to ensure more than just one function works fine...\n";
> -);
> +};
>  
>  echo "After function declaration...\n";
>  
> Index: t/htdocs/php/umask.php
> ===================================================================
> --- t/htdocs/php/umask.php	(revision 516579)
> +++ t/htdocs/php/umask.php	(working copy)
> @@ -1 +1 @@
> -<? print umask(000); ?>
> \ No newline at end of file
> +<? print umask(0000); ?>
> Index: t/htdocs/php/stack.php
> ===================================================================
> --- t/htdocs/php/stack.php	(revision 516579)
> +++ t/htdocs/php/stack.php	(working copy)
> @@ -1,9 +1,9 @@
>  <?php
> -old_function F (
> +function F() {
>          if(1):
>                  return("Hello");
>          endif;
> -);
> +};
>  
>  $i=0;
>  while($i<2):
> Index: t/htdocs/php/include2.inc
> ===================================================================
> --- t/htdocs/php/include2.inc	(revision 516579)
> +++ t/htdocs/php/include2.inc	(working copy)
> @@ -1,5 +1,5 @@
>  <?php 
> -	old_function MyFunc $a (
> +	function MyFunc ($a) {
>  		echo $a;
> -	);
> +	};
>  ?>
> Index: t/php/func2.t
> ===================================================================
> --- t/php/func2.t	(revision 516579)
> +++ t/php/func2.t	(working copy)
> @@ -4,7 +4,7 @@
>  use Apache::Test;
>  use Apache::TestRequest;
>  
> -plan tests => 1, need_php4;
> +plan tests => 1, need_php;
>  
>  my $expected = <<EXPECT;
>  hey=0, 0
> Index: t/php/func3.t
> ===================================================================
> --- t/php/func3.t	(revision 516579)
> +++ t/php/func3.t	(working copy)
> @@ -4,7 +4,7 @@
>  use Apache::Test;
>  use Apache::TestRequest;
>  
> -plan tests => 1, need_php4;
> +plan tests => 1, need_php;
>  
>  my $expected = <<EXPECT;
>  hey
> Index: t/php/func4.t
> ===================================================================
> --- t/php/func4.t	(revision 516579)
> +++ t/php/func4.t	(working copy)
> @@ -4,7 +4,7 @@
>  use Apache::Test;
>  use Apache::TestRequest;
>  
> -plan tests => 1, need_php4;
> +plan tests => 1, need_php;
>  
>  my $expected = <<EXPECT;
>  Before function declaration...
> Index: t/php/umask.t
> ===================================================================
> --- t/php/umask.t	(revision 516579)
> +++ t/php/umask.t	(working copy)
> @@ -7,7 +7,7 @@
>  
>  ## test that umask() is reset after script execution
>  
> -plan tests => 4, need_php4;
> +plan tests => 4, need_php;
>  
>  my $first = GET_BODY "/php/umask.php";
>  
> Index: t/php/param2.t
> ===================================================================
> --- t/php/param2.t	(revision 516579)
> +++ t/php/param2.t	(working copy)
> @@ -4,7 +4,7 @@
>  use Apache::Test;
>  use Apache::TestRequest;
>  
> -plan tests => 1, need_php4;
> +plan tests => 1, need_php;
>  
>  my $result = GET_BODY "/php/param2.php";
>  ok $result eq "2\n";
> Index: t/php/stack.t
> ===================================================================
> --- t/php/stack.t	(revision 516579)
> +++ t/php/stack.t	(working copy)
> @@ -6,7 +6,7 @@
>  
>  ## testing stack after early function return
>  
> -plan tests => 1, need_php4;
> +plan tests => 1, need_php;
>  
>  my $expected = "HelloHello";
>  
> Index: t/php/if2.t
> ===================================================================
> --- t/php/if2.t	(revision 516579)
> +++ t/php/if2.t	(working copy)
> @@ -6,7 +6,7 @@
>  
>  ## Testing user-defined function falling out of an If into another
>  
> -plan tests => 1, need_php4;
> +plan tests => 1, need_php;
>  
>  my $expected = "1\n";
>  
> Index: t/php/param.t
> ===================================================================
> --- t/php/param.t	(revision 516579)
> +++ t/php/param.t	(working copy)
> @@ -4,7 +4,7 @@
>  use Apache::Test;
>  use Apache::TestRequest;
>  
> -plan tests => 1, need_php4;
> +plan tests => 1, need_php;
>  
>  my $result = GET_BODY "/php/param.php";
>  ok $result eq "3\n";
> Index: t/php/regression3.t
> ===================================================================
> --- t/php/regression3.t	(revision 516579)
> +++ t/php/regression3.t	(working copy)
> @@ -4,7 +4,7 @@
>  use Apache::Test;
>  use Apache::TestRequest;
>  
> -plan tests => 1, need_php4;
> +plan tests => 1, need_php;
>  
>  my $expected = <<EXPECT;
>   0  a  1  a  2  a  3  a  4  a  5  a  6  a  7  a  8  a  9 
> Index: t/php/include2.t
> ===================================================================
> --- t/php/include2.t	(revision 516579)
> +++ t/php/include2.t	(working copy)
> @@ -6,7 +6,7 @@
>  
>  ## testing user function in an nclude
>  
> -plan tests => 1, need_php4;
> +plan tests => 1, need_php;
>  
>  my $expected = "Hello";
>  
> Index: t/php/eval2.t
> ===================================================================
> --- t/php/eval2.t	(revision 516579)
> +++ t/php/eval2.t	(working copy)
> @@ -6,7 +6,7 @@
>  
>  ## testing eval function inside user function
>  
> -plan tests => 1, need_php4;
> +plan tests => 1, need_php;
>  
>  my $expected = "Hello";
>  
>