This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace TextFile\Tests\Reader; |
||
4 | |||
5 | use TextFile\Reader\SimpleReader; |
||
6 | use TextFile\Tests\TextFileTestCase; |
||
7 | use TextFile\Walker\SimpleWalker; |
||
8 | |||
9 | /** |
||
10 | * Class SimpleReaderTest |
||
11 | * |
||
12 | * @package TextFile\Tests\Reader |
||
13 | */ |
||
14 | class SimpleReaderTest extends TextFileTestCase |
||
15 | { |
||
16 | /** |
||
17 | * @covers TextFile\Reader\SimpleReader::getLinesRange |
||
18 | */ |
||
19 | public function testGetLinesRange() |
||
20 | { |
||
21 | $reader = new SimpleReader(new SimpleWalker()); |
||
22 | |||
23 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
24 | $file = new \SplFileObject($filePath, 'r+'); |
||
25 | $range = $reader->getLinesRange($file, 0, 2); |
||
26 | |||
27 | $this->assertInstanceOf('\LimitIterator', $range); |
||
28 | |||
29 | $this->assertCount(2, $range); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @covers TextFile\Reader\SimpleReader::getLinesRange |
||
34 | * |
||
35 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
36 | */ |
||
37 | View Code Duplication | public function testGetLinesRangeOutOfBoundsTooLow() |
|
0 ignored issues
–
show
|
|||
38 | { |
||
39 | $reader = new SimpleReader(new SimpleWalker()); |
||
40 | |||
41 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
42 | $file = new \SplFileObject($filePath, 'r+'); |
||
43 | |||
44 | $reader->getLinesRange($file, -1, 2); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @covers TextFile\Reader\SimpleReader::getLinesRange |
||
49 | * |
||
50 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
51 | */ |
||
52 | View Code Duplication | public function testGetLinesRangeOutOfBoundsTooHigh() |
|
0 ignored issues
–
show
This method 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. ![]() |
|||
53 | { |
||
54 | $reader = new SimpleReader(new SimpleWalker()); |
||
55 | |||
56 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
57 | $file = new \SplFileObject($filePath, 'r+'); |
||
58 | |||
59 | $reader->getLinesRange($file, 0, 20); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @covers TextFile\Reader\SimpleReader::getNextLineContent |
||
64 | */ |
||
65 | public function testGetNextLineContentFromStart() |
||
66 | { |
||
67 | $reader = new SimpleReader(new SimpleWalker()); |
||
68 | |||
69 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
70 | $file = new \SplFileObject($filePath, 'r+'); |
||
71 | |||
72 | $this->assertEquals('second', $reader->getNextLineContent($file)); |
||
73 | |||
74 | // Test if pointer is correctly reset |
||
75 | |||
76 | $this->assertEquals('second', $reader->getNextLineContent($file)); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @covers TextFile\Reader\SimpleReader::getNextLineContent |
||
81 | */ |
||
82 | public function testGetNextLineContent() |
||
83 | { |
||
84 | $reader = new SimpleReader(new SimpleWalker()); |
||
85 | |||
86 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
87 | $file = new \SplFileObject($filePath, 'r+'); |
||
88 | |||
89 | $file->seek(2); |
||
90 | |||
91 | $this->assertEquals('fourth', $reader->getNextLineContent($file)); |
||
92 | |||
93 | // Test if pointer is correctly reset |
||
94 | |||
95 | $this->assertEquals('fourth', $reader->getNextLineContent($file)); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @covers TextFile\Reader\SimpleReader::getNextLineContent |
||
100 | * |
||
101 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
102 | */ |
||
103 | View Code Duplication | public function testGetNextLineContentOutOfBounds() |
|
0 ignored issues
–
show
This method 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. ![]() |
|||
104 | { |
||
105 | $reader = new SimpleReader(new SimpleWalker()); |
||
106 | |||
107 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
108 | $file = new \SplFileObject($filePath, 'r+'); |
||
109 | |||
110 | $file->seek(5); |
||
111 | |||
112 | $reader->getNextLineContent($file); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @covers TextFile\Reader\SimpleReader::getPreviousLineContent |
||
117 | */ |
||
118 | public function testGetPreviousLineContent() |
||
119 | { |
||
120 | $reader = new SimpleReader(new SimpleWalker()); |
||
121 | |||
122 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
123 | $file = new \SplFileObject($filePath, 'r+'); |
||
124 | |||
125 | $file->seek(2); |
||
126 | |||
127 | $this->assertEquals('second', $reader->getPreviousLineContent($file)); |
||
128 | |||
129 | // Test if pointer is correctly reset |
||
130 | |||
131 | $this->assertEquals('second', $reader->getPreviousLineContent($file)); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @covers TextFile\Reader\SimpleReader::getPreviousLineContent |
||
136 | * |
||
137 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
138 | */ |
||
139 | View Code Duplication | public function testGetPreviousLineContentOutOfBounds() |
|
0 ignored issues
–
show
This method 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. ![]() |
|||
140 | { |
||
141 | $reader = new SimpleReader(new SimpleWalker()); |
||
142 | |||
143 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
144 | $file = new \SplFileObject($filePath, 'r+'); |
||
145 | |||
146 | $file->seek(0); |
||
147 | |||
148 | $reader->getPreviousLineContent($file); |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @covers TextFile\Reader\SimpleReader::getCurrentLineContent |
||
153 | */ |
||
154 | public function testGetCurrentLineContent() |
||
155 | { |
||
156 | $reader = new SimpleReader(new SimpleWalker()); |
||
157 | |||
158 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
159 | $file = new \SplFileObject($filePath, 'r+'); |
||
160 | |||
161 | $file->seek(2); |
||
162 | |||
163 | $this->assertEquals('third', $reader->getCurrentLineContent($file)); |
||
164 | |||
165 | // Test if pointer is correctly reset |
||
166 | |||
167 | $this->assertEquals('third', $reader->getCurrentLineContent($file)); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * @covers TextFile\Reader\SimpleReader::getLineContent |
||
172 | */ |
||
173 | public function testGetLineContent() |
||
174 | { |
||
175 | $reader = new SimpleReader(new SimpleWalker()); |
||
176 | |||
177 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
178 | $file = new \SplFileObject($filePath, 'r+'); |
||
179 | |||
180 | $this->assertEquals('third', $reader->getLineContent($file, 2)); |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * @covers TextFile\Reader\SimpleReader::getLineContent |
||
185 | * |
||
186 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
187 | */ |
||
188 | public function testGetLineContentOutOfBoundsTooHigh() |
||
189 | { |
||
190 | $reader = new SimpleReader(new SimpleWalker()); |
||
191 | |||
192 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
193 | $file = new \SplFileObject($filePath, 'r+'); |
||
194 | |||
195 | $this->assertEquals('third', $reader->getLineContent($file, 9)); |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * @covers TextFile\Reader\SimpleReader::getLineContent |
||
200 | * |
||
201 | * @expectedException \TextFile\Exception\OutOfBoundsException |
||
202 | */ |
||
203 | public function testGetLineContentOutOfBoundsTooLow() |
||
204 | { |
||
205 | $reader = new SimpleReader(new SimpleWalker()); |
||
206 | |||
207 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
208 | $file = new \SplFileObject($filePath, 'r+'); |
||
209 | |||
210 | $this->assertEquals('third', $reader->getLineContent($file, -1)); |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * @covers TextFile\Reader\SimpleReader::getNextCharacterContent |
||
215 | */ |
||
216 | public function testGetNextCharacterContent() |
||
217 | { |
||
218 | $reader = new SimpleReader(new SimpleWalker()); |
||
219 | |||
220 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
221 | $file = new \SplFileObject($filePath, 'r+'); |
||
222 | |||
223 | $file->fseek(2); |
||
224 | |||
225 | $this->assertEquals('r', $reader->getNextCharacterContent($file)); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * @covers TextFile\Reader\SimpleReader::getPreviousCharacterContent |
||
230 | */ |
||
231 | public function testGetPreviousCharacterContent() |
||
232 | { |
||
233 | $reader = new SimpleReader(new SimpleWalker()); |
||
234 | |||
235 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
236 | $file = new \SplFileObject($filePath, 'r+'); |
||
237 | |||
238 | $file->fseek(2); |
||
239 | |||
240 | $this->assertEquals('i', $reader->getPreviousCharacterContent($file)); |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * @covers TextFile\Reader\SimpleReader::getCharacterContent |
||
245 | */ |
||
246 | public function testGetCharacterContent() |
||
247 | { |
||
248 | $reader = new SimpleReader(new SimpleWalker()); |
||
249 | |||
250 | $filePath = $this->createTestFileFromFixtures('complex_multiline_file.txt'); |
||
251 | $file = new \SplFileObject($filePath, 'r+'); |
||
252 | |||
253 | $this->assertEquals('r', $reader->getCharacterContent($file, 2)); |
||
254 | } |
||
255 | |||
256 | /** |
||
257 | * @covers TextFile\Reader\SimpleReader::cleanLineContent |
||
258 | */ |
||
259 | public function testCleanLineContent() |
||
260 | { |
||
261 | $reader = new SimpleReader(new SimpleWalker()); |
||
262 | |||
263 | $this->assertEmpty($reader->cleanLineContent(PHP_EOL)); |
||
264 | } |
||
265 | } |
||
266 |
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.