Commit:    5f6b20a44d833ede5e47b3b09c98678522347de1
Author:    Ben Ramsey <ram...@php.net>         Sat, 14 Apr 2012 11:19:55 -0500
Parents:   e921d28ae31e77965800c29454c4d426650126f0
Branches:  PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=5f6b20a44d833ede5e47b3b09c98678522347de1

Log:
array_column: Improved tests

Changed paths:
  D  ext/standard/tests/array/array_column.phpt
  A  ext/standard/tests/array/array_column_basic.phpt
  A  ext/standard/tests/array/array_column_error.phpt

diff --git a/ext/standard/tests/array/array_column.phpt 
b/ext/standard/tests/array/array_column.phpt
deleted file mode 100644
index a7a1b45..0000000
--- a/ext/standard/tests/array/array_column.phpt
+++ /dev/null
@@ -1,169 +0,0 @@
---TEST--
-Test array_column() function
---FILE--
-<?php
-/* Prototype:
- *  array array_column(array $input, mixed $key);
- * Description:
- *  Returns an array containing all the values from
- *  the specified "column" in a two-dimensional array.
- */
-
-echo "*** Testing basic functionalities ***\n";
-/* Array representing a possible record set returned from a database */
-$records = array(
-       array(
-               'id' => 1,
-               'first_name' => 'John',
-               'last_name' => 'Doe'
-       ),
-       array(
-               'id' => 2,
-               'first_name' => 'Sally',
-               'last_name' => 'Smith'
-       ),
-       array(
-               'id' => 3,
-               'first_name' => 'Jane',
-               'last_name' => 'Jones'
-       )
-);
-
-echo "-- first_name column from recordset --\n";
-var_dump(array_column($records, 'first_name'));
-
-echo "-- id column from recordset --\n";
-var_dump(array_column($records, 'id'));
-
-echo "\n*** Testing multiple data types ***\n";
-$file = basename(__FILE__);
-$fh = fopen($file, 'r', true);
-$values = array(
-       array(
-               'id' => 1,
-               'value' => new stdClass
-       ),
-       array(
-               'id' => 2,
-               'value' => 34.2345
-       ),
-       array(
-               'id' => 3,
-               'value' => true
-       ),
-       array(
-               'id' => 4,
-               'value' => false
-       ),
-       array(
-               'id' => 5,
-               'value' => null
-       ),
-       array(
-               'id' => 6,
-               'value' => 1234
-       ),
-       array(
-               'id' => 7,
-               'value' => 'Foo'
-       ),
-       array(
-               'id' => 8,
-               'value' => $fh
-       )
-);
-var_dump(array_column($values, 'value'));
-
-echo "\n*** Testing numeric column keys ***\n";
-$numericCols = array(
-       array('aaa', '111'),
-       array('bbb', '222'),
-       array('ccc', '333')
-);
-var_dump(array_column($numericCols, 1));
-
-echo "\n*** Testing failure to find specified column ***\n";
-var_dump(array_column($numericCols, 2));
-var_dump(array_column($numericCols, 'foo'));
-
-echo "\n*** Testing single dimensional array ***\n";
-$singleDimension = array('foo', 'bar', 'baz');
-var_dump(array_column($singleDimension, 1));
-
-echo "\n*** Testing columns not present in all rows ***\n";
-$mismatchedColumns = array(
-    array('a' => 'foo', 'b' => 'bar'),
-    array('a' => 'baz', 'c' => 'qux'),
-);
-var_dump(array_column($mismatchedColumns, 'c'));
-
-echo "Done\n";
-?>
---EXPECTF--
-*** Testing basic functionalities ***
--- first_name column from recordset --
-array(3) {
-  [0]=>
-  string(4) "John"
-  [1]=>
-  string(5) "Sally"
-  [2]=>
-  string(4) "Jane"
-}
--- id column from recordset --
-array(3) {
-  [0]=>
-  int(1)
-  [1]=>
-  int(2)
-  [2]=>
-  int(3)
-}
-
-*** Testing multiple data types ***
-array(8) {
-  [0]=>
-  object(stdClass)#1 (0) {
-  }
-  [1]=>
-  float(34.2345)
-  [2]=>
-  bool(true)
-  [3]=>
-  bool(false)
-  [4]=>
-  NULL
-  [5]=>
-  int(1234)
-  [6]=>
-  string(3) "Foo"
-  [7]=>
-  resource(5) of type (stream)
-}
-
-*** Testing numeric column keys ***
-array(3) {
-  [0]=>
-  string(3) "111"
-  [1]=>
-  string(3) "222"
-  [2]=>
-  string(3) "333"
-}
-
-*** Testing failure to find specified column ***
-array(0) {
-}
-array(0) {
-}
-
-*** Testing single dimensional array ***
-array(0) {
-}
-
-*** Testing columns not present in all rows ***
-array(1) {
-  [0]=>
-  string(3) "qux"
-}
-Done
diff --git a/ext/standard/tests/array/array_column_basic.phpt 
b/ext/standard/tests/array/array_column_basic.phpt
new file mode 100644
index 0000000..efa98ce
--- /dev/null
+++ b/ext/standard/tests/array/array_column_basic.phpt
@@ -0,0 +1,169 @@
+--TEST--
+Test array_column() function: basic functionality
+--FILE--
+<?php
+/* Prototype:
+ *  array array_column(array $input, mixed $key);
+ * Description:
+ *  Returns an array containing all the values from
+ *  the specified "column" in a two-dimensional array.
+ */
+
+echo "*** Testing array_column() : basic functionality ***\n";
+/* Array representing a possible record set returned from a database */
+$records = array(
+       array(
+               'id' => 1,
+               'first_name' => 'John',
+               'last_name' => 'Doe'
+       ),
+       array(
+               'id' => 2,
+               'first_name' => 'Sally',
+               'last_name' => 'Smith'
+       ),
+       array(
+               'id' => 3,
+               'first_name' => 'Jane',
+               'last_name' => 'Jones'
+       )
+);
+
+echo "-- first_name column from recordset --\n";
+var_dump(array_column($records, 'first_name'));
+
+echo "-- id column from recordset --\n";
+var_dump(array_column($records, 'id'));
+
+echo "\n*** Testing multiple data types ***\n";
+$file = basename(__FILE__);
+$fh = fopen($file, 'r', true);
+$values = array(
+       array(
+               'id' => 1,
+               'value' => new stdClass
+       ),
+       array(
+               'id' => 2,
+               'value' => 34.2345
+       ),
+       array(
+               'id' => 3,
+               'value' => true
+       ),
+       array(
+               'id' => 4,
+               'value' => false
+       ),
+       array(
+               'id' => 5,
+               'value' => null
+       ),
+       array(
+               'id' => 6,
+               'value' => 1234
+       ),
+       array(
+               'id' => 7,
+               'value' => 'Foo'
+       ),
+       array(
+               'id' => 8,
+               'value' => $fh
+       )
+);
+var_dump(array_column($values, 'value'));
+
+echo "\n*** Testing numeric column keys ***\n";
+$numericCols = array(
+       array('aaa', '111'),
+       array('bbb', '222'),
+       array('ccc', '333')
+);
+var_dump(array_column($numericCols, 1));
+
+echo "\n*** Testing failure to find specified column ***\n";
+var_dump(array_column($numericCols, 2));
+var_dump(array_column($numericCols, 'foo'));
+
+echo "\n*** Testing single dimensional array ***\n";
+$singleDimension = array('foo', 'bar', 'baz');
+var_dump(array_column($singleDimension, 1));
+
+echo "\n*** Testing columns not present in all rows ***\n";
+$mismatchedColumns = array(
+    array('a' => 'foo', 'b' => 'bar'),
+    array('a' => 'baz', 'c' => 'qux'),
+);
+var_dump(array_column($mismatchedColumns, 'c'));
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing array_column() : basic functionality ***
+-- first_name column from recordset --
+array(3) {
+  [0]=>
+  string(4) "John"
+  [1]=>
+  string(5) "Sally"
+  [2]=>
+  string(4) "Jane"
+}
+-- id column from recordset --
+array(3) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+}
+
+*** Testing multiple data types ***
+array(8) {
+  [0]=>
+  object(stdClass)#1 (0) {
+  }
+  [1]=>
+  float(34.2345)
+  [2]=>
+  bool(true)
+  [3]=>
+  bool(false)
+  [4]=>
+  NULL
+  [5]=>
+  int(1234)
+  [6]=>
+  string(3) "Foo"
+  [7]=>
+  resource(5) of type (stream)
+}
+
+*** Testing numeric column keys ***
+array(3) {
+  [0]=>
+  string(3) "111"
+  [1]=>
+  string(3) "222"
+  [2]=>
+  string(3) "333"
+}
+
+*** Testing failure to find specified column ***
+array(0) {
+}
+array(0) {
+}
+
+*** Testing single dimensional array ***
+array(0) {
+}
+
+*** Testing columns not present in all rows ***
+array(1) {
+  [0]=>
+  string(3) "qux"
+}
+Done
diff --git a/ext/standard/tests/array/array_column_error.phpt 
b/ext/standard/tests/array/array_column_error.phpt
new file mode 100644
index 0000000..d409d3b
--- /dev/null
+++ b/ext/standard/tests/array/array_column_error.phpt
@@ -0,0 +1,82 @@
+--TEST--
+Test array_column() function: error conditions
+--FILE--
+<?php
+/* Prototype:
+ *  array array_column(array $input, mixed $key);
+ * Description:
+ *  Returns an array containing all the values from
+ *  the specified "column" in a two-dimensional array.
+ */
+
+echo "*** Testing array_column() : error conditions ***\n";
+
+echo "\n-- Testing array_column() function with Zero arguments --\n";
+var_dump(array_column());
+
+echo "\n-- Testing array_column() function with One argument --\n";
+var_dump(array_column(array()));
+
+echo "\n-- Testing array_column() function with more than expected no. of 
arguments --\n";
+var_dump(array_column(array(), 'foo', 'bar'));
+
+echo "\n-- Testing array_column() function with string as first parameter 
--\n";
+var_dump(array_column('foo', 0));
+
+echo "\n-- Testing array_column() function with int as first parameter --\n";
+var_dump(array_column(1, 'foo'));
+
+echo "\n-- Testing array_column() key parameter should be a string or an 
integer (testing bool) --\n";
+var_dump(array_column(array(), true));
+
+echo "\n-- Testing array_column() key parameter should be a string or integer 
(testing float) --\n";
+var_dump(array_column(array(), 2.3));
+
+echo "\n-- Testing array_column() key parameter should be a string or integer 
(testing array) --\n";
+var_dump(array_column(array(), array()));
+
+echo "Done\n";
+?>
+--EXPECTF--
+*** Testing array_column() : error conditions ***
+
+-- Testing array_column() function with Zero arguments --
+
+Warning: array_column() expects exactly 2 parameters, 0 given in %s on line %d
+NULL
+
+-- Testing array_column() function with One argument --
+
+Warning: array_column() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+
+-- Testing array_column() function with more than expected no. of arguments --
+
+Warning: array_column() expects exactly 2 parameters, 3 given in %s on line %d
+NULL
+
+-- Testing array_column() function with string as first parameter --
+
+Warning: array_column() expects parameter 1 to be array, string given in %s on 
line %d
+NULL
+
+-- Testing array_column() function with int as first parameter --
+
+Warning: array_column() expects parameter 1 to be array, integer given in %s 
on line %d
+NULL
+
+-- Testing array_column() key parameter should be a string or an integer 
(testing bool) --
+
+Warning: array_column(): The key should be either a string or an integer in %s 
on line %d
+bool(false)
+
+-- Testing array_column() key parameter should be a string or integer (testing 
float) --
+
+Warning: array_column(): The key should be either a string or an integer in %s 
on line %d
+bool(false)
+
+-- Testing array_column() key parameter should be a string or integer (testing 
array) --
+
+Warning: array_column(): The key should be either a string or an integer in %s 
on line %d
+bool(false)
+Done
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to