Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Using Test::Harness to test PHP code

by petdance (Parson)
on Mar 26, 2002 at 15:58 UTC ( [id://154422]=perlcraft: print w/replies, xml ) Need Help??

   1: # My project uses Perl and PHP side by side.  I have .t
   2: # files throughout the source tree to test my Perl modules,
   3: # and also .phpt files to test my PHP code.  I wanted to
   4: # have Test::Harness run both sets of test scripts, but
   5: # the _open_test() specifically calls Perl scripts.  So
   6: # I made my own TW::Harness. (TW is the project)
   7: # 
   8: # Basically, what I'm doing is overloading the _open_test()
   9: # method, although we're not using any inheritance since
  10: # we don't have an instance of the *::Harness object.
  11: #
  12: # This method is terribly tied to current implementation of
  13: # Test::Harness, but is the best way I had without getting
  14: # into the Test::Harness::Straps API.
  15: 
  16: package TW::Harness;
  17: 
  18: =head1 NAME
  19: 
  20: TW::Harness - Magic override class to PHP-ify Test::Harness
  21: 
  22:     $Author: alester $
  23:     $Date: 2002/03/23 04:44:33 $
  24:     $Source: /home/cvs/tw/Lib/TW/Harness.pm,v $
  25:     $Revision: 1.4 $
  26: 
  27: =head1 DESCRIPTION
  28: 
  29: This class is a TW-specific testing harness that still lets us use Schwern's
  30: original C<Test::Harness> for everything that isn't a .phpt file.
  31: 
  32: =head1 USAGE
  33: 
  34: Use TW::Harness just like regular Test::Harness.  Here's the line from the Makefile:
  35: 
  36:     perl -I./Lib -I/usr/local/lib/perl5/5.6.1/sun4-solaris -I/usr/local/lib/perl5/5.6.1 \
  37:         -e 'use TW::Harness qw(&runtests $$verbose $$switches); $$verbose=$(TEST_VERBOSE); \
  38:         $$switches=""; runtests(@ARGV);' $(TEST_FILES)
  39: 
  40: =head1 SEE ALSO
  41: 
  42: L<Test::Harness>
  43: 
  44: =cut
  45: use Test::Harness qw( $verbose runtests $switches );
  46: 
  47: # Replicate all of C<Test::Harness>'s exports
  48: our @ISA = qw( Exporter );
  49: our @EXPORT    = @Test::Harness::EXPORT;
  50: our @EXPORT_OK = @Test::Harness::EXPORT_OK;
  51: 
  52: # Save a pointer to the original function
  53: my $original_open_test = \&Test::Harness::_open_test;
  54: 
  55: # And point the original at our new function.
  56: *Test::Harness::_open_test = \&_open_test;
  57: 
  58: sub _open_test {
  59:     my($test) = shift;
  60: 
  61:     if ( $test =~ /\.phpt$/ ) {
  62:         my $phproot = $ENV{PHPROOT} or die "Must set PHPROOT\n";
  63:         my $PHPINC = ".:$phproot/Class:$phproot/Include";
  64: 
  65:         $cmd = "php -dinclude_path=$PHPINC -q $test|";
  66:         if ( open( PERL, $cmd ) ) {
  67:             return \*PERL;
  68:         } else {
  69:             print "Can't run $test. $!\n";
  70:             return;
  71:         }
  72:     } else {
  73:         # Call the original version thru our saved typeglob
  74:         return $original_open_test->($test);
  75:     }
  76: }
  77: 
  78: 1;

Replies are listed 'Best First'.
Re: Using Test::Harness to test PHP code
by miyagawa (Chaplain) on Mar 27, 2002 at 10:26 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-18 12:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found