/** * {@inheritDoc} */ public function process(ProcessableInterface $processable, array $variables) { $values = $processable->getValue(); foreach ($values as $key => $value) { $values[$key] = $this->processor->process($value, $variables); } return $values; }
/** * {@inheritDoc} */ public function process(ProcessableInterface $processable, array $variables) { $trueValue = $this->processor->process($processable->getMatch('trueValue'), $variables); if ($this->shouldReturnTrue($processable)) { return $trueValue; } elseif (!is_null($processable->getMatch('falseValue')) && '' !== $processable->getMatch('falseValue')) { return $this->processor->process($processable->getMatch('falseValue'), $variables); } else { return is_array($trueValue) ? [] : null; } }
/** * {@inheritDoc} */ public function instantiate(Fixture $fixture) { $class = $fixture->getClass(); $constructorMethod = $fixture->getConstructorMethod(); $constructorArgs = $fixture->getConstructorArgs(); $reflClass = new \ReflectionClass($class); $constructorArgs = $this->processor->process($constructorArgs, array(), $fixture->getValueForCurrent()); foreach ($constructorArgs as $index => $value) { $constructorArgs[$index] = $this->typeHintChecker->check($class, $constructorMethod, $value, $index); } if ($constructorMethod === '__construct') { $instance = $reflClass->newInstanceArgs($constructorArgs); } else { $instance = forward_static_call_array(array($class, $constructorMethod), $constructorArgs); if (!$instance instanceof $class) { throw new \UnexpectedValueException("The static constructor '{$constructorMethod}' for object '{$fixture}' returned an object that is not an instance of '{$class}'"); } } return $instance; }
/** * ensures that the property generated for the given fixture is a unique property * * @param Fixture $fixture * @param PropertyDefinition $property * @return mixed */ protected function generateUnique(Fixture $fixture, PropertyDefinition $property) { $class = $fixture->getClass(); $key = $property->getName(); $i = $uniqueTriesLimit = 128; do { // process values $value = $this->processor->process($property, $fixture->getSetProperties(), $fixture->getValueForCurrent()); if (is_object($value)) { $valHash = spl_object_hash($value); } elseif (is_array($value)) { $valHash = hash('md4', serialize($value)); } else { $valHash = $value; } } while (--$i > 0 && isset($this->uniqueValues[$class . $key][$valHash])); if (isset($this->uniqueValues[$class . $key][$valHash])) { throw new \RuntimeException("Couldn't generate random unique value for {$class}: {$key} in {$uniqueTriesLimit} tries."); } $this->uniqueValues[$class . $key][$valHash] = true; return $value; }
public function testAddProcessorWillSetTheProcessorIfSetterExists() { $this->createProcessor(); $this->processor->addProcessor($custom = new CustomProcessor()); $this->assertEquals($this->processor, $custom->processor); }