ShorthandTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 102
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testCanGenerateShorthands() 0 7 1
A testThrowsExceptionForEmptyWords() 0 5 1
B shorthandsProvider() 0 60 1
1
<?php
2
3
namespace KamranAhmed\Shorthand;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * Class ShorthandTest
9
 *
10
 * @package KamranAhmed\Shorthand
11
 */
12
class ShorthandTest extends TestCase
13
{
14
    /**
15
     * @var Shorthand
16
     */
17
    protected $shorthand;
18
19
    protected function setUp()
20
    {
21
        parent::setUp();
22
23
        $this->shorthand = new Shorthand();
24
    }
25
26
    /**
27
     * @dataProvider shorthandsProvider
28
     *
29
     * @param $words
30
     * @param $expectedShorthands
31
     */
32
    public function testCanGenerateShorthands($words, $expectedShorthands)
33
    {
34
        $this->shorthand->setWords($words);
35
        $shorthands = $this->shorthand->generate();
36
37
        $this->assertEquals($expectedShorthands, $shorthands);
38
    }
39
40
    /**
41
     * @expectedException        \Exception
42
     * @expectedExceptionMessage Word(s) are required to generate shorthands
43
     */
44
    public function testThrowsExceptionForEmptyWords()
45
    {
46
        $this->shorthand->setWords([]);
47
        $this->shorthand->generate();
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function shorthandsProvider()
54
    {
55
        return [
56
            [
57
                ['create', 'crore'],
58
                [
59
                    'cre'    => 'create',
60
                    'crea'   => 'create',
61
                    'creat'  => 'create',
62
                    'create' => 'create',
63
                    'cro'    => 'crore',
64
                    'cror'   => 'crore',
65
                    'crore'  => 'crore',
66
                ],
67
            ],
68
            [
69
                ['crore', 'create', 'crop'],
70
                [
71
                    'cror'   => 'crore',
72
                    'crore'  => 'crore',
73
                    'cre'    => 'create',
74
                    'crea'   => 'create',
75
                    'creat'  => 'create',
76
                    'create' => 'create',
77
                    'crop'   => 'crop',
78
                ],
79
            ],
80
            [
81
                ['create', 'crore', 'create', 'crore'],
82
                [
83
                    'cre'    => 'create',
84
                    'crea'   => 'create',
85
                    'creat'  => 'create',
86
                    'create' => 'create',
87
                    'cro'    => 'crore',
88
                    'cror'   => 'crore',
89
                    'crore'  => 'crore',
90
                ],
91
            ],
92
            [
93
                ['ruby', 'rules'],
94
                [
95
                    'rub'   => 'ruby',
96
                    'ruby'  => 'ruby',
97
                    'rul'   => 'rules',
98
                    'rule'  => 'rules',
99
                    'rules' => 'rules',
100
                ],
101
            ],
102
            [
103
                'ruby',
104
                [
105
                    'r'    => 'ruby',
106
                    'ru'   => 'ruby',
107
                    'rub'  => 'ruby',
108
                    'ruby' => 'ruby',
109
                ],
110
            ],
111
        ];
112
    }
113
}
114