public function __call($name, $arguments)
 {
     if (!$this->_wasCalled($name, $arguments)) {
         return $this;
     }
     $calls = $this->_actualCalls();
     $expected = MethodCall::newInstance($name, $arguments)->toString() . ' is never called';
     $this->_fail("Unwanted method was called", $expected, $calls);
 }
 public function __call($name, $arguments)
 {
     if ($this->numberOfActualCalls($name, $arguments) === $this->times) {
         return $this;
     }
     $calls = $this->_actualCalls();
     $expected = MethodCall::newInstance($name, $arguments)->toString() . ' is called ' . $this->times . ' times';
     $this->_fail("Called method incorrect times", $expected, $calls);
 }
Exemple #3
0
 public static function runtestsBasic()
 {
     /* 0: Do nothing */
     $loop_do_nothing = function ($count) {
         $result = 0;
         for ($iter = 0; $iter < $count; $iter++) {
         }
         return $result;
     };
     TimeHHOperations::timeop('nothing', $loop_do_nothing);
     /* 1: Function call */
     $loop_function_call = function ($count) {
         $result = 0;
         for ($iter = 0; $iter < $count; $iter++) {
             $result += function_call(0);
         }
         return $result;
     };
     TimeHHOperations::timeop('function_call', $loop_function_call);
     /* 2: Method call */
     $loop_static_method_call = function ($count) {
         $result = 0;
         for ($iter = 0; $iter < $count; $iter++) {
             $result += MethodCall::callStaticMethod(0);
         }
         return $result;
     };
     TimeHHOperations::timeop('static_method_call', $loop_static_method_call);
     $loop_instance_method_call = function ($count) {
         $result = 0;
         $instance = new MethodCall();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->callInstanceMethod(0);
         }
         return $result;
     };
     TimeHHOperations::timeop('instance_method_call', $loop_instance_method_call);
     $loop_interface_method_call = function ($count) {
         $result = 0;
         $instance = new Class0();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->callInterfaceMethod(0);
         }
         return $result;
     };
     TimeHHOperations::timeop('interface_method_call', $loop_interface_method_call);
     /* 3: IndexArrayMap */
     $loop_idxemptyarray = function ($count) {
         $result = 0;
         $instance = new EmptyArray();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->indexEmpty();
         }
         return $result;
     };
     TimeHHOperations::timeop('idxemptyarray', $loop_idxemptyarray);
     $loop_idxnohit_smallarray = function ($count) {
         $result = 0;
         $instance = new NoHitSmallArray();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->indexNoHitSmall();
         }
         return $result;
     };
     TimeHHOperations::timeop('idxnohit_smallarray', $loop_idxnohit_smallarray);
     $loop_idxhit_smallarray = function ($count) {
         $result = 0;
         $instance = new HitSmallArray();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->indexHitSmall();
         }
         return $result;
     };
     TimeHHOperations::timeop('idxhit_smallarray', $loop_idxhit_smallarray);
     $loop_idxnohit_largearray = function ($count) {
         $result = 0;
         $instance = new NoHitLargeArray();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->indexNoHitLarge();
         }
         return $result;
     };
     TimeHHOperations::timeop('idxnohit_largearray', $loop_idxnohit_largearray);
     $loop_idxhit_largearray = function ($count) {
         $result = 0;
         $instance = new HitLargeArray();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->indexHitLarge();
         }
         return $result;
     };
     TimeHHOperations::timeop('idxhit_largearray', $loop_idxhit_largearray);
     /* 4: MethodExists */
     $loop_methodexists_string = function ($count) {
         $result = 0;
         $instance = new MethodExistsString();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->methodexists();
         }
         return $result;
     };
     TimeHHOperations::timeop('methodexists_string', $loop_methodexists_string);
     $loop_methodexists = function ($count) {
         $result = 0;
         $instance = new MethodExistsClass();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->methodexists();
         }
         return $result;
     };
     TimeHHOperations::timeop('methodexists', $loop_methodexists);
     $loop_methodnotexists = function ($count) {
         $result = 0;
         $instance = new MethodNotExistsClass();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->methodexists();
         }
         return $result;
     };
     TimeHHOperations::timeop('methodnotexists', $loop_methodnotexists);
     $loop_methodexists_base = function ($count) {
         $result = 0;
         $instance = new MethodExistsDerivedClass();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->methodexists();
         }
         return $result;
     };
     TimeHHOperations::timeop('methodexists_base', $loop_methodexists_base);
     $loop_methodnotexists_base = function ($count) {
         $result = 0;
         $instance = new MethodNotExistsDerivedClass();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->methodexists();
         }
         return $result;
     };
     TimeHHOperations::timeop('methodnotexists_base', $loop_methodnotexists_base);
     /* 5: Field Access */
     $loop_fieldaccess_staticint = function ($count) {
         $result = 0;
         for ($iter = 0; $iter < $count; $iter++) {
             $result += FieldAccess::accessStaticCounter();
         }
         return $result;
     };
     TimeHHOperations::timeop('fieldaccess_staticint', $loop_fieldaccess_staticint);
     $loop_fieldaccess_instanceint = function ($count) {
         $result = 0;
         $instance = new FieldAccess();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->accessInstanceCounter();
         }
         return $result;
     };
     TimeHHOperations::timeop('fieldaccess_instanceint', $loop_fieldaccess_instanceint);
     $loop_fieldaccess_staticstring = function ($count) {
         $result = 0;
         for ($iter = 0; $iter < $count; $iter++) {
             $result += FieldAccess::accessStaticString();
         }
         return $result;
     };
     TimeHHOperations::timeop('fieldaccess_staticstring', $loop_fieldaccess_staticstring);
     $loop_fieldaccess_instancestring = function ($count) {
         $result = 0;
         $instance = new FieldAccess();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->accessInstanceString();
         }
         return $result;
     };
     TimeHHOperations::timeop('fieldaccess_instancestring', $loop_fieldaccess_instancestring);
     /* 6: Array Access */
     $loop_arrayassign_int = function ($count) {
         $result = 0;
         $instance = new IntArray();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->assignArrayElem();
         }
         return $result;
     };
     TimeHHOperations::timeop('arrayassign_int', $loop_arrayassign_int);
     $loop_arrayassign_string = function ($count) {
         $result = 0;
         $instance = new StringArray();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->assignArrayElem();
         }
         return $result;
     };
     TimeHHOperations::timeop('arrayassign_string', $loop_arrayassign_string);
     /* 7: Closures et al */
     $loop_anonymousfunc_instance = function ($count) {
         $result = 0;
         $instance = new AnonymousFunctions();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->instanceFunction();
         }
         return $result;
     };
     TimeHHOperations::timeop('anonymousfunc_instance', $loop_anonymousfunc_instance);
     $loop_anonymousfunc_static = function ($count) {
         $result = 0;
         $instance = new AnonymousFunctions();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += AnonymousFunctions::staticFunction();
         }
         return $result;
     };
     TimeHHOperations::timeop('anonymousfunc_static', $loop_anonymousfunc_static);
     $loop_variablefunc_instance = function ($count) {
         $result = 0;
         $instance = new AnonymousFunctions();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += $instance->variableFunction();
         }
         return $result;
     };
     TimeHHOperations::timeop('variablefunc_instance', $loop_variablefunc_instance);
     $loop_variablefunc_static = function ($count) {
         $result = 0;
         $instance = new AnonymousFunctions();
         for ($iter = 0; $iter < $count; $iter++) {
             $result += AnonymousFunctions::variableFunctionStatic();
         }
         return $result;
     };
     TimeHHOperations::timeop('variablefunc_static', $loop_variablefunc_static);
 }