Annotation of embedaddon/php/ext/spl/tests/class_uses_variation2.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: SPL: Test class_uses() function : variation 
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : array class_uses(mixed what [, bool autoload ])
                      6:  * Description: Return all traits used by a class
                      7:  * Source code: ext/spl/php_spl.c
                      8:  * Alias to functions: 
                      9:  */
                     10: 
                     11: echo "*** Testing class_uses() : variation ***\n";
                     12: 
                     13: trait foo {}
                     14: class fooUser { use foo; }
                     15: 
                     16: // Define error handler
                     17: function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
                     18:        if (error_reporting() != 0) {
                     19:                // report non-silenced errors
                     20:                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
                     21:        }
                     22: }
                     23: set_error_handler('test_error_handler');
                     24: 
                     25: // Initialise function arguments not being substituted (if any)
                     26: $class = 'fooUser';
                     27: 
                     28: //resource
                     29: $res = fopen(__FILE__,'r');
                     30: 
                     31: //get an unset variable
                     32: $unset_var = 10;
                     33: unset ($unset_var);
                     34: 
                     35: // define some classes
                     36: class classWithToString
                     37: {
                     38:        public function __toString() {
                     39:                return "Class A object";
                     40:        }
                     41: }
                     42: 
                     43: class classWithoutToString
                     44: {
                     45: }
                     46: 
                     47: // heredoc string
                     48: $heredoc = <<<EOT
                     49: hello world
                     50: EOT;
                     51: 
                     52: // add arrays
                     53: $index_array = array (1, 2, 3);
                     54: $assoc_array = array ('one' => 1, 'two' => 2);
                     55: 
                     56: //array of values to iterate over
                     57: $inputs = array(
                     58: 
                     59:       // int data
                     60:       'int 0' => 0,
                     61:       'int 1' => 1,
                     62:       'int 12345' => 12345,
                     63:       'int -12345' => -2345,
                     64: 
                     65:       // float data
                     66:       'float 10.5' => 10.5,
                     67:       'float -10.5' => -10.5,
                     68:       'float 12.3456789000e10' => 12.3456789000e10,
                     69:       'float -12.3456789000e10' => -12.3456789000e10,
                     70:       'float .5' => .5,
                     71: 
                     72:       // array data
                     73:       'empty array' => array(),
                     74:       'int indexed array' => $index_array,
                     75:       'associative array' => $assoc_array,
                     76:       'nested arrays' => array('foo', $index_array, $assoc_array),
                     77: 
                     78:       // null data
                     79:       'uppercase NULL' => NULL,
                     80:       'lowercase null' => null,
                     81: 
                     82:       // boolean data
                     83:       'lowercase true' => true,
                     84:       'lowercase false' =>false,
                     85:       'uppercase TRUE' =>TRUE,
                     86:       'uppercase FALSE' =>FALSE,
                     87: 
                     88:       // empty data
                     89:       'empty string DQ' => "",
                     90:       'empty string SQ' => '',
                     91: 
                     92:       // object data
                     93:       'instance of classWithToString' => new classWithToString(),
                     94:       'instance of classWithoutToString' => new classWithoutToString(),
                     95: 
                     96:       // undefined data
                     97:       'undefined var' => @$undefined_var,
                     98: 
                     99:       // unset data
                    100:       'unset var' => @$unset_var,
                    101:       
                    102:       //resource
                    103:       'resource' => $res,
                    104: );
                    105: 
                    106: // loop through each element of the array for pattern
                    107: 
                    108: foreach($inputs as $key =>$value) {
                    109:       echo "\n--$key--\n";
                    110:       var_dump( class_uses($class, $value) );
                    111: };
                    112: 
                    113: fclose($res);
                    114: 
                    115: ?>
                    116: ===DONE===
                    117: --EXPECTF--
                    118: *** Testing class_uses() : variation ***
                    119: 
                    120: --int 0--
                    121: array(1) {
                    122:   ["foo"]=>
                    123:   string(3) "foo"
                    124: }
                    125: 
                    126: --int 1--
                    127: array(1) {
                    128:   ["foo"]=>
                    129:   string(3) "foo"
                    130: }
                    131: 
                    132: --int 12345--
                    133: array(1) {
                    134:   ["foo"]=>
                    135:   string(3) "foo"
                    136: }
                    137: 
                    138: --int -12345--
                    139: array(1) {
                    140:   ["foo"]=>
                    141:   string(3) "foo"
                    142: }
                    143: 
                    144: --float 10.5--
                    145: array(1) {
                    146:   ["foo"]=>
                    147:   string(3) "foo"
                    148: }
                    149: 
                    150: --float -10.5--
                    151: array(1) {
                    152:   ["foo"]=>
                    153:   string(3) "foo"
                    154: }
                    155: 
                    156: --float 12.3456789000e10--
                    157: array(1) {
                    158:   ["foo"]=>
                    159:   string(3) "foo"
                    160: }
                    161: 
                    162: --float -12.3456789000e10--
                    163: array(1) {
                    164:   ["foo"]=>
                    165:   string(3) "foo"
                    166: }
                    167: 
                    168: --float .5--
                    169: array(1) {
                    170:   ["foo"]=>
                    171:   string(3) "foo"
                    172: }
                    173: 
                    174: --empty array--
                    175: Error: 2 - class_uses() expects parameter 2 to be boolean, array given, %s(%d)
                    176: bool(false)
                    177: 
                    178: --int indexed array--
                    179: Error: 2 - class_uses() expects parameter 2 to be boolean, array given, %s(%d)
                    180: bool(false)
                    181: 
                    182: --associative array--
                    183: Error: 2 - class_uses() expects parameter 2 to be boolean, array given, %s(%d)
                    184: bool(false)
                    185: 
                    186: --nested arrays--
                    187: Error: 2 - class_uses() expects parameter 2 to be boolean, array given, %s(%d)
                    188: bool(false)
                    189: 
                    190: --uppercase NULL--
                    191: array(1) {
                    192:   ["foo"]=>
                    193:   string(3) "foo"
                    194: }
                    195: 
                    196: --lowercase null--
                    197: array(1) {
                    198:   ["foo"]=>
                    199:   string(3) "foo"
                    200: }
                    201: 
                    202: --lowercase true--
                    203: array(1) {
                    204:   ["foo"]=>
                    205:   string(3) "foo"
                    206: }
                    207: 
                    208: --lowercase false--
                    209: array(1) {
                    210:   ["foo"]=>
                    211:   string(3) "foo"
                    212: }
                    213: 
                    214: --uppercase TRUE--
                    215: array(1) {
                    216:   ["foo"]=>
                    217:   string(3) "foo"
                    218: }
                    219: 
                    220: --uppercase FALSE--
                    221: array(1) {
                    222:   ["foo"]=>
                    223:   string(3) "foo"
                    224: }
                    225: 
                    226: --empty string DQ--
                    227: array(1) {
                    228:   ["foo"]=>
                    229:   string(3) "foo"
                    230: }
                    231: 
                    232: --empty string SQ--
                    233: array(1) {
                    234:   ["foo"]=>
                    235:   string(3) "foo"
                    236: }
                    237: 
                    238: --instance of classWithToString--
                    239: Error: 2 - class_uses() expects parameter 2 to be boolean, object given, %s(%d)
                    240: bool(false)
                    241: 
                    242: --instance of classWithoutToString--
                    243: Error: 2 - class_uses() expects parameter 2 to be boolean, object given, %s(%d)
                    244: bool(false)
                    245: 
                    246: --undefined var--
                    247: array(1) {
                    248:   ["foo"]=>
                    249:   string(3) "foo"
                    250: }
                    251: 
                    252: --unset var--
                    253: array(1) {
                    254:   ["foo"]=>
                    255:   string(3) "foo"
                    256: }
                    257: 
                    258: --resource--
                    259: Error: 2 - class_uses() expects parameter 2 to be boolean, resource given, %s(%d)
                    260: bool(false)
                    261: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>