StringUtilTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 17
c 1
b 0
f 1
dl 0
loc 33
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetClassBaseName() 0 7 1
A testHumanize() 0 13 1
A testGetLabelFromClass() 0 7 1
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
}