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

[email protected] 7 Jun 2005 21:51:48 -0000
Newsgroups perl.php.sandwich.dev
Message-ID <[email protected]>
Author: gschlossnagle
Date: Tue Jun  7 14:51:47 2005
New Revision: 1075

Added:
   PHP-Sandwich/trunk/t/16.t   (contents, props changed)
Modified:
   PHP-Sandwich/trunk/phpfuncs.c
Log:
Add tests for blessed reference testing



Modified: PHP-Sandwich/trunk/phpfuncs.c
==============================================================================
--- PHP-Sandwich/trunk/phpfuncs.c	(original)
+++ PHP-Sandwich/trunk/phpfuncs.c	Tue Jun  7 14:51:47 2005
@@ -586,7 +586,7 @@ int sv_get_class_name(zval *obj, char **
     pl = (struct plsv *) zend_object_store_get_object(obj TSRMLS_CC);
     tmp = HvNAME((SvSTASH(SvRV(pl->sv))));
     if(!tmp) return FAILURE;
-    *class_name_len = strlen(tmp) + sizeof("PerlSV::");
+    *class_name_len = strlen(tmp) + sizeof("PerlSV::") - 1;
     *class_name = emalloc(*class_name_len);
     strncpy(*class_name, "PerlSV::", sizeof("PerlSV::"));
     strcat(*class_name, tmp);
@@ -675,12 +675,9 @@ static void plsv_iter_move_forwards(zend
     I->keylen = 0;
   }
   if((value = hv_iternextsv(I->hv, &key, &keylen)) != NULL) {
-      zval *foo;
-      MAKE_STD_ZVAL(foo);
-      ZVAL_STRING(foo, "test", 1);
       I->key = estrndup(key, keylen);
       I->keylen = keylen + 1;
-      I->fetch_ahead = foo; // SvZval(value TSRMLS_CC);
+      I->fetch_ahead = SvZval(value TSRMLS_CC);
   }
 }
 

Added: PHP-Sandwich/trunk/t/16.t
==============================================================================
--- (empty file)
+++ PHP-Sandwich/trunk/t/16.t	Tue Jun  7 14:51:47 2005
@@ -0,0 +1,60 @@
+#!/opt/ecelerity/3rdParty/bin/perl
+use strict;
+use Test::More tests => 7;
+
+BEGIN {
+    diag "Testing passing blessed references into PHP";
+    use_ok 'PHP' or die;
+    use_ok 'PHP::Interpreter' or die;
+}
+
+our @var;
+our $scalar;
+
+push @var, "hello";
+push @var, "goodbye";
+
+ok my $p = PHP::Interpreter->new, "Create new PHP interpreter";
+$p->eval(q/
+
+function property_access($obj, $prop)
+{
+  return $obj->$prop;
+}
+
+function method_call($obj, $meth)
+{
+  return $obj->$meth();
+}
+
+function props_as_array($obj)
+{
+  $rv = array();
+  foreach($obj as $k => $v) {
+    $rv[$k] = $v;
+  }
+  return $rv;
+}
+
+/);
+my $foo = new Foo();
+$foo->{bar} = 'bar';
+$foo->{baz} = 'baz';
+is $p->get_class($foo), 'PerlSV::Foo', 'Checking class name';
+is $p->property_access($foo, 'bar'), 'bar', 'Checking property access';
+is $p->method_call($foo, 'get'), 'bar', 'Checking method calls';
+is_deeply $p->props_as_array($foo), {'bar' => 'bar', 'baz' => 'baz'}, 'Checking iterators';
+package Foo;
+
+sub new {
+  my $self = shift;
+  my $class = ref($self) || $self;
+  bless {}, $class;
+}
+
+sub get {
+  my ($self) = @_;
+  return $self->{bar};
+}
+
+1;