Completed
Push — master ( 28b764...a7b092 )
by Michaël
02:42
created

ErasingWriterTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 82
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testWriteBeginning() 13 13 1
A testWriteMiddle() 15 15 1
A testWriteMiddleNewLine() 19 19 1
A testWriteBeginningNewLine() 17 17 1

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
namespace TextFile\Tests\Writer;
4
5
use TextFile\Tests\TextFileTestCase;
6
use TextFile\Writer\ErasingWriter;
7
8
/**
9
 * Class ErasingWriterTest
10
 *
11
 * @package TextFile\Tests\Writer
12
 */
13 View Code Duplication
class ErasingWriterTest extends TextFileTestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * @covers TextFile\Writer\ErasingWriter::write
17
     */
18
    public function testWriteBeginning()
19
    {
20
        $erasingWriter = new ErasingWriter();
21
22
        $filePath = $this->createTestFileFromFixtures('complex_singleline_file.txt');
23
        $file     = new \SplFileObject($filePath, 'r+');
24
25
        $erasingWriter->write($file, 'test');
26
27
        $file->rewind();
28
29
        $this->assertEquals('testtsecondthirdfourthfifth', trim($file->current()));
30
    }
31
32
    /**
33
     * @covers TextFile\Writer\ErasingWriter::write
34
     */
35
    public function testWriteMiddle()
36
    {
37
        $erasingWriter = new ErasingWriter();
38
39
        $filePath = $this->createTestFileFromFixtures('complex_singleline_file.txt');
40
        $file     = new \SplFileObject($filePath, 'r+');
41
42
        $file->fseek(5);
43
44
        $erasingWriter->write($file, 'test');
45
46
        $file->rewind();
47
48
        $this->assertEquals('firsttestndthirdfourthfifth', trim($file->current()));
49
    }
50
51
    /**
52
     * @covers TextFile\Writer\ErasingWriter::write
53
     */
54
    public function testWriteMiddleNewLine()
55
    {
56
        $erasingWriter = new ErasingWriter();
57
58
        $filePath = $this->createTestFileFromFixtures('complex_singleline_file.txt');
59
        $file     = new \SplFileObject($filePath, 'r+');
60
61
        $file->fseek(5);
62
63
        $erasingWriter->write($file, 'test', true);
64
65
        $file->rewind();
66
67
        $this->assertEquals('firsttest', trim($file->current()));
68
69
        $file->next();
70
71
        $this->assertEquals('dthirdfourthfifth', trim($file->current()));
72
    }
73
74
    /**
75
     * @covers TextFile\Writer\ErasingWriter::write
76
     */
77
    public function testWriteBeginningNewLine()
78
    {
79
        $erasingWriter = new ErasingWriter();
80
81
        $filePath = $this->createTestFileFromFixtures('complex_singleline_file.txt');
82
        $file     = new \SplFileObject($filePath, 'r+');
83
84
        $erasingWriter->write($file, 'test', true);
85
86
        $file->rewind();
87
88
        $this->assertEquals('test', trim($file->current()));
89
90
        $file->next();
91
92
        $this->assertEquals('secondthirdfourthfifth', trim($file->current()));
93
    }
94
}
95