/**
  * @dataProvider getSetValueData
  */
 public function testSetValue($columnSuffix, $data, $createMetric, $expectedData, $expectedUnit)
 {
     $columnInfo = $this->getMock('Pim\\Bundle\\TransformBundle\\Transformer\\ColumnInfo\\ColumnInfoInterface');
     $columnInfo->expects($this->any())->method('getSuffixes')->will($this->returnValue([$columnSuffix]));
     $attribute = $this->getMockBuilder('Pim\\Component\\Catalog\\Model\\AbstractAttribute')->setMethods(['getMetricFamily'])->getMock();
     $columnInfo->expects($this->any())->method('getAttribute')->will($this->returnValue($attribute));
     $attribute->expects($this->any())->method('getMetricFamily')->will($this->returnValue('metric_family'));
     $object = $this->getMockBuilder('Pim\\Component\\Catalog\\Model\\ProductValueInterface')->setMethods(['setText', 'setDatetime', 'setInteger', 'setId', 'getOption', 'getMedia', 'getDecimal', 'setDecimal', 'setAttribute', 'addOption', 'getBoolean', 'setOptions', 'setPrices', 'getId', 'setVarchar', 'setBoolean', 'getData', 'getMetric', 'getDate', 'getAttribute', 'getEntity', 'setMedia', 'getPrices', 'getOptions', 'getLocale', 'setMetric', 'addPrice', 'getVarchar', 'removePrice', 'hasData', 'setScope', 'removeOption', 'getText', 'setData', 'setOption', 'getPrice', 'setDate', 'addData', 'setLocale', 'isRemovable', 'getScope', 'getDatetime', 'setEntity', 'getInteger', 'getProduct', 'setProduct', '__toString'])->getMock();
     $metric = null;
     if ($createMetric) {
         $object->expects($this->once())->method('setMetric')->will($this->returnCallback(function ($createdMetric) use(&$metric) {
             $metric = $createdMetric;
         }));
     } else {
         $metric = new Metric();
         $metric->setFamily('metric_family');
     }
     $object->expects($this->any())->method('getMetric')->will($this->returnCallback(function () use(&$metric) {
         return $metric;
     }));
     $metricFactory = new MetricFactory('Pim\\Component\\Catalog\\Model\\Metric');
     $transformer = new MetricTransformer($metricFactory);
     $transformer->setValue($object, $columnInfo, $data);
     $this->assertInstanceOf('Pim\\Component\\Catalog\\Model\\Metric', $metric);
     $this->assertEquals('metric_family', $metric->getFamily());
     $this->assertEquals($expectedData, $metric->getData());
     $this->assertEquals($expectedUnit, $metric->getUnit());
 }
 function it_normalizes_a_metric_into_mongodb_document($mongoFactory, $converter, $manager, Metric $metric, \MongoId $mongoId)
 {
     $mongoFactory->createMongoId()->willReturn($mongoId);
     $metric->getUnit()->willReturn('Kg');
     $metric->getData()->willReturn(85);
     $metric->getFamily()->willReturn('weight');
     $converter->setFamily('weight')->willReturn($converter);
     $converter->convertBaseToStandard('Kg', 85)->willReturn(8500);
     $manager->getStandardUnitForFamily('weight')->willReturn('g');
     $metric->setBaseData(8500)->shouldBeCalled();
     $metric->getBaseData()->willReturn(8500);
     $metric->setBaseUnit('g')->shouldBeCalled();
     $metric->getBaseUnit()->willReturn('g');
     $this->normalize($metric, 'mongodb_document')->shouldReturn(['_id' => $mongoId, 'family' => 'weight', 'unit' => 'Kg', 'data' => 85, 'baseUnit' => 'g', 'baseData' => 8500]);
 }
 function it_validates_a_product_value_with_backendtype_as_metric($context, ProductValueComplete $constraint, ProductValueInterface $productValue, AttributeInterface $attribute)
 {
     $constraint->getChannel()->willReturn($this->getChannel());
     $metric = new Metric();
     $metric->setData('data');
     $productValue->getMetric()->willReturn($metric);
     $productValue->getData()->willReturn('data');
     $attribute->getBackendType()->willReturn('metric');
     $productValue->getAttribute()->willReturn($attribute);
     $context->buildViolation(Argument::any())->shouldNotBeCalled();
     $this->validate($productValue, $constraint);
 }