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); }
/** * @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]); }
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()); }
/** * @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; }
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; }
/** * @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; }
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]; }
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]; }
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)); }
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)); }
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); }
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); }
/** * @param $itemParameter * @return CliField * @throws \Exception */ private function getField($itemParameter) { return $this->fields->getField($itemParameter); }
/** * @param Parameter $param * @return CliField */ private function getField(Parameter $param) { return $this->fields->getField($param); }
private function itemHeadElements(Parameter $itemParameter) { /** @var WebField $field */ $field = $this->fields->getField($itemParameter); return $field->headElements($itemParameter); }
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); }
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')); }
/** * @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]); }
/** * @param Parameter $innerParameter * @return WebField */ private function getInnerField(Parameter $innerParameter) { return $this->fields->getField($innerParameter); }
/** * @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); }
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); }
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); }
/** * @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); }