Пример #1
0
 public function scan($entity)
 {
     $scanner = new \Mocker\Scanner();
     $contexts = $scanner->scan($entity);
     if (count($contexts) > 1) {
         throw new Exception\MoreThanOneException(400, 'Scanner return more than one context');
     }
     $this->setContext($contexts[0]);
     if (empty($this->context->getEntity())) {
         throw new \Exception('Entity is required in context to create a mock');
     }
     if (empty($this->context->getProperties())) {
         throw new \Exception('Propety is required in context to create a mock');
     }
 }
Пример #2
0
 public function createContextFromFilename($filename)
 {
     $tokens = $this->getFileTokens($filename);
     $class = $this->getNamespaceFromToken($tokens);
     $reader = new SimpleAnnotationReader();
     $reflClass = new \ReflectionClass($class);
     $entityAnnotation = $reader->getClassAnnotation($reflClass, Entity::class);
     if (!$entityAnnotation) {
         return;
     }
     $context = new Context();
     $context->setFile($filename);
     $context->setEntity($entityAnnotation);
     $propertyAnnotations = [];
     foreach ($reflClass->getProperties() as $property) {
         $annotation = $reader->getPropertyAnnotation($property, Property::class);
         if ($annotation && !$annotation->name) {
             $annotation->name = $property->getName();
             $context->addProperty($annotation);
         }
     }
     return $context;
 }