/** * @dataProvider setDefaultOptionsProvider */ public function testSetDefaultOptions($enumCode, $class, $nullValue, $fieldOptions, $expectedOptions) { $values = [new TestEnumValue('val1', 'Value1')]; $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(array('getResult'))->getMockForAbstractClass(); $query->expects($this->any())->method('getResult')->will($this->returnValue($values)); $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock(); $qb->expects($this->any())->method('orderBy')->with('o.priority')->will($this->returnSelf()); $qb->expects($this->any())->method('getQuery')->will($this->returnValue($query)); $repo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $this->doctrine->expects($this->any())->method('getRepository')->with($class !== null ? $class : ExtendHelper::buildEnumValueClassName($enumCode))->will($this->returnValue($repo)); $repo->expects($this->any())->method('createQueryBuilder')->with('o')->will($this->returnValue($qb)); $this->translator->expects($this->any())->method('trans')->with('oro.entity_extend.datagrid.enum.filter.empty')->will($this->returnValue('None')); $resolver = $this->getOptionsResolver(); $this->type->setDefaultOptions($resolver); $options = []; if ($enumCode !== null) { $options['enum_code'] = $enumCode; } if ($class !== null) { $options['class'] = $class; } if ($nullValue !== null) { $options['null_value'] = $nullValue; } if ($fieldOptions !== null) { $options['field_options'] = $fieldOptions; } $resolvedOptions = $resolver->resolve($options); $this->assertEquals($expectedOptions, $resolvedOptions); }
/** * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException * @expectedExceptionMessage must be a child of "Oro\Bundle\EntityExtendBundle\Entity\AbstractEnumValue" */ public function testClassNormalizerUnexpectedEnumException() { $resolver = $this->getOptionsResolver(); $this->type->setDefaultOptions($resolver); $resolver->resolve(['enum_code' => 'unknown', 'null_value' => ':empty:']); }