/** * @dataProvider getReverseTransformMultipleTests */ public function testReverseTransformMultiple($expected, $params, $entity1, $entity2, $entity3) { $transformer = new ModelToIdPropertyTransformer($this->modelManager, 'Sonata\\AdminBundle\\Tests\\Fixtures\\Entity\\Foo', 'bar', true); $this->modelManager->expects($this->any())->method('find')->will($this->returnCallback(function ($className, $value) use($entity1, $entity2, $entity3) { if ($className != 'Sonata\\AdminBundle\\Tests\\Fixtures\\Entity\\Foo') { return; } if ($value == 123) { return $entity1; } if ($value == 456) { return $entity2; } if ($value == 789) { return $entity3; } return; })); $collection = new ArrayCollection(); $this->modelManager->expects($this->any())->method('getModelCollectionInstance')->with($this->equalTo('Sonata\\AdminBundle\\Tests\\Fixtures\\Entity\\Foo'))->will($this->returnValue($collection)); $result = $transformer->reverseTransform($params); $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $result); $this->assertSame($expected, $result->getValues()); }
/** * @dataProvider getReverseTransformMultipleInvalidTypeTests */ public function testReverseTransformMultipleInvalidTypeTests($expected, $params, $type) { $this->setExpectedException('UnexpectedValueException', sprintf('Value should be array, %s given.', $type)); $transformer = new ModelToIdPropertyTransformer($this->modelManager, 'Sonata\\AdminBundle\\Tests\\Fixtures\\Entity\\Foo', 'bar', true); $collection = new ArrayCollection(); $this->modelManager->expects($this->any())->method('getModelCollectionInstance')->with($this->equalTo('Sonata\\AdminBundle\\Tests\\Fixtures\\Entity\\Foo'))->will($this->returnValue($collection)); $result = $transformer->reverseTransform($params); $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $result); $this->assertEquals($expected, $result->getValues()); }