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

ErasingWriterTest::testWriteBeginningNewLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 17
loc 17
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
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