コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function isComplete(ProductValueInterface $productValue, ChannelInterface $channel = null, LocaleInterface $locale = null)
 {
     $metric = $productValue->getMetric();
     if (!$metric || null === $metric->getData()) {
         return false;
     }
     return true;
 }
コード例 #2
0
 function it_validates_product_value_with_metric_data($accessor, $context, ValidMetric $constraint, ProductValueInterface $value, MetricInterface $metric)
 {
     $value->getMetric()->willReturn($metric);
     $metric->getUnit()->willReturn('cm');
     $metric->getData()->willReturn(12);
     $accessor->getValue($metric, 'family')->shouldBeCalled()->willReturn('Weight');
     $accessor->getValue($metric, 'unit')->shouldBeCalled()->willReturn('kg');
     $context->buildViolation(Argument::cetera())->shouldNotBeCalled();
     $this->validate($value, $constraint)->shouldReturn(null);
 }
コード例 #3
0
 /**
  * The metric is built by many ordered calls, one for the data column, one for the unit column
  *
  * @param ProductValueInterface $value
  * @param string                $dataOrUnit
  *
  * @return MetricInterface
  */
 protected function addFromManyFields(ProductValueInterface $value, $dataOrUnit)
 {
     // TODO come from original implementation, really FRAGIL because depends on many ordered calls
     if (null === ($metric = $value->getMetric())) {
         $metric = $this->factory->createMetric($value->getAttribute()->getMetricFamily());
         $metric->setData($dataOrUnit);
     } else {
         $metric->setUnit($dataOrUnit);
     }
     return $metric;
 }
コード例 #4
0
 public function it_succesfully_checks_complete_metric(ProductValueInterface $value, ChannelInterface $channel, LocaleInterface $locale, MetricInterface $metric)
 {
     $value->getMetric()->willReturn(null);
     $this->isComplete($value, $channel, $locale)->shouldReturn(false);
     $value->getMetric()->willReturn([]);
     $this->isComplete($value, $channel, $locale)->shouldReturn(false);
     $metric->getData()->willReturn(null);
     $value->getMetric()->willReturn($metric);
     $this->isComplete($value, $channel, $locale)->shouldReturn(false);
     $metric->getData()->willReturn('foobar');
     $value->getMetric()->willReturn($metric);
     $this->isComplete($value, $channel, $locale)->shouldReturn(true);
 }
コード例 #5
0
 /**
  * Validate metric type and default metric unit
  *
  * @param AttributeInterface|MetricInterface|ProductValueInterface $object
  * @param Constraint                                               $constraint
  */
 public function validate($object, Constraint $constraint)
 {
     if ($object instanceof AttributeInterface) {
         $familyProperty = 'metricFamily';
         $unitProperty = 'defaultMetricUnit';
     } elseif ($object instanceof MetricInterface && null !== $object->getData()) {
         $familyProperty = 'family';
         $unitProperty = 'unit';
     } elseif ($object instanceof ProductValueInterface && null !== $object->getMetric() && (null !== $object->getMetric()->getUnit() || null !== $object->getMetric()->getData())) {
         $object = $object->getMetric();
         $familyProperty = 'family';
         $unitProperty = 'unit';
     } else {
         return;
     }
     $family = $this->propertyAccessor->getValue($object, $familyProperty);
     $unit = $this->propertyAccessor->getValue($object, $unitProperty);
     if (!array_key_exists($family, $this->measures)) {
         $this->context->buildViolation($constraint->familyMessage)->atPath($familyProperty)->addViolation();
     } elseif (!array_key_exists($unit, $this->measures[$family]['units'])) {
         $this->context->buildViolation($constraint->unitMessage)->atPath($unitProperty)->addViolation();
     }
 }
コード例 #6
0
 function it_returns_a_metric_if_the_data_is_empty(ProductValueInterface $metricValue, MetricInterface $metric)
 {
     $metricValue->getMetric()->willReturn($metric);
     $this->denormalize('', 'className', null, ['value' => $metricValue])->shouldReturn($metric);
     $this->denormalize(null, 'className', null, ['value' => $metricValue])->shouldReturn($metric);
 }
コード例 #7
0
 /**
  * Check if the metric value is not empty
  *
  * @param ProductValueInterface $value
  * @param Constraint            $constraint
  */
 protected function validateMetric(ProductValueInterface $value, Constraint $constraint)
 {
     $metric = $value->getMetric();
     if (!$metric || $metric->getData() === null) {
         $this->context->buildViolation($constraint->messageComplete)->addViolation();
     }
 }
 function it_returns_null_when_unknown_backendtype($context, ProductValueComplete $constraint, ProductValueInterface $productValue, AttributeInterface $attribute)
 {
     $constraint->getChannel()->willReturn($this->getChannel());
     $metric = new Metric();
     $productValue->getMetric()->willReturn($metric);
     $productValue->getData()->willReturn('data');
     $attribute->getBackendType()->willReturn('unknown_metric');
     $productValue->getAttribute()->willReturn($attribute);
     $context->buildViolation(Argument::any())->shouldNotBeCalled();
     $this->validate($productValue, $constraint);
 }