Skip to content

Commit

Permalink
new tests were added, old tests were improved
Browse files Browse the repository at this point in the history
  • Loading branch information
zenovich committed Aug 24, 2012
1 parent 1e98a9e commit effa351
Show file tree
Hide file tree
Showing 34 changed files with 707 additions and 53 deletions.
2 changes: 1 addition & 1 deletion tests/Runkit_Sandbox__call_user_func_closure.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--TEST--
Runkit_Sandbox::__call_user_func() method with closure as the first parameter
--SKIPIF--
<?php if(!extension_loaded("runkit") || !RUNKIT_FEATURE_SANDBOX) print "skip";
<?php if(!extension_loaded("runkit") || !RUNKIT_FEATURE_SANDBOX) print "skip";
/* May not be available due to lack of TSRM interpreter support */
if(!function_exists("runkit_lint")) print "skip";
if(version_compare(PHP_VERSION, '5.3.0', '<')) print "skip";
Expand Down
2 changes: 1 addition & 1 deletion tests/namespaces.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
runkit_method_redefine() function
runkit_method_add(), runkit_method_redefine(), runkit_method_rename() & runkit_method_copy() functions with namespaces
--SKIPIF--
<?php
if(!extension_loaded("runkit") || !RUNKIT_FEATURE_MANIPULATION) print "skip";
Expand Down
6 changes: 5 additions & 1 deletion tests/runkit_default_property_add.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ class RunkitClass {

$className = 'RunkitClass';
$propName = 'publicProperty';
$value = 1;
runkit_default_property_add($className, 'constArray', array('a'=>1));
runkit_default_property_add($className, $propName, 1, RUNKIT_ACC_PUBLIC);
runkit_default_property_add($className, $propName, $value, RUNKIT_ACC_PUBLIC);
runkit_default_property_add($className, 'privateProperty', "a", RUNKIT_ACC_PRIVATE);
runkit_default_property_add($className, 'protectedProperty', NULL, RUNKIT_ACC_PROTECTED);
$obj = new $className();
runkit_default_property_add($className, 'dynamic', $obj);
$value = 10;
print_r(new $className());

runkit_default_property_add('stdClass', 'str', 'test');
Expand Down Expand Up @@ -48,6 +50,8 @@ RunkitClass Object
[publicProperty] => 1
[privateProperty%sprivate] => a
[protectedProperty:protected] =>%w
%w[dynamic] => RunkitClass Object
%w*RECURSION*%w
)

)
Expand Down
86 changes: 86 additions & 0 deletions tests/runkit_default_property_add_to_subclasses.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
--TEST--
runkit_default_property_add() add properties to subclasses
--SKIPIF--
<?php if(!extension_loaded("runkit") || !RUNKIT_FEATURE_MANIPULATION) print "skip";
if(array_shift(explode('.', PHP_VERSION)) < 5) print "skip";
?>
--INI--
error_reporting=E_ALL
display_errors=on
--FILE--
<?php
class RunkitClass {
public function setPrivate() {$this->privateProperty = "b";}
public function setProtected() {$this->protectedProperty = 1;}
}

class RunkitSubClass extends RunkitClass {}
class StdSubClass extends stdClass {}

$className = 'RunkitClass';
$propName = 'publicProperty';
$parentObj = new $className;
runkit_default_property_add($className, 'constArray', array('a'=>1));
runkit_default_property_add($className, $propName, 1, RUNKIT_ACC_PUBLIC);
runkit_default_property_add($className, 'privateProperty', "a", RUNKIT_ACC_PRIVATE);
runkit_default_property_add($className, 'protectedProperty', NULL, RUNKIT_ACC_PROTECTED);
$obj = new RunkitSubClass;
runkit_default_property_add($className, 'dynamic', $obj);

$parentObj->constArray = array('b'=>2);
$parentObj->publicProperty = 2;
$parentObj->setPrivate();
$parentObj->setProtected();
$parentObj->dynamic = $parentObj;

print_r($obj);
print_r(new RunkitSubClass);

runkit_default_property_add('StdSubClass', 'str', 'test');

