From 2d8466b2afa7640559d8aa3dac9b95607036014d Mon Sep 17 00:00:00 2001 From: Raghubansh Kumar Date: Fri, 26 Oct 2007 11:52:59 +0000 Subject: [PATCH] more testcases for array_unshift() function --- .../tests/array/array_unshift_object.phpt | 471 ++++++++++++++++++ 1 file changed, 471 insertions(+) create mode 100644 ext/standard/tests/array/array_unshift_object.phpt diff --git a/ext/standard/tests/array/array_unshift_object.phpt b/ext/standard/tests/array/array_unshift_object.phpt new file mode 100644 index 0000000000..b8723e4a85 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_object.phpt @@ -0,0 +1,471 @@ +--TEST-- +Test array_unshift() function : passing object for 'var' argument +--FILE-- + "first", "s" => 'second', 1, 2.222); + +// array containing different types of objects as elements +$vars = array( + new SimpleClass(), + new EmptyClass(), + new ChildClass(), + new FinalClass(), + new StaticClass() +); + +// loop through the various elements of $arrays to check the functionality of array_unshift +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : Passing object to $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + object(SimpleClass)#%d (1) { + ["var1"]=> + int(1) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(SimpleClass)#%d (1) { + ["var1"]=> + int(1) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + object(EmptyClass)#%d (0) { + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(EmptyClass)#%d (0) { + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + object(ChildClass)#%d (2) { + ["var3":"ChildClass":private]=> + NULL + ["var2":protected]=> + int(5) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(ChildClass)#%d (2) { + ["var3":"ChildClass":private]=> + NULL + ["var2":protected]=> + int(5) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + object(FinalClass)#%d (1) { + ["var4":"FinalClass":private]=> + NULL + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(FinalClass)#%d (1) { + ["var4":"FinalClass":private]=> + NULL + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + object(StaticClass)#%d (0) { + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(StaticClass)#%d (0) { + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done +--UEXPECTF-- +*** Testing array_unshift() : Passing object to $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + object(SimpleClass)#%d (1) { + [u"var1"]=> + int(1) + } + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(SimpleClass)#%d (1) { + [u"var1"]=> + int(1) + } + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + object(EmptyClass)#%d (0) { + } + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(EmptyClass)#%d (0) { + } + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + object(ChildClass)#%d (2) { + [u"var3":u"ChildClass":private]=> + NULL + [u"var2":protected]=> + int(5) + } + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(ChildClass)#%d (2) { + [u"var3":u"ChildClass":private]=> + NULL + [u"var2":protected]=> + int(5) + } + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + object(FinalClass)#%d (1) { + [u"var4":u"FinalClass":private]=> + NULL + } + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(FinalClass)#%d (1) { + [u"var4":u"FinalClass":private]=> + NULL + } + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + object(StaticClass)#%d (0) { + } + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(StaticClass)#%d (0) { + } + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done -- 2.50.1