Example #1
0
 /**
  * @return string
  */
 public function generateCode()
 {
     $class = new ClassBlock($this->_name);
     if ($this->_namespace) {
         $class->setNamespace($this->_namespace);
     }
     if ($this->_parentClassName) {
         $class->setParentClassName($this->_parentClassName);
     }
     return $class->dump();
 }
Example #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);
     }
     $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();
 }
Example #3
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();
 }
Example #4
0
 /**
  * @return string
  */
 public function generateCode()
 {
     $class = new ClassBlock($this->_name);
     if ($this->_namespace) {
         $class->setNamespace($this->_namespace);
     }
     if ($this->_parentClassName) {
         $class->setParentClassName($this->_parentClassName);
     }
     $class->addUse('\\Mocka\\ClassTrait');
     return $class->dump();
 }
Example #5
0
 public function testGetName()
 {
     $className = 'Foo';
     $class = new ClassBlock($className, 'Bar', array('Countable'));
     $this->assertSame($className, $class->getName());
 }