|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Xiidea\EasyConfigBundle\Tests\Utility; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Xiidea\EasyConfigBundle\Model\BaseConfig; |
|
7
|
|
|
use Xiidea\EasyConfigBundle\Utility\StringUtil; |
|
8
|
|
|
|
|
9
|
|
|
class StringUtilTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testGetLabelFromClass() |
|
12
|
|
|
{ |
|
13
|
|
|
$label = StringUtil::getLabelFromClass('App\\Entities\\UserEntity'); |
|
14
|
|
|
$this->assertEquals('User entity', $label); |
|
15
|
|
|
|
|
16
|
|
|
$labelFromObject = StringUtil::getLabelFromClass(new BaseConfig('config.test.item')); |
|
17
|
|
|
$this->assertEquals('Base config', $labelFromObject); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function testHumanize() |
|
21
|
|
|
{ |
|
22
|
|
|
$text = StringUtil::humanize('getUserInfo'); |
|
23
|
|
|
$this->assertEquals('get user info', $text); |
|
24
|
|
|
|
|
25
|
|
|
$textCamel = StringUtil::humanize('UserInfoData'); |
|
26
|
|
|
$this->assertEquals('user info data', $textCamel); |
|
27
|
|
|
|
|
28
|
|
|
$textReplace = StringUtil::humanize('dont'); |
|
29
|
|
|
$this->assertEquals("don't", $textReplace); |
|
30
|
|
|
|
|
31
|
|
|
$textReplace = StringUtil::humanize('this_is_new'); |
|
32
|
|
|
$this->assertEquals("this is new", $textReplace); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testGetClassBaseName() |
|
36
|
|
|
{ |
|
37
|
|
|
$baseName = StringUtil::getClassBaseName('App\\Entities\\UserEntity'); |
|
38
|
|
|
$this->assertEquals('UserEntity', $baseName); |
|
39
|
|
|
|
|
40
|
|
|
$baseNameFromObject = StringUtil::getClassBaseName(new \DateTime()); |
|
41
|
|
|
$this->assertEquals('DateTime', $baseNameFromObject); |
|
42
|
|
|
} |
|
43
|
|
|
} |