]> granicus.if.org Git - php/commitdiff
Backport some SplObjectStorage tests to 5.2
authorWilliam Martin <wimartin@php.net>
Fri, 29 Jan 2010 15:43:39 +0000 (15:43 +0000)
committerWilliam Martin <wimartin@php.net>
Fri, 29 Jan 2010 15:43:39 +0000 (15:43 +0000)
ext/spl/tests/SplObjectStorage_attach_invalid_parameter.phpt [new file with mode: 0644]
ext/spl/tests/SplObjectStorage_contains_invalid_parameter.phpt [new file with mode: 0644]
ext/spl/tests/SplObjectStorage_current_empty_storage.phpt [new file with mode: 0644]
ext/spl/tests/SplObjectStorage_detach_invalid_parameter.phpt [new file with mode: 0644]
ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter1.phpt [new file with mode: 0644]
ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter2.phpt [new file with mode: 0644]
ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter3.phpt [new file with mode: 0644]

diff --git a/ext/spl/tests/SplObjectStorage_attach_invalid_parameter.phpt b/ext/spl/tests/SplObjectStorage_attach_invalid_parameter.phpt
new file mode 100644 (file)
index 0000000..ebf7a2f
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Check that SplObjectStorage::attach generates a warning and returns NULL when bad params are passed
+--CREDITS--
+PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com)
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+$s = new SplObjectStorage();
+
+var_dump($s->attach(true));
+var_dump($s->attach(new stdClass, true, true));
+
+?>
+--EXPECTF--
+Warning: SplObjectStorage::attach() expects parameter 1 to be object, boolean given in %s on line %d
+NULL
+
+Warning: SplObjectStorage::attach() expects exactly 1 parameter, 3 given in %s on line %d
+NULL
+
diff --git a/ext/spl/tests/SplObjectStorage_contains_invalid_parameter.phpt b/ext/spl/tests/SplObjectStorage_contains_invalid_parameter.phpt
new file mode 100644 (file)
index 0000000..0e96cd8
--- /dev/null
@@ -0,0 +1,45 @@
+--TEST--
+Check that SplObjectStorage::contains generate a warning and returns NULL when passed non-object param
+--CREDITS--
+PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com)
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+$data_provider = array(
+       array(),
+       true,
+       "string",
+       12345,
+       1.2345,
+       NULL
+);
+
+foreach($data_provider as $input) {
+
+       $s = new SplObjectStorage();
+
+       var_dump($s->contains($input));
+}
+
+?>
+--EXPECTF--
+Warning: SplObjectStorage::contains() expects parameter 1 to be object, array given in %s on line %d
+NULL
+
+Warning: SplObjectStorage::contains() expects parameter 1 to be object, boolean given in %s on line %d
+NULL
+
+Warning: SplObjectStorage::contains() expects parameter 1 to be object, %unicode_string_optional% given in %s on line %d
+NULL
+
+Warning: SplObjectStorage::contains() expects parameter 1 to be object, integer given in %s on line %d
+NULL
+
+Warning: SplObjectStorage::contains() expects parameter 1 to be object, double given in %s on line %d
+NULL
+
+Warning: SplObjectStorage::contains() expects parameter 1 to be object, null given in %s on line %d
+NULL
+
diff --git a/ext/spl/tests/SplObjectStorage_current_empty_storage.phpt b/ext/spl/tests/SplObjectStorage_current_empty_storage.phpt
new file mode 100644 (file)
index 0000000..3fc883d
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Check that SplObjectStorage::current returns NULL when storage is empty
+--CREDITS--
+PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com)
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+$s = new SplObjectStorage();
+
+var_dump($s->current());
+
+?>
+--EXPECT--
+NULL
+
diff --git a/ext/spl/tests/SplObjectStorage_detach_invalid_parameter.phpt b/ext/spl/tests/SplObjectStorage_detach_invalid_parameter.phpt
new file mode 100644 (file)
index 0000000..a87dde9
--- /dev/null
@@ -0,0 +1,45 @@
+--TEST--
+Check that SplObjectStorage::detach generate a warning and returns NULL when passed non-object param
+--CREDITS--
+PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com)
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+$data_provider = array(
+       array(),
+       true,
+       "string",
+       12345,
+       1.2345,
+       NULL
+);
+
+foreach($data_provider as $input) {
+
+       $s = new SplObjectStorage();
+
+       var_dump($s->detach($input));
+}
+
+?>
+--EXPECTF--
+Warning: SplObjectStorage::detach() expects parameter 1 to be object, array given in %s on line %d
+NULL
+
+Warning: SplObjectStorage::detach() expects parameter 1 to be object, boolean given in %s on line %d
+NULL
+
+Warning: SplObjectStorage::detach() expects parameter 1 to be object, %unicode_string_optional% given in %s on line %d
+NULL
+
+Warning: SplObjectStorage::detach() expects parameter 1 to be object, integer given in %s on line %d
+NULL
+
+Warning: SplObjectStorage::detach() expects parameter 1 to be object, double given in %s on line %d
+NULL
+
+Warning: SplObjectStorage::detach() expects parameter 1 to be object, null given in %s on line %d
+NULL
+
diff --git a/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter1.phpt b/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter1.phpt
new file mode 100644 (file)
index 0000000..96f809e
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+Check that SplObjectStorage::unserialize returns NULL when non-string param is passed
+--CREDITS--
+PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com)
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+$data_provider = array(
+       array(),
+       new stdClass(),
+);
+
+foreach($data_provider as $input) {
+
+       $s = new SplObjectStorage();
+
+       var_dump($s->unserialize($input));
+}
+
+?>
+--EXPECTF--
+Warning: SplObjectStorage::unserialize() expects parameter 1 to be string, array given in %s on line %d
+NULL
+
+Warning: SplObjectStorage::unserialize() expects parameter 1 to be string, object given in %s on line %d
+NULL
+
diff --git a/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter2.phpt b/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter2.phpt
new file mode 100644 (file)
index 0000000..12d596b
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+Check that SplObjectStorage::unserialize throws exception when numeric value passed
+--CREDITS--
+PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com)
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+$data_provider = array(
+    12345,
+    1.2345,
+    PHP_INT_MAX,
+    'x:rubbish', // rubbish after the 'x:' prefix
+    'x:i:2;O:8:"stdClass":0:{},s:5:"value";;m:a:0:{}',
+);
+
+foreach($data_provider as $input) {
+
+       $s = new SplObjectStorage();
+
+    try {
+        $s->unserialize($input);
+    } catch(UnexpectedValueException $e) {
+        echo $e->getMessage() . PHP_EOL;
+    }
+}
+
+?>
+--EXPECTF--
+Error at offset %d of %d bytes
+Error at offset %d of %d bytes
+Error at offset %d of %d bytes
+Error at offset %d of %d bytes
+Error at offset %d of %d bytes
+
diff --git a/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter3.phpt b/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter3.phpt
new file mode 100644 (file)
index 0000000..cb11185
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Check that SplObjectStorage::unserialize throws exception when NULL passed
+--CREDITS--
+PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com)
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+$s = new SplObjectStorage();
+
+try {
+    $s->unserialize(NULL);
+} catch(UnexpectedValueException $e) {
+    echo $e->getMessage();
+}
+
+?>
+--EXPECTF--
+Empty serialized string cannot be empty
+