Example #1
0
 protected function before()
 {
     $fields = new FieldRegistry();
     $this->inside = M::of(WebField::class);
     $fields->add(M::mock($this->inside));
     $this->field = new NullableField($fields);
     M::stub($this->inside->handles(Arg::any()))->will()->return_(true);
 }
Example #2
0
 /**
  * @param Parameter $parameter
  * @param string $serialized
  * @return mixed
  * @throws \Exception
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $param = new Parameter($parameter->getName(), $this->getType($parameter)->getOptionType());
     $options = $this->getType($parameter)->getOptions();
     if (!array_key_exists($serialized, $options)) {
         throw new \Exception("[{$serialized}] is not an option in [" . implode(',', array_keys($options)) . ']');
     }
     return $this->fields->getField($param)->inflate($param, $options[$serialized]);
 }
Example #3
0
 protected function before()
 {
     $fields = new FieldRegistry();
     $this->mockster = Mockster::of(WebField::class);
     Mockster::stub($this->mockster->handles(Argument::any()))->will()->return_(true);
     $this->detector = Mockster::of(MobileDetector::class);
     $fields->add(Mockster::mock($this->mockster));
     $this->field = new ArrayField($fields, Mockster::mock($this->detector));
 }
 function before()
 {
     $this->access = Mockster::of(AccessControl::class);
     $this->registry = new ActionRegistry();
     $this->registry->restrictAccess(Mockster::mock($this->access));
     $this->reader = Mockster::of(ParameterReader::class);
     $fields = new FieldRegistry();
     $this->executor = new Executor($this->registry, $fields, Mockster::mock(RendererRegistry::class), Mockster::mock($this->reader));
     $this->executor->restrictAccess(Mockster::mock($this->access));
     $fields->add(new StringField());
 }
Example #5
0
 /**
  * @param Parameter[] $parameters
  * @param mixed[] $values
  * @return mixed[]
  */
 private function inflate($parameters, $values)
 {
     $inflated = [];
     foreach ($parameters as $parameter) {
         $name = $parameter->getName();
         if (isset($values[$name])) {
             $inflated[$name] = $this->fields->getField($parameter)->inflate($parameter, $values[$name]);
         }
     }
     return $inflated;
 }
Example #6
0
 private function readParameters(ParameterReader $reader, FieldRegistry $fields, Action $action)
 {
     $values = ['inflated' => [], 'errors' => []];
     foreach ($action->parameters() as $parameter) {
         if ($reader->has($parameter)) {
             $field = $fields->getField($parameter);
             try {
                 $values['inflated'][$parameter->getName()] = $field->inflate($parameter, $reader->read($parameter));
             } catch (\Exception $e) {
                 $values['errors'][$parameter->getName()] = $e;
             }
         }
     }
     return $values;
 }
Example #7
0
 /**
  * @param Parameter $parameter
  * @return array|\rtens\domin\delivery\web\Element[]
  */
 public function headElements(Parameter $parameter)
 {
     $action = $this->actions->getAction($parameter->getName());
     $headElements = [self::descriptionCode()];
     foreach ($action->parameters() as $parameter) {
         $field = $this->fields->getField($parameter);
         if ($field instanceof WebField) {
             $headElements = array_merge($headElements, $field->headElements($parameter));
         }
     }
     return $headElements;
 }
Example #8
0
 private function readParameters(Action $action)
 {
     $failed = [];
     $params = [];
     foreach ($action->parameters() as $parameter) {
         try {
             if ($this->paramReader->has($parameter)) {
                 $inflated = $this->fields->getField($parameter)->inflate($parameter, $this->paramReader->read($parameter));
                 if ($parameter->getType()->is($inflated)) {
                     $params[$parameter->getName()] = $inflated;
                     continue;
                 }
             }
             if ($parameter->isRequired()) {
                 throw new \Exception("[{$parameter->getName()}] is required.");
             }
         } catch (\Exception $e) {
             $failed[$parameter->getName()] = $e;
         }
     }
     return [$params, $failed];
 }
Example #9
0
 private function readParameters(Action $action)
 {
     $params = [];
     $missing = [];
     foreach ($action->parameters() as $parameter) {
         if ($this->paramReader->has($parameter)) {
             $inflated = $this->fields->getField($parameter)->inflate($parameter, $this->paramReader->read($parameter));
             if ($parameter->getType()->is($inflated)) {
                 $params[$parameter->getName()] = $inflated;
             } else {
                 if ($parameter->isRequired()) {
                     $missing[] = $parameter->getName();
                 }
             }
         } else {
             if ($parameter->isRequired()) {
                 $missing[] = $parameter->getName();
             }
         }
     }
     return [$params, $missing];
 }
Example #10
0
 private function registerFields(ParameterReader $reader)
 {
     $this->fields->add(new PrimitiveField());
     $this->fields->add(new BooleanField());
     $this->fields->add(new FileField());
     $this->fields->add(new HtmlField($reader));
     $this->fields->add(new DateTimeField());
     $this->fields->add(new DateIntervalField());
     $this->fields->add(new ArrayField($this->fields, $reader));
     $this->fields->add(new NullableField($this->fields, $reader));
     $this->fields->add(new ObjectField($this->types, $this->fields, $reader));
     $this->fields->add(new MultiField($this->fields, $reader));
     $this->fields->add(new IdentifierField($this->fields));
     $this->fields->add(new EnumerationField($this->fields));
 }