$obj = new StdSubClass();
print_r($obj);
?>
--EXPECTF--
RunkitSubClass Object
(
[constArray] => Array
(
[a] => 1
)

[publicProperty] => 1
[privateProperty%sprivate] => a
[protectedProperty:protected] =>%w
%w[dynamic] => RunkitSubClass Object
%w*RECURSION*%w
)
RunkitSubClass Object
(
[constArray] => Array
(
[a] => 1
)

[publicProperty] => 1
[privateProperty%sprivate] => a
[protectedProperty:protected] =>%w
[dynamic] => RunkitSubClass Object
(
[constArray] => Array
(
[a] => 1
)

[publicProperty] => 1
[privateProperty%sprivate] => a
[protectedProperty:protected] =>%w
%w[dynamic] => RunkitSubClass Object
%w*RECURSION*%w
)

)
StdSubClass Object
(
[str] => test
)
3 changes: 2 additions & 1 deletion tests/runkit_default_property_remove.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
runkit_default_property_add() function
runkit_default_property_remove() function
--SKIPIF--
<?php if(!extension_loaded("runkit") || !RUNKIT_FEATURE_MANIPULATION) print "skip";
if(array_shift(explode(".", PHP_VERSION)) < 5) print "skip";
Expand Down Expand Up @@ -34,6 +34,7 @@ print_r(new $className());

$obj = new stdClass();
runkit_default_property_remove('stdClass', 'str');
$obj = NULL;
?>
--EXPECTF--
Warning: runkit_default_property_remove(): RunkitClass::publicproperty does not exist in %s on line %d
Expand Down
4 changes: 2 additions & 2 deletions tests/runkit_default_property_remove4.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
runkit_default_property_add() function (PHP4)
runkit_default_property_remove() function (PHP4)
--SKIPIF--
<?php if(!extension_loaded("runkit") || !RUNKIT_FEATURE_MANIPULATION) print "skip";
if(array_shift(explode(".", PHP_VERSION)) != 4) print "skip";
Expand Down Expand Up @@ -32,7 +32,7 @@ $obj = new stdClass();
runkit_default_property_remove('stdClass', 'str');
?>
--EXPECTF--
Warning: runkit_default_property_remove(): RunkitClass::publicproperty does not exist in %s on line %d
Warning: runkit_default_property_remove(): runkitclass::publicproperty does not exist in %s on line %d
runkitclass Object
(
[publicProperty] => 1
Expand Down
52 changes: 52 additions & 0 deletions tests/runkit_default_property_remove_from_subclasses.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--TEST--
runkit_default_property_remove() remove properties from subclasses
--SKIPIF--
<?php if(!extension_loaded("runkit") || !RUNKIT_FEATURE_MANIPULATION) print "skip";
if(array_shift(explode(".", PHP_VERSION)) < 5) print "skip";
?>
--INI--
error_reporting=E_ALL
display_errors=On
--FILE--
<?php
class RunkitClass {
public $constArray = array();
public $publicProperty = 1;
public $publicproperty = 2;
private $privateProperty = "a";
protected $protectedProperty = "b";
}

class RunkitSubClass extends RunkitClass {}
class StdSubClass extends stdClass {}

ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);

$className = 'RunkitClass';
$obj = new RunkitSubClass();
runkit_default_property_add($className, 'dynamic', $obj);

runkit_default_property_remove($className, 'dynamic');
runkit_default_property_remove($className, 'publicproperty');
runkit_default_property_remove($className, 'publicproperty');
runkit_default_property_remove($className, 'privateProperty');
runkit_default_property_remove($className, 'protectedProperty');
runkit_default_property_remove($className, 'constArray');
print_r(new RunkitSubClass());

$obj = new StdSubClass();
runkit_default_property_add('StdSubClass', 'str', "test");
runkit_default_property_remove('StdSubClass', 'str');
print_r($obj);
$obj = NULL;
?>
--EXPECTF--
Warning: runkit_default_property_remove(): RunkitClass::publicproperty does not exist in %s on line %d
RunkitSubClass Object
(
[publicProperty] => 1
)
StdSubClass Object
(
)
48 changes: 48 additions & 0 deletions tests/runkit_default_property_remove_from_subclasses4.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
runkit_default_property_remove() remove properties from subclasses (PHP4)
--SKIPIF--
<?php if(!extension_loaded("runkit") || !RUNKIT_FEATURE_MANIPULATION) print "skip";
if(array_shift(explode(".", PHP_VERSION)) >= 5) print "skip";
?>
--INI--
error_reporting=E_ALL
display_errors=On
--FILE--
<?php
class RunkitClass {
var $constArray = array();
var $publicProperty = 1;
var $publicproperty = 2;
}

class RunkitSubClass extends RunkitClass {}
class StdSubClass extends stdClass {}

ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);

$className = 'RunkitClass';
$obj = new RunkitSubClass();
runkit_default_property_add($className, 'dynamic', $obj);

runkit_default_property_remove($className, 'dynamic');
runkit_default_property_remove($className, 'publicproperty');
runkit_default_property_remove($className, 'publicproperty');
runkit_default_property_remove($className, 'constArray');
print_r(new RunkitSubClass());

