function let(FeatureValidatorInterface $validator, PlanInterface $plan, AttachedInterface $attachedFeature, FeatureInterface $feature) { $this->beConstructedWith($validator); $feature->getSlug()->willReturn('first_feature'); $attachedFeature->getValue()->willReturn(null); $attachedFeature->getFeature()->willReturn($feature); $af = $attachedFeature->getWrappedObject(); $validator->validate($af->getFeature(), $af->getValue(), null)->willReturn(true); $plan->getAttachedFeatures()->willReturn(array($attachedFeature)); }
/** * Return not plans features * * @param PlanFeaturesAcl\Feature\FeatureInterface $plansFeatures * @return DataMapper */ public function getFreeFeatures($plansFeatures) { if ($plansFeatures->exists()) { $ids = array(); foreach ($plansFeatures as $plansFeature) { $ids[] = $plansFeature->feature_id; } $this->where_not_in('id', $ids); } return $this->get(); }
function let(FeatureInterface $ltNumericFeature, FeatureInterface $lteNumericFeature, FeatureInterface $gtNumericFeature, FeatureInterface $gteNumericFeature, FeatureInterface $eqNumericFeature, FeatureInterface $neqNumericFeature, FeatureInterface $waNumericFeature) { $ltNumericFeature->getType()->willReturn('numeric'); $ltNumericFeature->getValidationRules()->willReturn(json_encode(array('lt'))); $lteNumericFeature->getType()->willReturn('numeric'); $lteNumericFeature->getValidationRules()->willReturn(json_encode(array('lte'))); $gtNumericFeature->getType()->willReturn('numeric'); $gtNumericFeature->getValidationRules()->willReturn(json_encode(array('gt'))); $gteNumericFeature->getType()->willReturn('numeric'); $gteNumericFeature->getValidationRules()->willReturn(json_encode(array('gte'))); $eqNumericFeature->getType()->willReturn('numeric'); $eqNumericFeature->getValidationRules()->willReturn(json_encode(array('eq'))); $neqNumericFeature->getType()->willReturn('numeric'); $neqNumericFeature->getValidationRules()->willReturn(json_encode(array('neq'))); $waNumericFeature->getType()->willReturn('numeric'); $waNumericFeature->getValidationRules()->willReturn(null); }
/** * {@inheritDoc} */ public function validate(FeatureInterface $feature, $featureValue, $validatedValue) { if (!is_numeric($featureValue)) { throw new InvalidArgumentException('The value of feature should be numeric(is_numeric).'); } if (!is_numeric($validatedValue)) { throw new InvalidArgumentException('The validated value should be numeric(is_numeric).'); } $rules = $this->parseValidationRules($feature->getValidationRules()); if (empty($rules)) { return true; } $isValid = true; foreach ($rules as $rule) { switch ($rule) { case 'lt': $isValid = $validatedValue < $featureValue; break; case 'lte': $isValid = $validatedValue <= $featureValue; break; case 'gt': $isValid = $validatedValue > $featureValue; break; case 'gte': $isValid = $validatedValue >= $featureValue; break; case 'eq': $isValid = $validatedValue == $featureValue; break; case 'neq': $isValid = $validatedValue != $featureValue; break; } if (!$isValid) { break; } } return $isValid; }
/** * {@inheritDoc} */ public function validate(FeatureInterface $feature, $featureValue, $validatedValue) { $constraint = $this->constraintFactory->getConstraint($feature->getType()); return $constraint->validate($feature, $featureValue, $validatedValue); }
function it_should_use_factory_object(FeatureInterface $boolFeature, ConstraintFactoryInterface $constraintFactory) { $bf = $boolFeature->getWrappedObject(); $constraintFactory->getConstraint($bf->getType())->shouldBeCalled(); $this->validate($boolFeature, null, null); }