@@ -108,58 +108,98 @@ public function testBuildNotExistingFileNameForView() {
108108 $ this ->assertEquals ('/filename ' , OC_Helper::buildNotExistingFileNameForView ('/ ' , 'filename ' , $ viewMock ));
109109 $ this ->assertEquals ('dir/filename.ext ' , OC_Helper::buildNotExistingFileNameForView ('dir ' , 'filename.ext ' , $ viewMock ));
110110
111- $ viewMock ->expects ($ this ->at (0 ))
112- ->method ('file_exists ' )
113- ->willReturn (true ); // filename.ext exists
111+ $ viewMock = $ this ->createMock (View::class);
112+ $ viewMock ->expects ($ this ->exactly (2 ))
113+ ->method ('file_exists ' )
114+ ->withConsecutive (
115+ // Conflict on filename.ext
116+ ['dir/filename.ext ' ],
117+ ['dir/filename (2).ext ' ],
118+ )
119+ ->will ($ this ->onConsecutiveCalls (true , false ));
114120 $ this ->assertEquals ('dir/filename (2).ext ' , OC_Helper::buildNotExistingFileNameForView ('dir ' , 'filename.ext ' , $ viewMock ));
115121
116- $ viewMock ->expects ($ this ->at (0 ))
117- ->method ('file_exists ' )
118- ->willReturn (true ); // filename.ext exists
119- $ viewMock ->expects ($ this ->at (1 ))
120- ->method ('file_exists ' )
121- ->willReturn (true ); // filename (2).ext exists
122+ $ viewMock = $ this ->createMock (View::class);
123+ $ viewMock ->expects ($ this ->exactly (3 ))
124+ ->method ('file_exists ' )
125+ ->withConsecutive (
126+ ['dir/filename.ext ' ],
127+ ['dir/filename (2).ext ' ],
128+ ['dir/filename (3).ext ' ],
129+ )
130+ ->will ($ this ->onConsecutiveCalls (true , true , false ));
122131 $ this ->assertEquals ('dir/filename (3).ext ' , OC_Helper::buildNotExistingFileNameForView ('dir ' , 'filename.ext ' , $ viewMock ));
123132
124- $ viewMock ->expects ($ this ->at (0 ))
125- ->method ('file_exists ' )
126- ->willReturn (true ); // filename (1).ext exists
133+ $ viewMock = $ this ->createMock (View::class);
134+ $ viewMock ->expects ($ this ->exactly (2 ))
135+ ->method ('file_exists ' )
136+ ->withConsecutive (
137+ ['dir/filename (1).ext ' ],
138+ ['dir/filename (2).ext ' ],
139+ )
140+ ->will ($ this ->onConsecutiveCalls (true , false ));
127141 $ this ->assertEquals ('dir/filename (2).ext ' , OC_Helper::buildNotExistingFileNameForView ('dir ' , 'filename (1).ext ' , $ viewMock ));
128142
129- $ viewMock ->expects ($ this ->at (0 ))
130- ->method ('file_exists ' )
131- ->willReturn (true ); // filename (2).ext exists
143+ $ viewMock = $ this ->createMock (View::class);
144+ $ viewMock ->expects ($ this ->exactly (2 ))
145+ ->method ('file_exists ' )
146+ ->withConsecutive (
147+ ['dir/filename (2).ext ' ],
148+ ['dir/filename (3).ext ' ],
149+ )
150+ ->will ($ this ->onConsecutiveCalls (true , false ));
132151 $ this ->assertEquals ('dir/filename (3).ext ' , OC_Helper::buildNotExistingFileNameForView ('dir ' , 'filename (2).ext ' , $ viewMock ));
133152
134- $ viewMock ->expects ($ this ->at (0 ))
135- ->method ('file_exists ' )
136- ->willReturn (true ); // filename (2).ext exists
137- $ viewMock ->expects ($ this ->at (1 ))
138- ->method ('file_exists ' )
139- ->willReturn (true ); // filename (3).ext exists
153+ $ viewMock = $ this ->createMock (View::class);
154+ $ viewMock ->expects ($ this ->exactly (3 ))
155+ ->method ('file_exists ' )
156+ ->withConsecutive (
157+ ['dir/filename (2).ext ' ],
158+ ['dir/filename (3).ext ' ],
159+ ['dir/filename (4).ext ' ],
160+ )
161+ ->will ($ this ->onConsecutiveCalls (true , true , false ));
140162 $ this ->assertEquals ('dir/filename (4).ext ' , OC_Helper::buildNotExistingFileNameForView ('dir ' , 'filename (2).ext ' , $ viewMock ));
141163
142- $ viewMock ->expects ($ this ->at (0 ))
143- ->method ('file_exists ' )
144- ->willReturn (true ); // filename(1).ext exists
164+ $ viewMock = $ this ->createMock (View::class);
165+ $ viewMock ->expects ($ this ->exactly (2 ))
166+ ->method ('file_exists ' )
167+ ->withConsecutive (
168+ ['dir/filename(1).ext ' ],
169+ ['dir/filename(2).ext ' ],
170+ )
171+ ->will ($ this ->onConsecutiveCalls (true , false ));
145172 $ this ->assertEquals ('dir/filename(2).ext ' , OC_Helper::buildNotExistingFileNameForView ('dir ' , 'filename(1).ext ' , $ viewMock ));
146173
147- $ viewMock ->expects ($ this ->at (0 ))
148- ->method ('file_exists ' )
149- ->willReturn (true ); // filename(1) (1).ext exists
174+ $ viewMock = $ this ->createMock (View::class);
175+ $ viewMock ->expects ($ this ->exactly (2 ))
176+ ->method ('file_exists ' )
177+ ->withConsecutive (
178+ ['dir/filename(1) (1).ext ' ],
179+ ['dir/filename(1) (2).ext ' ],
180+ )
181+ ->will ($ this ->onConsecutiveCalls (true , false ));
150182 $ this ->assertEquals ('dir/filename(1) (2).ext ' , OC_Helper::buildNotExistingFileNameForView ('dir ' , 'filename(1) (1).ext ' , $ viewMock ));
151183
152- $ viewMock ->expects ($ this ->at (0 ))
153- ->method ('file_exists ' )
154- ->willReturn (true ); // filename(1) (1).ext exists
155- $ viewMock ->expects ($ this ->at (1 ))
156- ->method ('file_exists ' )
157- ->willReturn (true ); // filename(1) (2).ext exists
184+ $ viewMock = $ this ->createMock (View::class);
185+ $ viewMock ->expects ($ this ->exactly (3 ))
186+ ->method ('file_exists ' )
187+ ->withConsecutive (
188+ ['dir/filename(1) (1).ext ' ],
189+ ['dir/filename(1) (2).ext ' ],
190+ ['dir/filename(1) (3).ext ' ],
191+ )
192+ ->will ($ this ->onConsecutiveCalls (true , true , false ));
158193 $ this ->assertEquals ('dir/filename(1) (3).ext ' , OC_Helper::buildNotExistingFileNameForView ('dir ' , 'filename(1) (1).ext ' , $ viewMock ));
159194
160- $ viewMock ->expects ($ this ->at (0 ))
161- ->method ('file_exists ' )
162- ->willReturn (true ); // filename(1) (2) (3).ext exists
195+ $ viewMock = $ this ->createMock (View::class);
196+ $ viewMock ->expects ($ this ->exactly (2 ))
197+ ->method ('file_exists ' )
198+ ->withConsecutive (
199+ ['dir/filename(1) (2) (3).ext ' ],
200+ ['dir/filename(1) (2) (4).ext ' ],
201+ )
202+ ->will ($ this ->onConsecutiveCalls (true , false ));
163203 $ this ->assertEquals ('dir/filename(1) (2) (4).ext ' , OC_Helper::buildNotExistingFileNameForView ('dir ' , 'filename(1) (2) (3).ext ' , $ viewMock ));
164204 }
165205
0 commit comments