How to use spec method of or class

Best AspectMock code snippet using or.spec

Factory.php

Source:Factory.php Github

copy

Full Screen

...82 }83 /**84 * Create an element, fieldset, or form85 *86 * Introspects the 'type' key of the provided $spec, and determines what87 * type is being requested; if none is provided, assumes the spec88 * represents simply an element.89 *90 * @param array|Traversable $spec91 * @return ElementInterface92 * @throws Exception\DomainException93 */94 public function create($spec)95 {96 $spec = $this->validateSpecification($spec, __METHOD__);97 $type = isset($spec['type']) ? $spec['type'] : 'Zend\Form\Element';98 $element = $this->getFormElementManager()->get($type);99 if ($element instanceof FormInterface) {100 return $this->configureForm($element, $spec);101 }102 if ($element instanceof FieldsetInterface) {103 return $this->configureFieldset($element, $spec);104 }105 if ($element instanceof ElementInterface) {106 return $this->configureElement($element, $spec);107 }108 throw new Exception\DomainException(sprintf(109 '%s expects the $spec["type"] to implement one of %s, %s, or %s; received %s',110 __METHOD__,111 'Zend\Form\ElementInterface',112 'Zend\Form\FieldsetInterface',113 'Zend\Form\FormInterface',114 $type115 ));116 }117 /**118 * Create an element119 *120 * @param array $spec121 * @return ElementInterface122 */123 public function createElement($spec)124 {125 if (!isset($spec['type'])) {126 $spec['type'] = 'Zend\Form\Element';127 }128 return $this->create($spec);129 }130 /**131 * Create a fieldset132 *133 * @param array $spec134 * @return ElementInterface135 */136 public function createFieldset($spec)137 {138 if (!isset($spec['type'])) {139 $spec['type'] = 'Zend\Form\Fieldset';140 }141 return $this->create($spec);142 }143 /**144 * Create a form145 *146 * @param array $spec147 * @return ElementInterface148 */149 public function createForm($spec)150 {151 if (!isset($spec['type'])) {152 $spec['type'] = 'Zend\Form\Form';153 }154 return $this->create($spec);155 }156 /**157 * Configure an element based on the provided specification158 *159 * Specification can contain any of the following:160 * - type: the Element class to use; defaults to \Zend\Form\Element161 * - name: what name to provide the element, if any162 * - options: an array, Traversable, or ArrayAccess object of element options163 * - attributes: an array, Traversable, or ArrayAccess object of element164 * attributes to assign165 *166 * @param ElementInterface $element167 * @param array|Traversable|ArrayAccess $spec168 * @throws Exception\DomainException169 * @return ElementInterface170 */171 public function configureElement(ElementInterface $element, $spec)172 {173 $spec = $this->validateSpecification($spec, __METHOD__);174 $name = isset($spec['name']) ? $spec['name'] : null;175 $options = isset($spec['options']) ? $spec['options'] : null;176 $attributes = isset($spec['attributes']) ? $spec['attributes'] : null;177 if ($name !== null && $name !== '') {178 $element->setName($name);179 }180 if (is_array($options) || $options instanceof Traversable || $options instanceof ArrayAccess) {181 $element->setOptions($options);182 }183 if (is_array($attributes) || $attributes instanceof Traversable || $attributes instanceof ArrayAccess) {184 $element->setAttributes($attributes);185 }186 return $element;187 }188 /**189 * Configure a fieldset based on the provided specification190 *191 * Specification can contain any of the following:192 * - type: the Fieldset class to use; defaults to \Zend\Form\Fieldset193 * - name: what name to provide the fieldset, if any194 * - options: an array, Traversable, or ArrayAccess object of element options195 * - attributes: an array, Traversable, or ArrayAccess object of element196 * attributes to assign197 * - elements: an array or Traversable object where each entry is an array198 * or ArrayAccess object containing the keys:199 * - flags: (optional) array of flags to pass to FieldsetInterface::add()200 * - spec: the actual element specification, per {@link configureElement()}201 *202 * @param FieldsetInterface $fieldset203 * @param array|Traversable|ArrayAccess $spec204 * @throws Exception\DomainException205 * @return FieldsetInterface206 */207 public function configureFieldset(FieldsetInterface $fieldset, $spec)208 {209 $spec = $this->validateSpecification($spec, __METHOD__);210 $fieldset = $this->configureElement($fieldset, $spec);211 if (isset($spec['object'])) {212 $this->prepareAndInjectObject($spec['object'], $fieldset, __METHOD__);213 }214 if (isset($spec['hydrator'])) {215 $this->prepareAndInjectHydrator($spec['hydrator'], $fieldset, __METHOD__);216 }217 if (isset($spec['elements'])) {218 $this->prepareAndInjectElements($spec['elements'], $fieldset, __METHOD__);219 }220 if (isset($spec['fieldsets'])) {221 $this->prepareAndInjectFieldsets($spec['fieldsets'], $fieldset, __METHOD__);222 }223 $factory = (isset($spec['factory']) ? $spec['factory'] : $this);224 $this->prepareAndInjectFactory($factory, $fieldset, __METHOD__);225 return $fieldset;226 }227 /**228 * Configure a form based on the provided specification229 *230 * Specification follows that of {@link configureFieldset()}, and adds the231 * following keys:232 *233 * - input_filter: input filter instance, named input filter class, or234 * array specification for the input filter factory235 * - hydrator: hydrator instance or named hydrator class236 *237 * @param FormInterface $form238 * @param array|Traversable|ArrayAccess $spec239 * @return FormInterface240 */241 public function configureForm(FormInterface $form, $spec)242 {243 $spec = $this->validateSpecification($spec, __METHOD__);244 $form = $this->configureFieldset($form, $spec);245 if (isset($spec['input_filter'])) {246 $this->prepareAndInjectInputFilter($spec['input_filter'], $form, __METHOD__);247 }248 if (isset($spec['validation_group'])) {249 $this->prepareAndInjectValidationGroup($spec['validation_group'], $form, __METHOD__);250 }251 return $form;252 }253 /**254 * Validate a provided specification255 *256 * Ensures we have an array, Traversable, or ArrayAccess object, and returns it.257 *258 * @param array|Traversable|ArrayAccess $spec259 * @param string $method Method invoking the validator260 * @return array|ArrayAccess261 * @throws Exception\InvalidArgumentException for invalid $spec262 */263 protected function validateSpecification($spec, $method)264 {265 if (is_array($spec)) {266 return $spec;267 }268 if ($spec instanceof Traversable) {269 $spec = ArrayUtils::iteratorToArray($spec);270 return $spec;271 }272 if (!$spec instanceof ArrayAccess) {273 throw new Exception\InvalidArgumentException(sprintf(274 '%s expects an array, or object implementing Traversable or ArrayAccess; received "%s"',275 $method,276 (is_object($spec) ? get_class($spec) : gettype($spec))277 ));278 }279 return $spec;280 }281 /**282 * Takes a list of element specifications, creates the elements, and injects them into the provided fieldset283 *284 * @param array|Traversable|ArrayAccess $elements285 * @param FieldsetInterface $fieldset286 * @param string $method Method invoking this one (for exception messages)287 * @return void288 */289 protected function prepareAndInjectElements($elements, FieldsetInterface $fieldset, $method)290 {291 $elements = $this->validateSpecification($elements, $method);292 foreach ($elements as $elementSpecification) {293 if (null === $elementSpecification) {294 continue;295 }296 $flags = isset($elementSpecification['flags']) ? $elementSpecification['flags'] : array();297 $spec = isset($elementSpecification['spec']) ? $elementSpecification['spec'] : array();298 if (!isset($spec['type'])) {299 $spec['type'] = 'Zend\Form\Element';300 }301 $element = $this->create($spec);302 $fieldset->add($element, $flags);303 }304 }305 /**306 * Takes a list of fieldset specifications, creates the fieldsets, and injects them into the master fieldset307 *308 * @param array|Traversable|ArrayAccess $fieldsets309 * @param FieldsetInterface $masterFieldset310 * @param string $method Method invoking this one (for exception messages)311 * @return void312 */313 public function prepareAndInjectFieldsets($fieldsets, FieldsetInterface $masterFieldset, $method)314 {315 $fieldsets = $this->validateSpecification($fieldsets, $method);316 foreach ($fieldsets as $fieldsetSpecification) {317 $flags = isset($fieldsetSpecification['flags']) ? $fieldsetSpecification['flags'] : array();318 $spec = isset($fieldsetSpecification['spec']) ? $fieldsetSpecification['spec'] : array();319 $fieldset = $this->createFieldset($spec);320 $masterFieldset->add($fieldset, $flags);321 }322 }323 /**324 * Prepare and inject an object325 *326 * Takes a string indicating a class name, instantiates the class327 * by that name, and injects the class instance as the bound object.328 *329 * @param string $objectName330 * @param FieldsetInterface $fieldset331 * @param string $method332 * @throws Exception\DomainException333 * @return void334 */335 protected function prepareAndInjectObject($objectName, FieldsetInterface $fieldset, $method)336 {337 if (!is_string($objectName)) {338 throw new Exception\DomainException(sprintf(339 '%s expects string class name; received "%s"',340 $method,341 (is_object($objectName) ? get_class($objectName) : gettype($objectName))342 ));343 }344 if (!class_exists($objectName)) {345 throw new Exception\DomainException(sprintf(346 '%s expects string class name to be a valid class name; received "%s"',347 $method,348 $objectName349 ));350 }351 $fieldset->setObject(new $objectName);352 }353 /**354 * Prepare and inject a named hydrator355 *356 * Takes a string indicating a hydrator class name (or a concrete instance), try first to instantiates the class357 * by pulling it from service manager, and injects the hydrator instance into the form.358 *359 * @param string|array|Hydrator\HydratorInterface $hydratorOrName360 * @param FieldsetInterface $fieldset361 * @param string $method362 * @return void363 * @throws Exception\DomainException If $hydratorOrName is not a string, does not resolve to a known class, or364 * the class does not implement Hydrator\HydratorInterface365 */366 protected function prepareAndInjectHydrator($hydratorOrName, FieldsetInterface $fieldset, $method)367 {368 if ($hydratorOrName instanceof Hydrator\HydratorInterface) {369 $fieldset->setHydrator($hydratorOrName);370 return;371 }372 if (is_array($hydratorOrName)) {373 if (!isset($hydratorOrName['type'])) {374 throw new Exception\DomainException(sprintf(375 '%s expects array specification to have a type value',376 $method377 ));378 }379 $hydratorOptions = (isset($hydratorOrName['options'])) ? $hydratorOrName['options'] : array();380 $hydratorOrName = $hydratorOrName['type'];381 } else {382 $hydratorOptions = array();383 }384 if (is_string($hydratorOrName)) {385 $hydrator = $this->getHydratorFromName($hydratorOrName);386 }387 if (!$hydrator instanceof Hydrator\HydratorInterface) {388 throw new Exception\DomainException(sprintf(389 '%s expects a valid implementation of Zend\Stdlib\Hydrator\HydratorInterface; received "%s"',390 $method,391 $hydratorOrName392 ));393 }394 if (!empty($hydratorOptions) && $hydrator instanceof Hydrator\HydratorOptionsInterface) {395 $hydrator->setOptions($hydratorOptions);396 }397 $fieldset->setHydrator($hydrator);398 }399 /**400 * Prepare and inject a named factory401 *402 * Takes a string indicating a factory class name (or a concrete instance), try first to instantiates the class403 * by pulling it from service manager, and injects the factory instance into the fieldset.404 *405 * @param string|array|Factory $factoryOrName406 * @param FieldsetInterface $fieldset407 * @param string $method408 * @return void409 * @throws Exception\DomainException If $factoryOrName is not a string, does not resolve to a known class, or410 * the class does not extend Form\Factory411 */412 protected function prepareAndInjectFactory($factoryOrName, FieldsetInterface $fieldset, $method)413 {414 if (is_array($factoryOrName)) {415 if (!isset($factoryOrName['type'])) {416 throw new Exception\DomainException(sprintf(417 '%s expects array specification to have a type value',418 $method419 ));420 }421 $factoryOrName = $factoryOrName['type'];422 }423 if (is_string($factoryOrName)) {424 $factoryOrName = $this->getFactoryFromName($factoryOrName);425 }426 if (!$factoryOrName instanceof Factory) {427 throw new Exception\DomainException(sprintf(428 '%s expects a valid extention of Zend\Form\Factory; received "%s"',429 $method,430 $factoryOrName431 ));432 }433 $fieldset->setFormFactory($factoryOrName);434 }435 /**436 * Prepare an input filter instance and inject in the provided form437 *438 * If the input filter specified is a string, assumes it is a class name,439 * and attempts to instantiate it. If the class does not exist, or does440 * not extend InputFilterInterface, an exception is raised.441 *442 * Otherwise, $spec is passed on to the attached InputFilter Factory443 * instance in order to create the input filter.444 *445 * @param string|array|Traversable $spec446 * @param FormInterface $form447 * @param string $method448 * @return void449 * @throws Exception\DomainException for unknown InputFilter class or invalid InputFilter instance450 */451 protected function prepareAndInjectInputFilter($spec, FormInterface $form, $method)452 {453 if ($spec instanceof InputFilterInterface) {454 $form->setInputFilter($spec);455 return;456 }457 if (is_string($spec)) {458 if (!class_exists($spec)) {459 throw new Exception\DomainException(sprintf(460 '%s expects string input filter names to be valid class names; received "%s"',461 $method,462 $spec463 ));464 }465 $filter = new $spec;466 if (!$filter instanceof InputFilterInterface) {467 throw new Exception\DomainException(sprintf(468 '%s expects a valid implementation of Zend\InputFilter\InputFilterInterface; received "%s"',469 $method,470 $spec471 ));472 }473 $form->setInputFilter($filter);474 return;475 }476 $factory = $this->getInputFilterFactory();477 $filter = $factory->createInputFilter($spec);478 if (method_exists($filter, 'setFactory')) {479 $filter->setFactory($factory);480 }481 $form->setInputFilter($filter);482 }483 /**484 * Prepare a validation group and inject in the provided form485 *486 * Takes an array of elements names487 *488 * @param string|array|Traversable $spec489 * @param FormInterface $form490 * @param string $method491 * @return void492 * @throws Exception\DomainException if validation group given is not an array493 */494 protected function prepareAndInjectValidationGroup($spec, FormInterface $form, $method)495 {496 if (!is_array($spec)) {497 if (!class_exists($spec)) {498 throw new Exception\DomainException(sprintf(499 '%s expects an array for validation group; received "%s"',500 $method,501 $spec502 ));503 }504 }505 $form->setValidationGroup($spec);506 }507 /**508 * Try to pull hydrator from service manager, or instantiates it from its name509 *510 * @param string $hydratorName511 * @return mixed512 * @throws Exception\DomainException513 */514 protected function getHydratorFromName($hydratorName)515 {516 $services = $this->getFormElementManager()->getServiceLocator();517 if ($services && $services->has('HydratorManager')) {518 $hydrators = $services->get('HydratorManager');519 if ($hydrators->has($hydratorName)) {...

Full Screen

Full Screen

spec

Using AI Code Generation

copy

Full Screen

1$myObj = new MyClass();2$myObj->spec();3$myObj = new MyClass();4$myObj->spec();5$myObj = new MyClass();6$myObj->spec();7$myObj = new MyClass();8$myObj->spec();9$myObj = new MyClass();10$myObj->spec();

Full Screen

Full Screen

spec

Using AI Code Generation

copy

Full Screen

1require '1.php';2use \My\Full\Classname as AnotherClass;3$obj = new AnotherClass;4$obj->method();5namespace My\Full;6require '1.php';7use My\Full\NSname;8$obj = new NSname;9$obj->method();10namespace My\Full;11require '1.php';12use My\Full\NSname as AnotherClass;13$obj = new AnotherClass;14$obj->method();15namespace My\Full;16require '1.php';17use My\Full\NSname;18$obj = new NSname;19$obj->method();20namespace My\Full;21require '1.php';22use My\Full\NSname as AnotherClass;23$obj = new AnotherClass;24$obj->method();25namespace My\Full;26require '1.php';27use My\Full\NSname;28$obj = new NSname;29$obj->method();30namespace My\Full;31require '1.php';32use My\Full\NSname as AnotherClass;33$obj = new AnotherClass;34$obj->method();35namespace My\Full;36require '1.php';37use My\Full\NSname;38$obj = new NSname;39$obj->method();40namespace My\Full;41require '1.php';42use My\Full\NSname as AnotherClass;43$obj = new AnotherClass;44$obj->method();45namespace My\Full;46require '1.php';47use My\Full\NSname;48$obj = new NSname;49$obj->method();50namespace My\Full;51require '1.php';52use My\Full\NSname as AnotherClass;53$obj = new AnotherClass;54$obj->method();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run AspectMock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in or

Trigger spec code on LambdaTest Cloud Grid

Execute automation tests with spec on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful