Passed
Push — master ( b34030...56c38f )
by Sebastian
03:50
created

CommitMessageTest::testGetLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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\Git;
11
12
class CommitMessageTest extends \PHPUnit_Framework_TestCase
13
{
14
    /**
15
     * Tests CommitMessage::isEmpty
16
     */
17
    public function testIsEmpty()
18
    {
19
        $msg = new CommitMessage('');
20
        $this->assertTrue($msg->isEmpty());
21
    }
22
23
    public function testGetContent()
24
    {
25
        $content = 'Foo' . PHP_EOL . 'Bar' . PHP_EOL . 'Baz';
26
        $msg = new CommitMessage($content);
27
        $this->assertEquals($content, $msg->getContent());
28
    }
29
30
    /**
31
     * Tests CommitMessage::getLines
32
     */
33
    public function testGetLines()
34
    {
35
        $msg   = new CommitMessage('Foo' . PHP_EOL . 'Bar' . PHP_EOL . 'Baz');
36
        $lines = $msg->getLines();
37
        $this->assertTrue(is_array($lines));
38
        $this->assertEquals(3, count($lines));
39
    }
40
41
    /**
42
     * Tests CommitMessage::getLineCount
43
     */
44
    public function testLineCodeOnEmptyMessage()
45
    {
46
        $msg = new CommitMessage('');
47
        $this->assertEquals(0, $msg->getLineCount());
48
    }
49
50
    /**
51
     * Tests CommitMessage::getLineCount
52
     */
53
    public function testLineCount()
54
    {
55
        $msg = new CommitMessage('Foo' . PHP_EOL . 'Bar' . PHP_EOL . 'Baz');
56
        $this->assertEquals(3, $msg->getLineCount());
57
    }
58
59
    /**
60
     * Tests CommitMessage::getSubject
61
     */
62
    public function testGetSubject()
63
    {
64
        $msg = new CommitMessage('Foo' . PHP_EOL . 'Bar' . PHP_EOL . 'Baz');
65
        $this->assertEquals('Foo', $msg->getSubject());
66
    }
67
68
    /**
69
     * Tests CommitMessage::getBody
70
     */
71
    public function testGetBody()
72
    {
73
        $msg = new CommitMessage('Foo' . PHP_EOL . PHP_EOL . 'Bar' . PHP_EOL . 'Baz');
74
        $this->assertEquals('Bar' . PHP_EOL . 'Baz', $msg->getBody());
75
    }
76
77
    /**
78
     * Tests CommitMessage::getBodyLines
79
     */
80
    public function testGetBodyLines()
81
    {
82
        $msg   = new CommitMessage('Foo' . PHP_EOL . PHP_EOL . 'Bar' . PHP_EOL . 'Baz');
83
        $lines = $msg->getBodyLines();
84
        $this->assertEquals(2, count($lines));
85
        $this->assertEquals('Bar', $lines[0]);
86
        $this->assertEquals('Baz', $lines[1]);
87
    }
88
89
    /**
90
     * Tests CommitMessage::getLine
91
     */
92
    public function testGetLine()
93
    {
94
        $msg = new CommitMessage('Foo' . PHP_EOL . 'Bar' . PHP_EOL . 'Baz');
95
        $this->assertEquals('Foo', $msg->getLine(0));
96
        $this->assertEquals('Bar', $msg->getLine(1));
97
        $this->assertEquals('Baz', $msg->getLine(2));
98
    }
99
100
    /**
101
     * Tests CommitMessage::createFromFile
102
     *
103
     * @expectedException \Exception
104
     */
105
    public function testCreateFromFile()
106
    {
107
        CommitMessage::createFromFile('iDoNotExist.txt');
108
    }
109
}
110