Пример #1
0
 /**
  * @return string
  */
 public function generateCode()
 {
     $class = new ClassBlock($this->_className);
     if ($this->_parentClassName) {
         $class->setParentClassName($this->_parentClassName);
     }
     foreach ($this->_interfaces as $interface) {
         $class->addInterface($interface);
     }
     $class->addInterface(OverridableInterface::class);
     foreach ($this->_traits as $trait) {
         $reflectionTrait = new \ReflectionClass($trait);
         $trait = new TraitBlock($trait);
         foreach ($reflectionTrait->getMethods() as $reflectionMethod) {
             if (!$reflectionMethod->isAbstract()) {
                 $trait->addAlias($reflectionMethod->getName(), "_mockaTraitAlias_{$reflectionMethod->getName()}");
             }
         }
         $class->addUse($trait);
     }
     $class->addUse(new TraitBlock('\\Mocka\\Classes\\ClassMockTrait'));
     $mockableMethods = $this->_getMockableMethods();
     foreach ($mockableMethods as $reflectionMethod) {
         $method = new MethodBlock($reflectionMethod->getName());
         $method->setAbstract(false);
         $method->setParametersFromReflection($reflectionMethod);
         $method->setStaticFromReflection($reflectionMethod);
         $method->setVisibilityFromReflection($reflectionMethod);
         if ($reflectionMethod->isStatic()) {
             $method->extractFromClosure(function () {
                 return static::_callStaticMethod(__FUNCTION__, func_get_args());
             });
         } else {
             $method->extractFromClosure(function () {
                 return $this->_callMethod(__FUNCTION__, func_get_args());
             });
         }
         $class->addMethod($method);
     }
     $method = new MethodBlock('__construct');
     $method->extractFromClosure(function () {
         return $this->_callMethod(__FUNCTION__, func_get_args());
     });
     $class->addMethod($method);
     return $class->dump();
 }
Пример #2
0
 /**
  * @return string
  */
 public function generateCode()
 {
     $class = new ClassBlock($this->_className);
     if ($this->_parentClassName) {
         $class->setParentClassName($this->_parentClassName);
     }
     foreach ($this->_interfaces as $interface) {
         $class->addInterface($interface);
     }
     foreach ($this->_traits as $trait) {
         $class->addUse($trait);
     }
     $class->addUse('\\Mocka\\AbstractClassTrait');
     $mockableMethods = $this->_getMockableMethods();
     foreach ($mockableMethods as $reflectionMethod) {
         $method = new MethodBlock($reflectionMethod->getName());
         $method->setAbstract(false);
         $method->setParametersFromReflection($reflectionMethod);
         $method->setStaticFromReflection($reflectionMethod);
         $method->setVisibilityFromReflection($reflectionMethod);
         if ($reflectionMethod->isStatic()) {
             $method->extractFromClosure(function () {
                 return static::_callStaticMethod(__FUNCTION__, func_get_args());
             });
         } else {
             $method->extractFromClosure(function () {
                 return $this->_callMethod(__FUNCTION__, func_get_args());
             });
         }
         $class->addMethod($method);
     }
     $method = new MethodBlock('__construct');
     $method->extractFromClosure(function () {
         return $this->_callMethod(__FUNCTION__, func_get_args());
     });
     $class->addMethod($method);
     return $class->dump();
 }