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