public function testConstructorWithAllParams()
 {
     $enumValue = new TestEnumValue('test', 'Test', 123, true);
     $this->assertEquals('test', $enumValue->getId());
     $this->assertEquals('Test', $enumValue->getName());
     $this->assertEquals(123, $enumValue->getPriority());
     $this->assertTrue($enumValue->isDefault());
 }
示例#2
0
 public function testApplyEnumOptionsWithDuplicatedIdsAndGeneratedIdEqualsRemovingId()
 {
     $enumValueClassName = 'Test\\EnumValue';
     $locale = 'fr';
     $enumOptions = [['id' => 'option_1', 'label' => 'Existing Option 1', 'priority' => 1, 'is_default' => true], ['id' => 'option_1_1', 'label' => 'Existing Option 11', 'priority' => 3, 'is_default' => false], ['id' => '', 'label' => 'Option 1', 'priority' => 2, 'is_default' => true]];
     $value1 = new TestEnumValue('option_1', 'Existing Option 1', 1, true);
     $value2 = new TestEnumValue('option_1_1', 'Existing Option 11', 3, true);
     $value3 = new TestEnumValue('option_1_2', 'Existing Option 12', 2, false);
     $newValue = new TestEnumValue('option_1_2', 'Option 1', 2, true);
     $values = [$value1, $value2, $value3];
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->doctrine->expects($this->once())->method('getManagerForClass')->with($enumValueClassName)->will($this->returnValue($em));
     $enumRepo = $this->setApplyEnumOptionsQueryExpectation($em, $enumValueClassName, $locale, $values);
     $em->expects($this->once())->method('remove')->with($this->identicalTo($value3));
     $enumRepo->expects($this->once())->method('createEnumValue')->with('Option 1', 2, true, 'option_1_2')->will($this->returnValue($newValue));
     $em->expects($this->once())->method('persist')->with($this->identicalTo($newValue));
     $em->expects($this->once())->method('flush');
     $this->dbTranslationMetadataCache->expects($this->once())->method('updateTimestamp')->with($locale);
     $this->synchronizer->applyEnumOptions($enumValueClassName, $enumOptions, $locale);
     $expectedValue1 = new TestEnumValue('option_1', 'Existing Option 1', 1, true);
     $this->assertEquals($expectedValue1, $value1);
     $expectedValue2 = new TestEnumValue('option_1_1', 'Existing Option 11', 3, false);
     $expectedValue2->setLocale($locale);
     $this->assertEquals($expectedValue2, $value2);
     $expectedNewValue = new TestEnumValue('option_1_2', 'Option 1', 2, true);
     $expectedNewValue->setLocale($locale);
     $this->assertEquals($expectedNewValue, $newValue);
 }