develooper Front page | perl.php.sandwich.dev | Postings from June 2006

[svn:PHP-Sandwich] r6470 - PHP-Sandwich/trunk/t

From:
theory
Date:
June 4, 2006 21:33
Subject:
[svn:PHP-Sandwich] r6470 - PHP-Sandwich/trunk/t
Message ID:
20060605043321.1C01BCBA47@x12.develooper.com
Author: theory
Date: Sun Jun  4 21:33:20 2006
New Revision: 6470

Modified:
   PHP-Sandwich/trunk/t/test_perl_classes.t

Log:
Added more tests for call_method. Curiously, PHP seems to think that isa()
returns NULL, but the diags I have in the code show that it does in fact
return 1. Wha??


Modified: PHP-Sandwich/trunk/t/test_perl_classes.t
==============================================================================
--- PHP-Sandwich/trunk/t/test_perl_classes.t	(original)
+++ PHP-Sandwich/trunk/t/test_perl_classes.t	Sun Jun  4 21:33:20 2006
@@ -1,9 +1,20 @@
 #!/opt/ecelerity/3rdParty/bin/perl -w
 use strict;
-use Test::More tests => 12;
+use Test::More tests => 15;
 use Test::Builder;
 use IO::File;
 
+BASE: {
+    package My::Base;
+    sub new { bless {} => shift }
+    sub list { wantarray ? (1,2,3,4) : [1,2,3,4] }
+}
+
+SUB: {
+    package My::Sub;
+    use base 'My::Base';
+}
+
 BEGIN {
     use_ok 'PHP::Interpreter' or die;
 }
@@ -44,7 +55,6 @@
 ^), "We should get a value back from the file";
 like $ret, qr/^#\!.*perl\s+-w$/, "We should have a shebang line";
 
-
 # Make sure that eval() works on class methods, too.
 ok $ret = $php->eval(q^
     $perl = Perl::getInstance();
@@ -58,7 +68,7 @@
 ^), "We should get a value back from the file";
 like $ret, qr/^#\!.*perl\s+-w$/, "We should have a shebang line";
 
-# Make sure that call_method() calls class methods, too.
+# Make sure that call_methodod() calls class methods, too.
 ok $ret = $php->eval(q^
     $perl = Perl::getInstance();
     $file = $perl->call('file');
@@ -71,3 +81,27 @@
     }
 ^), "We should get a value back from the file";
 like $ret, qr/^#\!.*perl\s+-w$/, "We should have a shebang line";
+
+NO: {
+    no warnings 'redefine';
+    my $orig = \&UNIVERSAL::isa;
+    local *UNIVERSAL::isa = sub {
+        diag $orig->(@_);
+        return $orig->(@_);
+    };
+
+# Make sure that new() uses inheritance.
+ok $ret = $php->eval(q^
+    $perl = Perl::getInstance();
+    $sub  = $perl->new('My::Sub');
+    # These seem to be returning NULL, even though the diag above shows 1.
+    return $sub->isa('My::Base') && $sub->isa('My::Sub');
+^), 'The object created by new() should obey inheritance';
+}
+
+# Make sure that a list is returned.
+ok $ret = $php->eval(q^
+    $perl = Perl::getInstance();
+    return $perl->call_method('My::Sub', 'list');
+^), 'We should get the return value of a class method call';
+is_deeply $ret, [1,2,3,4], 'And it should be the proper array';



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About