public function testCreate() { $type = '1'; $data = ['data2', 'data3']; $this->objectManagerMock->expects($this->once())->method('create')->with($type, $data); $this->conditionFactory->create($type, $data); }
public function testExceptingClonedObject() { $origin = new \stdClass(); $this->objectManagerMock->expects($this->once())->method('create')->with('clone')->willReturn($origin); $cloned = $this->conditionFactory->create('clone'); $this->assertNotSame($cloned, $origin); }
/** * Retrieve new object for each requested model. * If model is requested first time, store it at static array. * * It's made by performance reasons to avoid initialization of same models each time when rules are being processed. * * @param string $modelClass * @return AbstractCondition|bool */ protected function _getNewConditionModelInstance($modelClass) { if (empty($modelClass)) { return false; } if (!array_key_exists($modelClass, $this->_conditionModels)) { $model = $this->_conditionFactory->create($modelClass); $this->_conditionModels[$modelClass] = $model; } else { $model = $this->_conditionModels[$modelClass]; } if (!$model) { return false; } $newModel = clone $model; return $newModel; }
/** * @param array $arr * @param string $key * @return $this * @SuppressWarnings(PHPMD.NPathComplexity) */ public function loadArray($arr, $key = 'conditions') { $this->setAggregator(isset($arr['aggregator']) ? $arr['aggregator'] : (isset($arr['attribute']) ? $arr['attribute'] : null))->setValue(isset($arr['value']) ? $arr['value'] : (isset($arr['operator']) ? $arr['operator'] : null)); if (!empty($arr[$key]) && is_array($arr[$key])) { foreach ($arr[$key] as $conditionArr) { try { $condition = $this->_conditionFactory->create($conditionArr['type']); $this->addCondition($condition); $condition->loadArray($conditionArr, $key); } catch (\Exception $e) { $this->_logger->critical($e); } } } return $this; }