FAQ
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';

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-sandwich-dev @
categoriesperl
postedJun 5, '06 at 4:33a
activeJun 5, '06 at 4:33a
posts1
users1
websiteperl.org

1 user in discussion

Theory: 1 post

People

Translate

site design / logo © 2018 Grokbase