Beispiel #1
0
 /**
  * Helper method to properly initialize a class builder with everything
  * ready for $builder->create() to be invoked. Has no side effects
  *
  * @return \Shmock\ClassBuilder\ClassBuilder
  */
 protected function initializeClassBuilder()
 {
     // build the mock class
     $builder = new ClassBuilder();
     if (class_exists($this->className)) {
         $builder->setExtends($this->className);
     } elseif (interface_exists($this->className)) {
         $builder->addInterface($this->className);
     } else {
         throw new \InvalidArgumentException("Class or interface " . $this->className . " does not exist");
     }
     // every mocked method goes through this invocation, which delegates
     // the retrieval of the correct Spec to this Instance's Ordering constraint.
     $resolveCall = function (Invocation $inv) {
         $spec = $this->ordering->nextSpec($inv->getMethodName());
         return $spec->doInvocation($inv);
     };
     return $this->addMethodsToBuilder($builder, $resolveCall);
 }