$obj = new StdSubClass();
runkit_default_property_add('StdSubClass', 'str', "test");
runkit_default_property_remove('StdSubClass', 'str');
print_r($obj);
$obj = NULL;
?>
--EXPECTF--
Warning: runkit_default_property_remove(): runkitclass::publicproperty does not exist in %s on line %d
runkitsubclass Object
(
[publicProperty] => 1
)
stdsubclass Object
(
)
63 changes: 63 additions & 0 deletions tests/runkit_default_property_remove_inheritance.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
--TEST--
runkit_default_property_remove() remove properties with inheritance
--SKIPIF--
<?php if(!extension_loaded("runkit") || !RUNKIT_FEATURE_MANIPULATION) print "skip";
if(array_shift(explode(".", PHP_VERSION)) < 5) print "skip";
?>
--INI--
error_reporting=E_ALL
display_errors=On
--FILE--
<?php
class RunkitClass {
public $publicProperty = 1;
private $privateProperty = "a";
protected $protectedProperty = "b";
private static $staticProperty = "s";
public $removedProperty = "r";
}

class RunkitSubClass extends RunkitClass {
public $publicProperty = 2;
private $privateProperty = "aa";
protected $protectedProperty = "bb";
protected $staticProperty = "ss";
}
class RunkitSubSubClass extends RunkitSubClass {
protected $protectedProperty = "cc";
}

ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);

$className = 'RunkitClass';
$obj = new RunkitSubSubClass();

runkit_default_property_remove($className, 'publicProperty');
runkit_default_property_remove($className, 'privateProperty');
runkit_default_property_remove($className, 'protectedProperty');
runkit_default_property_remove('RunkitSubClass', 'removedProperty');
runkit_default_property_remove($className, 'removedProperty');
print_r(new RunkitClass());
print_r(new RunkitSubClass());
print_r(new $obj);
?>
--EXPECTF--
Warning: runkit_default_property_remove(): RunkitSubClass::removedProperty does not exist in %s on line %d
RunkitClass Object
(
)
RunkitSubClass Object
(
[publicProperty] => 2
[privateProperty%sprivate] => aa
[protectedProperty:protected] => bb
[staticProperty:protected] => ss
)
RunkitSubSubClass Object
(
[protectedProperty:protected] => cc
[publicProperty] => 2
[privateProperty%sprivate] => aa
[staticProperty:protected] => ss
)
7 changes: 5 additions & 2 deletions tests/runkit_function_add.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ runkit_function_add() function
<?php if(!extension_loaded("runkit") || !RUNKIT_FEATURE_MANIPULATION) print "skip"; ?>
--FILE--
<?php
runkit_function_add('runkit_sample', '$a, $b, $c = "baz"', 'echo "a is $a\nb is $b\nc is $c\n";');
runkit_sample('foo','bar');
$name = 'runkitSample';
runkit_function_add($name, '$a, $b, $c = "baz"', 'static $is="is"; for($i=0; $i<10; $i++) {} echo "a $is $a\nb $is $b\nc $is $c\n";');
runkitSample('foo','bar');
echo $name;
?>
--EXPECT--
a is foo
b is bar
c is baz
runkitSample
37 changes: 27 additions & 10 deletions tests/runkit_function_copy.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,39 @@ runkit_function_copy() function
<?php if(!extension_loaded("runkit") || !RUNKIT_FEATURE_MANIPULATION) print "skip"; ?>
--FILE--
<?php
function runkit_sample($n) {
echo "Runkit Sample: $n\n";
function runkitSample($n) {
static $runkit = "Runkit";
$v = explode(".", PHP_VERSION);
if($v[0] >= 5) {
$constArray = array('a'=>1);
}
for ($i = 0; $i < 10; $i++) {}
$sample = "Sample";
if ($v[0] >= 5 && $constArray != array('a'=>1)) {
echo "FAIL!";
}
echo "$runkit $sample: $n\n";
}

runkit_sample(1);
runkit_function_copy('runkit_sample','runkit_duplicate');
runkit_sample(2);
runkit_duplicate(3);
runkit_function_remove('runkit_sample');
if (function_exists('runkit_sample')) {
echo "runkit_sample() still exists!\n";
$oldName = 'runkitSample';
$newName = 'runkitDuplicate';

runkitSample(1);
runkit_function_copy($oldName, $newName);
runkitSample(2);
runkitDuplicate(3);
runkit_function_remove($oldName);
if (function_exists('runkitSample')) {
echo "runkitSample() still exists!\n";
}
runkit_duplicate(4);
runkitDuplicate(4);
echo $oldName, "\n";
echo $newName, "\n";
?>
--EXPECT--
Runkit Sample: 1
Runkit Sample: 2
Runkit Sample: 3
Runkit Sample: 4
runkitSample
runkitDuplicate
Loading

0 comments on commit effa351

Please sign in to comment.