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