[svn:PHP-Sandwich] rev 1426 - in PHP-Sandwich/trunk: . t

[email protected] 30 Jul 2005 01:57:40 -0000
Newsgroups perl.php.sandwich.dev
Message-ID <[email protected]>
Author: theory
Date: Fri Jul 29 18:57:40 2005
New Revision: 1426

Added:
   PHP-Sandwich/trunk/t/test_perl_classes.t
Modified:
   PHP-Sandwich/trunk/MANIFEST
Log:
Added tests for using Perl classes in PHP. I get a bus error when I try
to use the IO::File XS module.

Modified: PHP-Sandwich/trunk/MANIFEST
==============================================================================
--- PHP-Sandwich/trunk/MANIFEST	(original)
+++ PHP-Sandwich/trunk/MANIFEST	Fri Jul 29 18:57:40 2005
@@ -33,5 +33,6 @@ t/9.t
 t/pod.t
 t/pod_coverage.t
 t/test.inc
+t/test_perl_classes.t
 TODO
 typemap

Added: PHP-Sandwich/trunk/t/test_perl_classes.t
==============================================================================
--- (empty file)
+++ PHP-Sandwich/trunk/t/test_perl_classes.t	Fri Jul 29 18:57:40 2005
@@ -0,0 +1,34 @@
+#!/opt/ecelerity/3rdParty/bin/perl -w
+use strict;
+use Test::More tests => 6;
+use IO::File;
+
+BEGIN {
+    use_ok 'PHP::Interpreter' or die;
+}
+
+ok my $php = PHP::Interpreter->new, "Create new PHP interpreter";
+
+# Try using a pure Perl class.
+ok $php->eval(q/
+    $perl = Perl::getInstance();
+    $test = $perl->call('Test::Builder::new', 'Test::Builder');
+    return $test->ok(1, "This test should run from PHP!");
+/), "The test should have passed and returned a true value";
+
+# Try using an XS module.
+sub file {  __FILE__ }
+sub line { my $fh = shift; return <$fh> }
+ok my $ret = $php->eval(q/
+    $perl = Perl::getInstance();
+    $file = $perl->call('file');
+    $fh = $perl->call('IO::File::new', 'IO::File', "<$file");
+    if ($fh) {
+        return $perl->call($fh);
+    } else {
+         throw new Error("Could not open $file");
+    }
+/), "We should get a value back from the file";
+
+like $ret, qr/^#\!.*perl\s+-w$/, "We should have a shebang line";
+