1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheCodingMachine\TDBM\Utils; |
4
|
|
|
|
5
|
|
|
class DefaultNamingStrategyTest extends \PHPUnit_Framework_TestCase |
6
|
|
|
{ |
7
|
|
|
public function testGetBeanName() |
8
|
|
|
{ |
9
|
|
|
$strategy = new DefaultNamingStrategy(); |
10
|
|
|
$strategy->setBeanPrefix(''); |
11
|
|
|
$strategy->setBeanSuffix('Bean'); |
12
|
|
|
|
13
|
|
|
$this->assertSame('UserBean', $strategy->getBeanClassName("users")); |
14
|
|
|
$this->assertSame('UserBean', $strategy->getBeanClassName("user")); |
15
|
|
|
$this->assertSame('UserCountryBean', $strategy->getBeanClassName("users_countries")); |
16
|
|
|
$this->assertSame('UserCountryBean', $strategy->getBeanClassName("users countries")); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testGetBaseBeanName() |
20
|
|
|
{ |
21
|
|
|
$strategy = new DefaultNamingStrategy(); |
22
|
|
|
$strategy->setBaseBeanPrefix(''); |
23
|
|
|
$strategy->setBaseBeanSuffix('BaseBean'); |
24
|
|
|
$this->assertSame('UserBaseBean', $strategy->getBaseBeanClassName("users")); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
View Code Duplication |
public function testGetDaoName() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$strategy = new DefaultNamingStrategy(); |
30
|
|
|
$strategy->setDaoPrefix(''); |
31
|
|
|
$strategy->setDaoSuffix('Dao'); |
32
|
|
|
$this->assertSame('UserDao', $strategy->getDaoClassName("users")); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetBaseDaoName() |
36
|
|
|
{ |
37
|
|
|
$strategy = new DefaultNamingStrategy(); |
38
|
|
|
$strategy->setBaseDaoPrefix(''); |
39
|
|
|
$strategy->setBaseDaoSuffix('BaseDao'); |
40
|
|
|
$this->assertSame('UserBaseDao', $strategy->getBaseDaoClassName("users")); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetBeanNameDefault() |
44
|
|
|
{ |
45
|
|
|
$strategy = new DefaultNamingStrategy(); |
46
|
|
|
|
47
|
|
|
$this->assertSame('User', $strategy->getBeanClassName("users")); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testGetBaseBeanNameDefault() |
51
|
|
|
{ |
52
|
|
|
$strategy = new DefaultNamingStrategy(); |
53
|
|
|
$this->assertSame('AbstractUser', $strategy->getBaseBeanClassName("users")); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testGetDaoNameDefault() |
57
|
|
|
{ |
58
|
|
|
$strategy = new DefaultNamingStrategy(); |
59
|
|
|
$this->assertSame('UserDao', $strategy->getDaoClassName("users")); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testGetBaseDaoNameDefault() |
63
|
|
|
{ |
64
|
|
|
$strategy = new DefaultNamingStrategy(); |
65
|
|
|
$this->assertSame('AbstractUserDao', $strategy->getBaseDaoClassName("users")); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testGetDaoFactory() |
69
|
|
|
{ |
70
|
|
|
$strategy = new DefaultNamingStrategy(); |
71
|
|
|
$this->assertSame('DaoFactory', $strategy->getDaoFactoryClassName()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testExceptions() |
75
|
|
|
{ |
76
|
|
|
$strategy = new DefaultNamingStrategy(); |
77
|
|
|
$strategy->setExceptions([ |
78
|
|
|
'chevaux' => 'Cheval' |
79
|
|
|
]); |
80
|
|
|
$this->assertSame('ChevalDao', $strategy->getDaoClassName('chevaux')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
View Code Duplication |
public function testUppercaseNames() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$strategy = new DefaultNamingStrategy(); |
86
|
|
|
$strategy->setDaoPrefix(''); |
87
|
|
|
$strategy->setDaoSuffix('Dao'); |
88
|
|
|
$this->assertSame('UserDao', $strategy->getDaoClassName("USERS")); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.