diff options
Diffstat (limited to 'ext/spl/tests')
| -rw-r--r-- | ext/spl/tests/bug38325.phpt | 11 | ||||
| -rw-r--r-- | ext/spl/tests/bug40036.phpt | 34 | ||||
| -rw-r--r-- | ext/spl/tests/bug40091.phpt | 39 | ||||
| -rwxr-xr-x | ext/spl/tests/bug40442.phpt | 12 | ||||
| -rwxr-xr-x | ext/spl/tests/bug40872.phpt | 30 | ||||
| -rwxr-xr-x | ext/spl/tests/fileobject_003.phpt | 18 | ||||
| -rwxr-xr-x | ext/spl/tests/iterator_044.phpt | 4 | ||||
| -rwxr-xr-x | ext/spl/tests/observer_003.phpt | 60 | ||||
| -rwxr-xr-x | ext/spl/tests/observer_004.phpt | 78 | ||||
| -rwxr-xr-x | ext/spl/tests/observer_005.phpt | 144 | ||||
| -rwxr-xr-x | ext/spl/tests/spl_006.phpt | 41 | ||||
| -rwxr-xr-x | ext/spl/tests/spl_007.phpt | 26 | ||||
| -rwxr-xr-x | ext/spl/tests/spl_autoload_009.phpt | 28 |
13 files changed, 520 insertions, 5 deletions
diff --git a/ext/spl/tests/bug38325.phpt b/ext/spl/tests/bug38325.phpt new file mode 100644 index 000000000..126e1f3c0 --- /dev/null +++ b/ext/spl/tests/bug38325.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #38325 (spl_autoload_register() gaves wrong line for "class not found") +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php +spl_autoload_register(); +new Foo(); +?> +--EXPECTF-- +Fatal error: spl_autoload(): Class Foo could not be loaded in %s on line 3 diff --git a/ext/spl/tests/bug40036.phpt b/ext/spl/tests/bug40036.phpt new file mode 100644 index 000000000..8569629d3 --- /dev/null +++ b/ext/spl/tests/bug40036.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #40036 (empty() does not work correctly with ArrayObject when using ARRAY_AS_PROPS) +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php +class View extends ArrayObject +{ + public function __construct(array $array = array()) + { + parent::__construct($array, ArrayObject::ARRAY_AS_PROPS); + } +} + +$view = new View(); +$view->foo = false; +$view->bar = null; +$view->baz = ''; +if (empty($view['foo']) || empty($view->foo)) { + echo "View::foo empty\n"; +} +if (empty($view['bar']) || empty($view->bar)) { + echo "View::bar empty\n"; +} +if (empty($view['baz']) || empty($view->baz)) { + echo "View::baz empty\n"; +} +?> +===DONE=== +--EXPECT-- +View::foo empty +View::bar empty +View::baz empty +===DONE=== diff --git a/ext/spl/tests/bug40091.phpt b/ext/spl/tests/bug40091.phpt new file mode 100644 index 000000000..7d6210b8b --- /dev/null +++ b/ext/spl/tests/bug40091.phpt @@ -0,0 +1,39 @@ +--TEST-- +Bug #40091 (issue with spl_autoload_register() and 2 instances of the same class) +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php +class MyAutoloader { + function __construct($directory_to_use) {} + function autoload($class_name) { + // code to autoload based on directory + } +} + +$autloader1 = new MyAutoloader('dir1'); +spl_autoload_register(array($autloader1, 'autoload')); + +$autloader2 = new MyAutoloader('dir2'); +spl_autoload_register(array($autloader2, 'autoload')); + +print_r(spl_autoload_functions()); +?> +===DONE=== +--EXPECT-- +Array +( + [0] => Array + ( + [0] => MyAutoloader + [1] => autoload + ) + + [1] => Array + ( + [0] => MyAutoloader + [1] => autoload + ) + +) +===DONE=== diff --git a/ext/spl/tests/bug40442.phpt b/ext/spl/tests/bug40442.phpt new file mode 100755 index 000000000..fbeb22d2b --- /dev/null +++ b/ext/spl/tests/bug40442.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #40442 (ArrayObject::offsetExists broke in 5.2.1, works in 5.2.0) +--FILE-- +<?php +$a = new ArrayObject(); +$a->offsetSet('property', 0); +var_dump($a->offsetExists('property')); +?> +===DONE=== +--EXPECT-- +bool(true) +===DONE=== diff --git a/ext/spl/tests/bug40872.phpt b/ext/spl/tests/bug40872.phpt new file mode 100755 index 000000000..a48fe74fe --- /dev/null +++ b/ext/spl/tests/bug40872.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #40872 (inconsistency in offsetSet, offsetExists treatment of string enclosed integers) +--FILE-- +<?php + class Project { + public $id; + + function __construct($id) { + $this->id = $id; + } + } + + class ProjectsList extends ArrayIterator { + public function add(Project $item) { + $this->offsetSet($item->id, $item); + } + } + + $projects = new ProjectsList(); + $projects->add(new Project('1')); + $projects->add(new Project(2)); + + var_dump($projects->offsetExists(1)); + var_dump($projects->offsetExists('2')); +?> +===DONE=== +--EXPECT-- +bool(true) +bool(true) +===DONE=== diff --git a/ext/spl/tests/fileobject_003.phpt b/ext/spl/tests/fileobject_003.phpt index 74f2002d0..0b19ad7fb 100755 --- a/ext/spl/tests/fileobject_003.phpt +++ b/ext/spl/tests/fileobject_003.phpt @@ -31,6 +31,9 @@ function test($name, $lc, $lp) var_dump($f->getPath()); $l = substr($f->getPath(), -1); var_dump($l != '/' && $l != '\\' && $l == $lp); + + $fo = $o->openFile(); + var_dump($fo->getPathName(), $fo->getFileName(), $fo->getPath()); } test(dirname(__FILE__) . '/' . 'fileobject_001a.txt', 't', substr(dirname(__FILE__),-1)); @@ -52,10 +55,13 @@ bool(true) string(%d) "%sfileobject_001a.txt" string(%d) "%sfileobject_001a.txt" bool(true) -string(%d) "%sfileobject_001a.txt" +string(19) "fileobject_001a.txt" bool(true) string(%d) "%stests" bool(true) +string(%d) "%sfileobject_001a.txt" +string(19) "fileobject_001a.txt" +string(%d) "%stests" ===1=== object(SplFileInfo)#%d (0) { } @@ -67,10 +73,13 @@ bool(true) string(%d) "%stests/" string(%d) "%stests" bool(true) -string(%d) "%stests" +string(5) "tests" bool(true) string(%d) "%sspl" bool(true) +string(%d) "%stests" +string(%d) "%stests" +string(%d) "%stests" ===2=== object(SplFileInfo)#1 (0) { } @@ -82,8 +91,11 @@ bool(true) string(%d) "%stests" string(%d) "%stests" bool(true) -string(%d) "%stests" +string(%d) "tests" bool(true) string(%d) "%sspl" bool(true) +string(%d) "%stests" +string(5) "tests" +string(%d) "%sspl" ===DONE=== diff --git a/ext/spl/tests/iterator_044.phpt b/ext/spl/tests/iterator_044.phpt index e25e0d1dd..d3c625314 100755 --- a/ext/spl/tests/iterator_044.phpt +++ b/ext/spl/tests/iterator_044.phpt @@ -76,10 +76,10 @@ Exception: MyCachingIterator does not use a full cache (see CachingIterator::__c Notice: Undefined index: 0 in %siterator_044.php on line %d Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct) -Warning: CachingIterator::offsetExists() expects exactly 1 parameter, 0 given in %s/iterator_044.php on line %d +Warning: CachingIterator::offsetExists() expects exactly 1 parameter, 0 given in %siterator_044.php on line %d NULL -Warning: CachingIterator::offsetGet() expects exactly 1 parameter, 0 given in %s/iterator_044.php on line %d +Warning: CachingIterator::offsetGet() expects exactly 1 parameter, 0 given in %siterator_044.php on line %d NULL ===0=== int(0) diff --git a/ext/spl/tests/observer_003.phpt b/ext/spl/tests/observer_003.phpt new file mode 100755 index 000000000..79df8cf96 --- /dev/null +++ b/ext/spl/tests/observer_003.phpt @@ -0,0 +1,60 @@ +--TEST-- +SPL: SplObjectStorage serialization +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class TestClass +{ + public $test = 25; + + public function __construct($test = 42) + { + $this->test = $test; + } +} + +$storage = new SplObjectStorage(); + +foreach(array(1,"2","foo",true) as $value) +{ + $storage->attach(new TestClass($value)); +} + +var_dump(count($storage)); + +foreach($storage as $object) +{ + var_dump($object->test); +} + +var_dump(serialize($storage)); +echo "===UNSERIALIZE===\n"; + +$storage2 = unserialize(serialize($storage)); + +var_dump(count($storage2)); + +foreach($storage2 as $object) +{ + var_dump($object->test); +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +int(4) +int(1) +string(1) "2" +string(3) "foo" +bool(true) +string(%d) "%s" +===UNSERIALIZE=== +int(4) +int(1) +string(1) "2" +string(3) "foo" +bool(true) +===DONE=== diff --git a/ext/spl/tests/observer_004.phpt b/ext/spl/tests/observer_004.phpt new file mode 100755 index 000000000..78b480ab1 --- /dev/null +++ b/ext/spl/tests/observer_004.phpt @@ -0,0 +1,78 @@ +--TEST-- +SPL: SplObjectStorage serialization & overloading +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class TestClass +{ + public $test = 25; + + public function __construct($test = 42) + { + $this->test = $test; + } +} + +class MyStorage extends SplObjectStorage +{ + public $bla = 25; + + public function __construct($bla = 26) + { + $this->bla = $bla; + } +} + +$storage = new MyStorage(); + +foreach(array(1,2) as $value) +{ + $storage->attach(new TestClass($value)); +} + +var_dump(count($storage)); + +foreach($storage as $object) +{ + var_dump($object->test); +} + +var_dump($storage); + +var_dump(serialize($storage)); +echo "===UNSERIALIZE===\n"; + +$storage2 = unserialize(serialize($storage)); + +var_dump(count($storage2)); + +foreach($storage2 as $object) +{ + var_dump($object->test); +} + +var_dump($storage2); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +int(2) +int(1) +int(2) +object(MyStorage)#%d (1) { + ["bla"]=> + int(26) +} +string(%d) "%s" +===UNSERIALIZE=== +int(2) +int(1) +int(2) +object(MyStorage)#%d (1) { + ["bla"]=> + int(26) +} +===DONE=== diff --git a/ext/spl/tests/observer_005.phpt b/ext/spl/tests/observer_005.phpt new file mode 100755 index 000000000..46971cc2d --- /dev/null +++ b/ext/spl/tests/observer_005.phpt @@ -0,0 +1,144 @@ +--TEST-- +SPL: SplObjectStorage serialization & visibility +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class TestClass +{ + public $def = 24; + public $pub = 25; + protected $pro = 26; + private $pri = 27; + + public function __construct($pub = 42, $pro = 43, $pri = 44) + { + $this->pub = $pub; + $this->pro = $pro; + $this->pri = $pri; + } +} + +class ExtTestClass +{ +} + +class MyStorage extends SplObjectStorage +{ + public $def = 24; + public $pub = 25; + protected $pro = 26; + private $pri = 27; + + public function __construct($pub = 52, $pro = 53, $pri = 54) + { + $this->pub = $pub; + $this->pro = $pro; + $this->pri = $pri; + } +} + +class ExtStorage extends MyStorage +{ +} + +$storage = new MyStorage(1,2,3); + +foreach(array(array(4,5,6),array(7,8,9)) as $value) +{ + $storage->attach(new TestClass($value[0], $value[1], $value[2])); +} + +var_dump(count($storage)); + +foreach($storage as $object) +{ + var_dump($object); +} + +var_dump($storage); + +var_dump(serialize($storage)); +echo "===UNSERIALIZE===\n"; + +$storage2 = unserialize(serialize($storage)); + +var_dump(count($storage2)); + +foreach($storage2 as $object) +{ + var_dump($object); +} + +var_dump($storage2); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +int(2) +object(TestClass)#%d (4) { + ["def"]=> + int(24) + ["pub"]=> + int(4) + ["pro:protected"]=> + int(5) + ["pri:private"]=> + int(6) +} +object(TestClass)#%d (4) { + ["def"]=> + int(24) + ["pub"]=> + int(7) + ["pro:protected"]=> + int(8) + ["pri:private"]=> + int(9) +} +object(MyStorage)#%d (4) { + ["def"]=> + int(24) + ["pub"]=> + int(1) + ["pro:protected"]=> + int(2) + ["pri:private"]=> + int(3) +} +string(%d) "%s" +===UNSERIALIZE=== +int(2) +object(TestClass)#%d (4) { + ["def"]=> + int(24) + ["pub"]=> + int(4) + ["pro:protected"]=> + int(5) + ["pri:private"]=> + int(6) +} +object(TestClass)#%d (4) { + ["def"]=> + int(24) + ["pub"]=> + int(7) + ["pro:protected"]=> + int(8) + ["pri:private"]=> + int(9) +} +object(MyStorage)#%d (4) { + ["def"]=> + int(24) + ["pub"]=> + int(1) + ["pro:protected"]=> + int(2) + ["pri:private"]=> + int(3) +} +===DONE=== diff --git a/ext/spl/tests/spl_006.phpt b/ext/spl/tests/spl_006.phpt new file mode 100755 index 000000000..89859624d --- /dev/null +++ b/ext/spl/tests/spl_006.phpt @@ -0,0 +1,41 @@ +--TEST-- +SPL: iterator_to_array() without keys +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$it = new AppendIterator(); +$it->append(new ArrayIterator(array(1,2))); +$it->append(new ArrayIterator(array(2,3))); + +var_dump(iterator_to_array($it)); +var_dump(iterator_to_array($it, false)); +var_dump(iterator_to_array($it, true)); + +?> +===DONE=== +--EXPECT-- +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(2) + [3]=> + int(3) +} +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +===DONE=== diff --git a/ext/spl/tests/spl_007.phpt b/ext/spl/tests/spl_007.phpt new file mode 100755 index 000000000..dcd63f9b5 --- /dev/null +++ b/ext/spl/tests/spl_007.phpt @@ -0,0 +1,26 @@ +--TEST-- +SPL: iterator_apply() with callback using __call() +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class Foo { + public function __call($name, $params) { + echo "Called $name.\n"; + return true; + } +} + +$it = new ArrayIterator(array(1, 2, 3)); + +iterator_apply($it, array(new Foo, "foobar")); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +Called foobar. +Called foobar. +Called foobar. +===DONE=== diff --git a/ext/spl/tests/spl_autoload_009.phpt b/ext/spl/tests/spl_autoload_009.phpt new file mode 100755 index 000000000..057e96616 --- /dev/null +++ b/ext/spl/tests/spl_autoload_009.phpt @@ -0,0 +1,28 @@ +--TEST--
+SPL: spl_autoload() and friends
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--INI--
+include_path=.
+--FILE--
+<?php
+
+function my_autoload($name)
+{
+ require $name . '.class.inc';
+ var_dump(class_exists($name));
+}
+
+spl_autoload_register("spl_autoload");
+spl_autoload_register("my_autoload");
+
+$obj = new testclass;
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECTF--
+%stestclass.inc
+%stestclass.class.inc
+bool(true)
+===DONE===
|
