com php-src: Add tests for invalid count() operations: Zend/tests/generators/errors/count_error.phpt ext/standar d/tests/array/count_invalid.phpt
| From: | Joe Watkins | Date: | Thu, 17 Nov 2016 09:33:04 +0000 |
| Subject: | com php-src: Add tests for invalid count() operations: Zend/tests/generators/errors/count_error.phpt ext/standar d/tests/array/count_invalid.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95820@lists.php.net to get a copy of this message | ||
Commit: b000f5c3413c49be19568d225f9ff6312f181f3d
Author: Craig Duncan <git@duncanc.co.uk> Tue, 4 Oct 2016 13:27:18 +0100
Committer: Joe Watkins <krakjoe@php.net> Thu, 17 Nov 2016 09:33:04 +0000
Parents: aaf7341b1ce6889387b4dcdf5a9b04a651076bc6
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b000f5c3413c49be19568d225f9ff6312f181f3d
Log:
Add tests for invalid count() operations
Changed paths:
A Zend/tests/generators/errors/count_error.phpt
A ext/standard/tests/array/count_invalid.phpt
Diff:
diff --git a/Zend/tests/generators/errors/count_error.phpt
b/Zend/tests/generators/errors/count_error.phpt
new file mode 100644
index 0000000..97e03e7
--- /dev/null
+++ b/Zend/tests/generators/errors/count_error.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Generators can't be counted
+--FILE--
+<?php
+
+function gen() { yield; }
+
+$gen = gen();
+
+try {
+ count($gen);
+} catch (Exception $e) {
+ echo $e;
+}
+
+?>
+--EXPECTF--
+Warning: count(): Parameter must be an array or an object that implements Countable in %s on line
%d
diff --git a/ext/standard/tests/array/count_invalid.phpt
b/ext/standard/tests/array/count_invalid..phpt
new file mode 100644
index 0000000..95da00d
--- /dev/null
+++ b/ext/standard/tests/array/count_invalid.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Only arrays and countable objects can be counted
+--FILE--
+<?php
+
+$result = count(null);
+var_dump($result);
+
+$result = count("string");
+var_dump($result);
+
+$result = count(123);
+var_dump($result);
+
+$result = count(true);
+var_dump($result);
+
+$result = count(false);
+var_dump($result);
+
+$result = count((object) []);
+var_dump($result);
+
+?>
+--EXPECTF--
+Warning: count(): Parameter must be an array or an object that implements Countable in %s on line
%d
+int(0)
+
+Warning: count(): Parameter must be an array or an object that implements Countable in %s on line
%d
+int(1)
+
+Warning: count(): Parameter must be an array or an object that implements Countable in %s on line
%d
+int(1)
+
+Warning: count(): Parameter must be an array or an object that implements Countable in %s on line
%d
+int(1)
+
+Warning: count(): Parameter must be an array or an object that implements Countable in %s on line
%d
+int(1)
+
+Warning: count(): Parameter must be an array or an object that implements Countable in %s on line
%d
+int(1)