Example #1
0
 public function initialize($object)
 {
     $reflectionClass = new ReflectionClass($object);
     $reader = new Phake_Annotation_Reader($reflectionClass);
     if ($this->useDoctrineParser()) {
         $parser = new \Doctrine\Common\Annotations\PhpParser();
     }
     $properties = $reader->getPropertiesWithAnnotation('Mock');
     foreach ($properties as $property) {
         $annotations = $reader->getPropertyAnnotations($property);
         if ($annotations['Mock'] !== true) {
             $mockedClass = $annotations['Mock'];
         } else {
             $mockedClass = $annotations['var'];
         }
         if (isset($parser)) {
             // Ignore it if the class start with a backslash
             if (substr($mockedClass, 0, 1) !== '\\') {
                 $useStatements = $parser->parseClass($reflectionClass);
                 $key = strtolower($mockedClass);
                 if (array_key_exists($key, $useStatements)) {
                     $mockedClass = $useStatements[$key];
                 }
             }
         }
         $reflProp = new ReflectionProperty(get_class($object), $property);
         $reflProp->setAccessible(true);
         $reflProp->setValue($object, Phake::mock($mockedClass));
     }
 }
 /**
  * Collects parsing metadata for a given class
  *
  * @param ReflectionClass $class
  */
 private function collectParsingMetadata(ReflectionClass $class)
 {
     $ignoredAnnotationNames = self::$globalIgnoredNames;
     $annotations = $this->preParser->parse($class->getDocComment(), 'class ' . $class->name);
     foreach ($annotations as $annotation) {
         if ($annotation instanceof IgnoreAnnotation) {
             foreach ($annotation->names as $annot) {
                 $ignoredAnnotationNames[$annot] = true;
             }
         }
     }
     $name = $class->getName();
     $this->imports[$name] = array_merge(self::$globalImports, $this->phpParser->parseClass($class), array('__NAMESPACE__' => $class->getNamespaceName()));
     $this->ignoredAnnotationNames[$name] = $ignoredAnnotationNames;
 }
 /**
  * Collects parsing metadata for a given class
  *
  * @param ReflectionClass $class
  */
 private function collectParsingMetadata(ReflectionClass $class)
 {
     $imports = self::$globalImports;
     $ignoredAnnotationNames = self::$globalIgnoredNames;
     if ($this->enablePhpImports) {
         $annotations = $this->preParser->parse($class->getDocComment());
         foreach ($annotations as $annotation) {
             if ($annotation instanceof IgnoreAnnotation) {
                 foreach ($annotation->names as $annot) {
                     $ignoredAnnotationNames[$annot] = true;
                 }
             }
         }
     }
     $name = $class->getName();
     $this->imports[$name] = array_merge(self::$globalImports, $this->enablePhpImports ? $this->phpParser->parseClass($class) : array(), $this->enablePhpImports ? array('__NAMESPACE__' => $class->getNamespaceName()) : array());
     if ($this->defaultAnnotationNamespace) {
         $this->imports[$name]['__DEFAULT__'] = $this->defaultAnnotationNamespace;
     }
     $this->ignoredAnnotationNames[$name] = $ignoredAnnotationNames;
 }