Example #11
0
 private function registerFields()
 {
     $this->fields->add(new StringField());
     $this->fields->add(new NumberField());
     $this->fields->add(new BooleanField());
     $this->fields->add(new ColorField());
     $this->fields->add(new FileField());
     $this->fields->add(new ImageField());
     $this->fields->add(new TextField());
     $this->fields->add(new HtmlField());
     $this->fields->add(new DateTimeField());
     $this->fields->add(new DateIntervalField());
     $this->fields->add(new ArrayField($this->fields, $this->detector));
     $this->fields->add(new NullableField($this->fields));
     $this->fields->add(new ActionField($this->fields, $this->actions));
     $this->fields->add(new ObjectField($this->types, $this->fields));
     $this->fields->add(new MultiField($this->fields));
     $this->fields->add(new IdentifierField($this->fields, $this->identifiers));
     $this->fields->add(new EnumerationField($this->fields));
 }
Example #12
0
 private function whenIExecute_With($id, $params)
 {
     $fields = new FieldRegistry();
     foreach ($this->fields as $field) {
         $fields->add(Mockster::mock($field));
     }
     $reader = new FakeParameterReader($params);
     $executor = new Executor($this->action->registry, $fields, $reader, $this->access);
     $this->result = $executor->execute($id);
 }
Example #13
0
 private function givenAWebFieldRequiringTheHeadElements($elements)
 {
     $field = Mockster::of(WebField::class);
     $this->fields->add(Mockster::mock($field));
     Mockster::stub($field->handles(Arg::any()))->will()->return_(true);
     Mockster::stub($field->inflate(Arg::any(), Arg::any()))->will()->forwardTo(function ($s) {
         return $s . '(inflated)';
     });
     Mockster::stub($field->headElements(Arg::any()))->will()->forwardTo($elements);
 }
Example #14
0
 /**
  * @param $itemParameter
  * @return CliField
  * @throws \Exception
  */
 private function getField($itemParameter)
 {
     return $this->fields->getField($itemParameter);
 }
Example #15
0
 /**
  * @param Parameter $param
  * @return CliField
  */
 private function getField(Parameter $param)
 {
     return $this->fields->getField($param);
 }
Example #16
0
 private function itemHeadElements(Parameter $itemParameter)
 {
     /** @var WebField $field */
     $field = $this->fields->getField($itemParameter);
     return $field->headElements($itemParameter);
 }
Example #17
0
 private function whenIExecute($id)
 {
     $fields = new FieldRegistry();
     foreach ($this->fields as $field) {
         $fields->add(Mockster::mock($field));
     }
     $renderers = new RendererRegistry();
     foreach ($this->renderers as $renderer) {
         $renderers->add(Mockster::mock($renderer));
     }
     $executor = new Executor($this->action->registry, $fields, $renderers, Mockster::mock($this->reader));
     $this->result = $executor->execute($id);
 }
Example #18
0
 function inflatesUsingOptionType()
 {
     $this->fields->add(new DateTimeField());
     $type = new EnumerationType([new \DateTime()], new ClassType(\DateTime::class));
     $this->assert($this->field->inflate(new Parameter('foo', $type), '2011-12-13'), new \DateTime('2011-12-13 00:00:00'));
 }
Example #19
0
 /**
  * @param Parameter $parameter
  * @param string $serialized
  * @return mixed
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $param = new Parameter($parameter->getName(), $this->getType($parameter)->getOptionType());
     return $this->fields->getField($param)->inflate($param, $this->getType($parameter)->getOptions()[(int) $serialized]);
 }
Example #20
0
 /**
  * @param Parameter $innerParameter
  * @return WebField
  */
 private function getInnerField(Parameter $innerParameter)
 {
     return $this->fields->getField($innerParameter);
 }
Example #21
0
 /**
  * @param Parameter $parameter
  * @param string $serialized
  * @return mixed
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $primitiveParameter = new Parameter($parameter->getName(), $this->getType($parameter)->getPrimitive());
     return $this->fields->getField($primitiveParameter)->inflate($primitiveParameter, $serialized);
 }
Example #22
0
 private function givenAWebFieldRenderingWith($callback)
 {
     $field = Mockster::of(WebField::class);
     $this->fields->add(Mockster::mock($field));
     Mockster::stub($field->handles(Arg::any()))->will()->return_(true);
     //        Mockster::stub($field->inflate(Arg::any(), Arg::any()))->will()->forwardTo(function (Parameter $p, $s) {
     //            return $p->getName() . '_' . $s . '(inflated)';
     //        });
     Mockster::stub($field->render(Arg::any(), Arg::any()))->will()->forwardTo($callback);
 }
Example #23
0
 private function givenAWebFieldRenderingWith($callback)
 {
     $field = Mockster::of(WebField::class);
     $this->fields->add(Mockster::mock($field));
     Mockster::stub($field->handles(Arg::any()))->will()->return_(true);
     Mockster::stub($field->render(Arg::any(), Arg::any()))->will()->forwardTo($callback);
 }
Example #24
0
 /**
  * @param Parameter $parameter
  * @param string $serialized
  * @return mixed
  */
 public function inflate(Parameter $parameter, $serialized)
 {
     $param = new Parameter($parameter->getName() . '-value', $this->getOptionType($parameter));
     return $this->fields->getField($param)->inflate($param, $serialized);
 }