Fix for Code

  1. <?php
  2.  
  3. define ('TEST_LOAD', 0);
  4. define ('TEST_START', 1);
  5. define ('TEST_IN', 2);
  6.  
  7. /**
  8.  * on the first call, you pass in one argument, the test array.
  9.  * On the second call, you pass in the function you want to call and the arguments.
  10.  */
  11. function test_clearinghouse(&$a0 = NULL, &$a1 = NULL, &$a2 = NULL, &$a3 = NULL, &$a4 = NULL, &$a5 = NULL, &$a6 = NULL, &$a7 = NULL, &$a8 = NULL, &$a9 = NULL) {
  12.   static $state, $test;
  13.   switch ($state) {
  14.     case TEST_LOAD:
  15.       $test = $a0;
  16.       $state = TEST_START;
  17.       break;
  18.     case TEST_START:
  19.       $state = TEST_IN;
  20.       $function = 'original_'. $a0;
  21.       $num_args = func_num_args();
  22.       switch ($num_args - 1) {
  23.         case 0: $return = $function();break
  24.         case 1: $return = $function($a1); break;
  25.         case 2: $return = $function($a1, $a2); break;
  26.         case 3: $return = $function($a1, $a2, $a3); break;
  27.         case 4: $return = $function($a1, $a2, $a3, $a4); break;
  28.         case 5: $return = $function($a1, $a2, $a3, $a4, $a5); break;
  29.         case 6: $return = $function($a1, $a2, $a3, $a4, $a5, $a6); break;
  30.         case 7: $return = $function($a1, $a2, $a3, $a4, $a5, $a6, $a7); break;
  31.         case 8: $return = $function($a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8); break;
  32.         case 9: $return = $function($a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9); break;
  33.       }
  34.       $final_return = $test['final_return'];
  35.       unset($test['final_return']);
  36.       if (!$test && $return === $final_return) {
  37.         $this->pass();
  38.       }
  39.       else {
  40.         $this->fail();
  41.       }
  42.       $state = TEST_LOAD;
  43.       break;
  44.     case TEST_IN:
  45.       $step = array_shift($test);
  46.       $incoming = $step['incoming'];
  47.       $num_args = func_num_args();
  48.       for ($i = 0; $i < $num_args; $i++) {
  49.         $variable_name = "$a$i";
  50.         if ($incoming[$i] !== $$variable_name) {
  51.           $this->fail();
  52.         }
  53.       }
  54.       if (isset($step['references'])) {
  55.         foreach ($step['references'] as $key => $value) {
  56.           $variable_name = "$a$key";
  57.           $$variable_name = $value;
  58.         }
  59.       }
  60.       if (isset($step['return'])) {
  61.         return $step['return'];
  62.       }
  63.   }
  64. }
  65.  
  66. test_clearinghouse(
  67.   array(
  68.     array(
  69.       'incoming' => array('cache_get', 'variables', 'cache'),
  70.       'return' => FALSE,
  71.     ),
  72.     array(
  73.       'incoming' => array('db_query', 'SELECT * FROM {variable}'),
  74.       'return' => '__test_placeholder__',
  75.     ),
  76.     array(
  77.       'incoming' => array('db_fetch_object', '__test_placeholder__'),
  78.       'return' => (object) array('name '=> 'foo', 'value' => serialize('bar')),
  79.     ),
  80.     array(
  81.       'incoming' => array('db_fetch_object', '__test_placeholder__'),
  82.       'return' => FALSE,
  83.     ),
  84.     array(
  85.       'incoming' => array('cache_set', 'variables', ),
  86.     )
  87.   );
  88. );
  89. test_clearinghouse('variable_init');