1
0
mirror of synced 2024-12-14 15:16:04 +03:00
doctrine2/tests/Doctrine/Tests/ORM/Mapping/NamingStrategyTest.php

298 lines
8.9 KiB
PHP
Raw Normal View History

2011-12-22 18:07:18 +04:00
<?php
namespace Doctrine\Tests\ORM\Mapping;
2011-12-22 18:07:18 +04:00
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
use Doctrine\ORM\Mapping\NamingStrategy;
2011-12-22 18:07:18 +04:00
require_once __DIR__ . '/../../TestInit.php';
2011-12-22 18:07:18 +04:00
/**
* @group DDC-559
*/
class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
{
2011-12-22 20:07:58 +04:00
/**
* @return DefaultNamingStrategy
*/
static private function defaultNaming()
2011-12-22 18:07:18 +04:00
{
2011-12-23 18:16:36 +04:00
return new DefaultNamingStrategy();
}
/**
* @return UnderscoreNamingStrategy
*/
static private function underscoreNamingLower()
{
2011-12-24 17:45:51 +04:00
return new UnderscoreNamingStrategy(CASE_LOWER);
2011-12-23 18:16:36 +04:00
}
/**
* @return UnderscoreNamingStrategy
*/
static private function underscoreNamingUpper()
{
2011-12-24 17:45:51 +04:00
return new UnderscoreNamingStrategy(CASE_UPPER);
2011-12-22 20:07:58 +04:00
}
/**
* Data Provider for NamingStrategy#classToTableName
*
* @return array
*/
static public function dataClassToTableName()
{
return array(
2011-12-23 18:16:36 +04:00
// DefaultNamingStrategy
2011-12-22 20:07:58 +04:00
array(self::defaultNaming(), 'SomeClassName',
'SomeClassName'
),
2011-12-23 17:03:28 +04:00
array(self::defaultNaming(), 'SomeClassName',
'\SomeClassName'
2011-12-22 20:07:58 +04:00
),
2011-12-23 17:03:28 +04:00
array(self::defaultNaming(), 'Name',
'\Some\Class\Name'
2011-12-22 20:07:58 +04:00
),
2011-12-23 18:16:36 +04:00
// UnderscoreNamingStrategy
array(self::underscoreNamingLower(), 'some_class_name',
'\Name\Space\SomeClassName'
),
array(self::underscoreNamingLower(), 'name',
'\Some\Class\Name'
),
array(self::underscoreNamingUpper(), 'SOME_CLASS_NAME',
'\Name\Space\SomeClassName'
),
array(self::underscoreNamingUpper(), 'NAME',
'\Some\Class\Name'
),
2011-12-22 20:07:58 +04:00
);
}
/**
* @dataProvider dataClassToTableName
*/
2011-12-23 17:03:28 +04:00
public function testClassToTableName(NamingStrategy $strategy, $expected, $className)
2011-12-22 20:07:58 +04:00
{
$this->assertEquals($expected, $strategy->classToTableName($className));
}
/**
* Data Provider for NamingStrategy#propertyToColumnName
*
* @return array
*/
static public function dataPropertyToColumnName()
{
return array(
2011-12-23 18:16:36 +04:00
// DefaultNamingStrategy
2011-12-22 20:07:58 +04:00
array(self::defaultNaming(), 'someProperty',
'someProperty'
),
array(self::defaultNaming(), 'SOME_PROPERTY',
'SOME_PROPERTY'
),
array(self::defaultNaming(), 'some_property',
'some_property'
),
2011-12-23 18:16:36 +04:00
// UnderscoreNamingStrategy
array(self::underscoreNamingLower(), 'some_property',
'someProperty'
),
array(self::underscoreNamingUpper(), 'SOME_PROPERTY',
'someProperty'
),
array(self::underscoreNamingUpper(), 'SOME_PROPERTY',
'some_property'
),
array(self::underscoreNamingUpper(), 'SOME_PROPERTY',
'SOME_PROPERTY'
),
2011-12-22 20:07:58 +04:00
);
}
/**
* @dataProvider dataPropertyToColumnName
*
2011-12-24 17:45:51 +04:00
* @param NamingStrategy $strategy
* @param string $expected
* @param string $propertyName
2011-12-22 20:07:58 +04:00
*/
public function testPropertyToColumnName(NamingStrategy $strategy, $expected, $propertyName)
{
$this->assertEquals($expected, $strategy->propertyToColumnName($propertyName));
}
/**
2011-12-23 17:03:28 +04:00
* Data Provider for NamingStrategy#referenceColumnName
2011-12-22 20:07:58 +04:00
*
* @return array
*/
2011-12-23 17:03:28 +04:00
static public function dataReferenceColumnName()
2011-12-22 20:07:58 +04:00
{
return array(
2011-12-23 18:16:36 +04:00
// DefaultNamingStrategy
2011-12-23 17:03:28 +04:00
array(self::defaultNaming(), 'id'),
2011-12-23 18:16:36 +04:00
// UnderscoreNamingStrategy
array(self::underscoreNamingLower(), 'id'),
array(self::underscoreNamingUpper(), 'ID'),
2011-12-22 20:07:58 +04:00
);
}
2011-12-23 17:03:28 +04:00
2011-12-22 20:07:58 +04:00
/**
2011-12-23 17:03:28 +04:00
* @dataProvider dataReferenceColumnName
*
2011-12-24 17:45:51 +04:00
* @param NamingStrategy $strategy
* @param string $expected
2011-12-22 20:07:58 +04:00
*/
2011-12-23 17:03:28 +04:00
public function testReferenceColumnName(NamingStrategy $strategy, $expected)
2011-12-22 20:07:58 +04:00
{
2011-12-23 17:03:28 +04:00
$this->assertEquals($expected, $strategy->referenceColumnName());
2011-12-22 20:07:58 +04:00
}
/**
2011-12-23 17:03:28 +04:00
* Data Provider for NamingStrategy#joinColumnName
2011-12-22 20:07:58 +04:00
*
* @return array
*/
2011-12-23 17:03:28 +04:00
static public function dataJoinColumnName()
2011-12-22 20:07:58 +04:00
{
return array(
2011-12-23 18:16:36 +04:00
// DefaultNamingStrategy
2011-12-23 17:03:28 +04:00
array(self::defaultNaming(), 'someColumn_id',
'someColumn', null,
2011-12-22 20:07:58 +04:00
),
2011-12-23 17:03:28 +04:00
array(self::defaultNaming(), 'some_column_id',
'some_column', null,
2011-12-22 20:07:58 +04:00
),
2011-12-23 18:16:36 +04:00
// UnderscoreNamingStrategy
array(self::underscoreNamingLower(), 'some_column_id',
'someColumn', null,
),
array(self::underscoreNamingUpper(), 'SOME_COLUMN_ID',
'someColumn', null,
),
2011-12-22 20:07:58 +04:00
);
}
2011-12-23 17:03:28 +04:00
2011-12-22 20:07:58 +04:00
/**
2011-12-23 17:03:28 +04:00
* @dataProvider dataJoinColumnName
*
2011-12-24 17:45:51 +04:00
* @param NamingStrategy $strategy
* @param string $expected
* @param string $propertyName
2011-12-22 20:07:58 +04:00
*/
2011-12-23 17:03:28 +04:00
public function testJoinColumnName(NamingStrategy $strategy, $expected, $propertyName)
2011-12-22 20:07:58 +04:00
{
2011-12-23 17:03:28 +04:00
$this->assertEquals($expected, $strategy->joinColumnName($propertyName));
2011-12-22 20:07:58 +04:00
}
/**
2011-12-23 17:03:28 +04:00
* Data Provider for NamingStrategy#joinTableName
2011-12-22 20:07:58 +04:00
*
* @return array
*/
2011-12-23 17:03:28 +04:00
static public function dataJoinTableName()
2011-12-22 20:07:58 +04:00
{
return array(
2011-12-23 18:16:36 +04:00
// DefaultNamingStrategy
2011-12-23 17:03:28 +04:00
array(self::defaultNaming(), 'someclassname_classname',
'SomeClassName', 'Some\ClassName', null,
2011-12-22 20:07:58 +04:00
),
2011-12-23 17:03:28 +04:00
array(self::defaultNaming(), 'someclassname_classname',
'\SomeClassName', 'ClassName', null,
2011-12-22 20:07:58 +04:00
),
2011-12-23 17:03:28 +04:00
array(self::defaultNaming(), 'name_classname',
'\Some\Class\Name', 'ClassName', null,
2011-12-22 20:07:58 +04:00
),
2011-12-23 18:16:36 +04:00
// UnderscoreNamingStrategy
array(self::underscoreNamingLower(), 'some_class_name_class_name',
'SomeClassName', 'Some\ClassName', null,
),
array(self::underscoreNamingLower(), 'some_class_name_class_name',
'\SomeClassName', 'ClassName', null,
),
array(self::underscoreNamingLower(), 'name_class_name',
'\Some\Class\Name', 'ClassName', null,
),
array(self::underscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME',
'SomeClassName', 'Some\ClassName', null,
),
array(self::underscoreNamingUpper(), 'SOME_CLASS_NAME_CLASS_NAME',
'\SomeClassName', 'ClassName', null,
),
array(self::underscoreNamingUpper(), 'NAME_CLASS_NAME',
'\Some\Class\Name', 'ClassName', null,
),
2011-12-22 20:07:58 +04:00
);
}
/**
2011-12-23 17:03:28 +04:00
* @dataProvider dataJoinTableName
2011-12-22 20:07:58 +04:00
*
2011-12-24 17:45:51 +04:00
* @param NamingStrategy $strategy
* @param string $expected
* @param string $ownerEntity
* @param string $associatedEntity
* @param string $propertyName
2011-12-22 20:07:58 +04:00
*/
2011-12-23 17:03:28 +04:00
public function testJoinTableName(NamingStrategy $strategy, $expected, $ownerEntity, $associatedEntity, $propertyName = null)
2011-12-22 20:07:58 +04:00
{
2011-12-23 17:03:28 +04:00
$this->assertEquals($expected, $strategy->joinTableName($ownerEntity, $associatedEntity, $propertyName));
2011-12-22 20:07:58 +04:00
}
/**
* Data Provider for NamingStrategy#joinKeyColumnName
*
* @return array
*/
static public function dataJoinKeyColumnName()
{
return array(
2011-12-23 18:16:36 +04:00
// DefaultNamingStrategy
2011-12-23 17:03:28 +04:00
array(self::defaultNaming(), 'someclassname_id',
'SomeClassName', null, null,
2011-12-22 20:07:58 +04:00
),
2011-12-23 17:03:28 +04:00
array(self::defaultNaming(), 'name_identifier',
'\Some\Class\Name', 'identifier', null,
2011-12-22 20:07:58 +04:00
),
2011-12-23 18:16:36 +04:00
// UnderscoreNamingStrategy
array(self::underscoreNamingLower(), 'some_class_name_id',
'SomeClassName', null, null,
),
array(self::underscoreNamingLower(), 'class_name_identifier',
'\Some\Class\ClassName', 'identifier', null,
),
array(self::underscoreNamingUpper(), 'SOME_CLASS_NAME_ID',
'SomeClassName', null, null,
),
array(self::underscoreNamingUpper(), 'CLASS_NAME_IDENTIFIER',
'\Some\Class\ClassName', 'IDENTIFIER', null,
),
2011-12-22 20:07:58 +04:00
);
}
/**
* @dataProvider dataJoinKeyColumnName
*
2011-12-24 17:45:51 +04:00
* @param NamingStrategy $strategy
* @param string $expected
* @param string $propertyEntityName
* @param string $referencedColumnName
* @param string $propertyName
2011-12-22 20:07:58 +04:00
*/
2011-12-23 17:03:28 +04:00
public function testJoinKeyColumnName(NamingStrategy $strategy, $expected, $propertyEntityName, $referencedColumnName = null, $propertyName = null)
2011-12-22 20:07:58 +04:00
{
2011-12-23 17:03:28 +04:00
$this->assertEquals($expected, $strategy->joinKeyColumnName($propertyEntityName, $referencedColumnName, $propertyName));
2011-12-22 20:07:58 +04:00
}
2011-12-22 18:07:18 +04:00
}