/** * Environment setup */ protected function setUp() { $this->attributeTypeMock = $this->getMock('OroB2B\\Bundle\\AttributeBundle\\AttributeType\\AttributeTypeInterface'); $this->attributeTypeMock->expects($this->any())->method('getName')->will($this->returnValue(self::ATTRIBUTE_TYPE_NAME)); /** @var \Symfony\Component\Translation\TranslatorInterface $translator */ $translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface'); $this->registry = new AttributeTypeRegistry($translator); $this->registry->addType($this->attributeTypeMock); }
protected function setUp() { $localeRepository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository'); $localeRepository->expects($this->any())->method('find')->will($this->returnValueMap([[1, $this->getLocale(1)], [2, $this->getLocale(2)]])); $websiteRepository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository'); $websiteRepository->expects($this->any())->method('find')->will($this->returnValueMap([[1, $this->getWebsite(1)], [2, $this->getWebsite(2)]])); $repositoriesMap = [['OroB2BWebsiteBundle:Locale', null, $localeRepository], ['OroB2BWebsiteBundle:Website', null, $websiteRepository]]; $this->managerRegistry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry'); $this->managerRegistry->expects($this->any())->method('getRepository')->will($this->returnValueMap($repositoriesMap)); $this->typeRegistry = new AttributeTypeRegistry(); $this->typeRegistry->addType(new Text()); $this->typeRegistry->addType(new Integer()); $this->typeRegistry->addType(new Select()); }
/** * @expectedException \Symfony\Component\Form\Exception\LogicException * @expectedExceptionMessage Form type is required for attribute type "invalid" */ public function testBuildFormNoFormTypeOptionsException() { $type = 'invalid'; /** @var \PHPUnit_Framework_MockObject_MockObject|AttributeTypeInterface $invalidAttributeType */ $invalidAttributeType = $this->getMock('OroB2B\\Bundle\\AttributeBundle\\AttributeType\\OptionAttributeTypeInterface'); $invalidAttributeType->expects($this->any())->method('getName')->will($this->returnValue($type)); $invalidAttributeType->expects($this->any())->method('getDefaultValueFormParameters')->will($this->returnValue([])); $this->typeRegistry->addType($invalidAttributeType); $attribute = new Attribute(); $attribute->setType($type); /** @var \PHPUnit_Framework_MockObject_MockObject|FormBuilderInterface $builder */ $builder = $this->getMock('Symfony\\Component\\Form\\FormBuilderInterface'); $builder->expects($this->any())->method('add')->willReturnSelf(); $this->formType->buildForm($builder, ['data' => $attribute]); }