コード例 #1
0
 public function testGetFieldNameByColumnName()
 {
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $metadata->expects($this->once())->method('getTableName')->will($this->returnValue('acme_test'));
     $metadata->expects($this->once())->method('getFieldName')->with('name_column')->will($this->returnValue('name_field'));
     $metadata->expects($this->once())->method('getName')->will($this->returnValue('Oro\\Bundle\\EntityBundle\\Tests\\Unit\\ORM\\Fixtures\\TestEntity'));
     $metadataFactory = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadataFactory')->disableOriginalConstructor()->getMock();
     $metadataFactory->expects($this->once())->method('getAllMetadata')->will($this->returnValue([$metadata]));
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $em->expects($this->once())->method('getMetadataFactory')->will($this->returnValue($metadataFactory));
     $em->expects($this->once())->method('getClassMetadata')->with('Oro\\Bundle\\EntityBundle\\Tests\\Unit\\ORM\\Fixtures\\TestEntity')->will($this->returnValue($metadata));
     $this->doctrine->expects($this->once())->method('getManagers')->will($this->returnValue(array('default' => $em)));
     $this->doctrine->expects($this->once())->method('getManager')->with($this->equalTo('default'))->will($this->returnValue($em));
     $this->doctrine->expects($this->once())->method('getManagerForClass')->with('Oro\\Bundle\\EntityBundle\\Tests\\Unit\\ORM\\Fixtures\\TestEntity')->will($this->returnValue($em));
     $this->assertEquals('name_field', $this->helper->getFieldNameByColumnName('acme_test', 'name_column'));
 }
コード例 #2
0
ファイル: ExtendExtension.php プロジェクト: hugeval/platform
 /**
  * Gets a field name by a table name and a column name
  *
  * @param string $tableName
  * @param string $columnName
  *
  * @return string|null
  */
 public function getFieldNameByColumnName($tableName, $columnName)
 {
     return $this->entityMetadataHelper->getFieldNameByColumnName($tableName, $columnName);
 }
コード例 #3
0
 /**
  * Gets a field name by a column name
  *
  * @param string $tableName
  * @param string $columnName
  *
  * @return string
  */
 protected function getFieldName($tableName, $columnName)
 {
     $fieldName = $this->entityMetadataHelper->getFieldNameByColumnName($tableName, $columnName);
     return $fieldName ?: $columnName;
 }