Passed
Push — master ( 21c505...12ca40 )
by Sebastian
02:34
created

ValidatorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 44.64 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 25
loc 56
c 0
b 0
f 0
rs 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace sebastianfeldmann\CaptainHook\Hook\Message;
11
12
use sebastianfeldmann\CaptainHook\Git\CommitMessage;
13
use sebastianfeldmann\CaptainHook\Hook\Message\Validator\Rule\CapitalizeSubject;
14
use sebastianfeldmann\CaptainHook\Hook\Message\Validator\Rule\MsgNotEmpty;
15
16
class ValidatorTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * Tests Validator::validate
20
     */
21
    public function testValidOnEmptyRuleList()
22
    {
23
        $msg = new CommitMessage('Foo');
24
        $v   = new Validator();
25
26
        $v->validate($msg);
27
        $this->assertTrue(true);
28
29
    }
30
31
    /**
32
     * Tests Validator::setRules
33
     */
34
    public function testSetRulesValid()
35
    {
36
        $msg = new CommitMessage('Foo');
37
        $v   = new Validator();
38
        $v->setRules([new MsgNotEmpty()]);
39
40
        $v->validate($msg);
41
        $this->assertTrue(true);
42
    }
43
44
    /**
45
     * Tests Validator::setRules
46
     *
47
     * @expectedException \Exception
48
     */
49
    public function testSetRulesInvalid()
50
    {
51
        $msg = new CommitMessage('');
52
        $v   = new Validator();
53
        $v->setRules([new MsgNotEmpty()]);
54
        $v->validate($msg);
55
    }
56
57
    /**
58
     * Tests Validator::setRules
59
     *
60
     * @expectedException \Exception
61
     */
62
    public function testAddRuleInvalid()
63
    {
64
        $msg = new CommitMessage('foo bar baz');
65
        $v   = new Validator();
66
        $v->setRules([new MsgNotEmpty()]);
67
        $v->addRule(new CapitalizeSubject());
68
69
        $v->validate($msg);
70
    }
71
}
72