@@ -30,7 +30,7 @@ protected function setUp(): void
3030 #[Test]
3131 public function itReturnsEmptyArrayForEmptyDiff (): void
3232 {
33- self ::assertSame ([], $ this ->lineNumbersByFile ( $ this -> parser ->parse ('' )) );
33+ self ::assertSame ([], $ this ->parser ->parse ('' )-> fileChanges );
3434 }
3535
3636 #[Test]
@@ -47,10 +47,10 @@ public function itParsesAddedLineNumbers(): void
4747 line3
4848DIFF;
4949
50- $ result = $ this ->lineNumbersByFile ( $ this -> parser ->parse ($ diff ));
50+ $ change = $ this ->parser ->parse ($ diff )-> changeFor ( ' reference/file.xml ' );
5151
52- self ::assertArrayHasKey ( ' reference/file.xml ' , $ result );
53- self ::assertSame ([2 ], $ result [ ' reference/file.xml ' ] );
52+ self ::assertNotNull ( $ change );
53+ self ::assertSame ([2 ], $ change -> addedLineNumbers );
5454 }
5555
5656 #[Test]
@@ -68,9 +68,9 @@ public function itParsesMultipleAddedLines(): void
6868 last line
6969DIFF;
7070
71- $ result = $ this ->lineNumbersByFile ( $ this -> parser ->parse ($ diff) );
71+ $ result = $ this ->parser ->parse ($ diff );
7272
73- self ::assertSame ([6 , 7 ], $ result[ 'doc/chapter.xml ' ] );
73+ self ::assertSame ([6 , 7 ], $ result-> changeFor ( 'doc/chapter.xml ' )?->addedLineNumbers );
7474 }
7575
7676 #[Test]
@@ -85,10 +85,10 @@ public function itStripsTheBPrefix(): void
8585+added
8686DIFF;
8787
88- $ result = $ this ->lineNumbersByFile ( $ this -> parser ->parse ($ diff) );
88+ $ result = $ this ->parser ->parse ($ diff );
8989
90- self ::assertArrayHasKey ( ' src/file.xml ' , $ result );
91- self ::assertArrayNotHasKey ( ' b/ src/file.xml ' , $ result );
90+ self ::assertCount ( 1 , $ result-> fileChanges );
91+ self ::assertSame ( ' src/file.xml ' , $ result-> fileChanges [ 0 ]-> filePath );
9292 }
9393
9494 #[Test]
@@ -105,7 +105,7 @@ public function itExcludesDeletedFiles(): void
105105-line3
106106DIFF;
107107
108- self ::assertSame ([], $ this ->lineNumbersByFile ( $ this -> parser ->parse ($ diff )) );
108+ self ::assertSame ([], $ this ->parser ->parse ($ diff )-> fileChanges );
109109 }
110110
111111 #[Test]
@@ -122,10 +122,10 @@ public function itHandlesNewlyCreatedFiles(): void
122122+line3
123123DIFF;
124124
125- $ result = $ this ->lineNumbersByFile ( $ this -> parser ->parse ($ diff ));
125+ $ change = $ this ->parser ->parse ($ diff )-> changeFor ( ' new.xml ' );
126126
127- self ::assertArrayHasKey ( ' new.xml ' , $ result );
128- self ::assertSame ([1 , 2 , 3 ], $ result [ ' new.xml ' ] );
127+ self ::assertNotNull ( $ change );
128+ self ::assertSame ([1 , 2 , 3 ], $ change -> addedLineNumbers );
129129 }
130130
131131 #[Test]
@@ -148,12 +148,14 @@ public function itHandlesMultipleFilesInOneDiff(): void
148148 unchanged
149149DIFF;
150150
151- $ result = $ this ->lineNumbersByFile ($ this ->parser ->parse ($ diff ));
151+ $ result = $ this ->parser ->parse ($ diff );
152+ $ firstChange = $ result ->changeFor ('first.xml ' );
153+ $ secondChange = $ result ->changeFor ('second.xml ' );
152154
153- self ::assertArrayHasKey ( ' first.xml ' , $ result );
154- self ::assertArrayHasKey ( ' second.xml ' , $ result );
155- self ::assertSame ([2 ], $ result [ ' first.xml ' ] );
156- self ::assertSame ([2 ], $ result [ ' second.xml ' ] );
155+ self ::assertNotNull ( $ firstChange );
156+ self ::assertNotNull ( $ secondChange );
157+ self ::assertSame ([2 ], $ firstChange -> addedLineNumbers );
158+ self ::assertSame ([2 ], $ secondChange -> addedLineNumbers );
157159 }
158160
159161 #[Test]
@@ -170,11 +172,11 @@ public function itIgnoresRemovedLines(): void
170172 line3
171173DIFF;
172174
173- $ result = $ this ->lineNumbersByFile ( $ this -> parser ->parse ($ diff ));
175+ $ change = $ this ->parser ->parse ($ diff )-> changeFor ( ' file.xml ' );
174176
175177 // No lines added, so the changed set is empty (not absent — the file is tracked).
176- self ::assertArrayHasKey ( ' file.xml ' , $ result );
177- self ::assertSame ([], $ result [ ' file.xml ' ] );
178+ self ::assertNotNull ( $ change );
179+ self ::assertSame ([], $ change -> addedLineNumbers );
178180 }
179181
180182 #[Test]
@@ -211,9 +213,9 @@ public function itIgnoresTheMissingFinalNewlineMarker(): void
211213+second
212214DIFF;
213215
214- $ result = $ this ->lineNumbersByFile ( $ this -> parser ->parse ($ diff) );
216+ $ result = $ this ->parser ->parse ($ diff );
215217
216- self ::assertSame ([1 , 2 ], $ result[ 'file.xml ' ] );
218+ self ::assertSame ([1 , 2 ], $ result-> changeFor ( 'file.xml ' )?->addedLineNumbers );
217219 }
218220
219221 #[Test]
@@ -255,9 +257,9 @@ public function itTracksLineNumbersAcrossMultipleHunks(): void
255257 line12
256258DIFF;
257259
258- $ result = $ this ->lineNumbersByFile ( $ this -> parser ->parse ($ diff) );
260+ $ result = $ this ->parser ->parse ($ diff );
259261
260- self ::assertSame ([2 , 12 ], $ result[ 'file.xml ' ] );
262+ self ::assertSame ([2 , 12 ], $ result-> changeFor ( 'file.xml ' )?->addedLineNumbers );
261263 }
262264
263265 #[Test]
@@ -271,21 +273,8 @@ public function itHandlesHunkWithNoContext(): void
271273+only line
272274DIFF;
273275
274- $ result = $ this ->lineNumbersByFile ($ this ->parser ->parse ($ diff ));
275-
276- self ::assertSame ([1 ], $ result ['file.xml ' ]);
277- }
278-
279- // TODO: avoids test diff churn; remove when fixers merged
280- /** @return array<string, list<int>> */
281- private function lineNumbersByFile (DiffChangeset $ diff ): array
282- {
283- $ lineNumbersByFile = [];
284-
285- foreach ($ diff ->fileChanges as $ fileChange ) {
286- $ lineNumbersByFile [$ fileChange ->filePath ] = $ fileChange ->addedLineNumbers ;
287- }
276+ $ result = $ this ->parser ->parse ($ diff );
288277
289- return $ lineNumbersByFile ;
278+ self :: assertSame ([ 1 ], $ result -> changeFor ( ' file.xml ' )?->addedLineNumbers) ;
290279 }
291280}
0 commit comments