diff options
author | François Freitag <mail@franek.fr> | 2021-05-31 23:12:02 +0200 |
---|---|---|
committer | François Freitag <mail@franek.fr> | 2021-06-07 21:43:30 +0200 |
commit | 21762a1e9416f71fa04a8b32e960ed660cf455b0 (patch) | |
tree | bb6bfa9dc1bbeed831aaeeb6fb75f7d644d911bf /tests/lib/LegacyHelperTest.php | |
parent | ae4907b6c95b7ac5d36ef358048c7acafd517c07 (diff) | |
download | nextcloud-server-21762a1e9416f71fa04a8b32e960ed660cf455b0.tar.gz nextcloud-server-21762a1e9416f71fa04a8b32e960ed660cf455b0.zip |
Rewrite LegacyHelperTest without $this->at()
The at() matcher has been deprecated. It will be removed in PHPUnit 10.
Please refactor your test to not rely on the order in which methods are
invoked.
Signed-off-by: François Freitag <mail@franek.fr>
Diffstat (limited to 'tests/lib/LegacyHelperTest.php')
-rw-r--r-- | tests/lib/LegacyHelperTest.php | 112 |
1 files changed, 76 insertions, 36 deletions
diff --git a/tests/lib/LegacyHelperTest.php b/tests/lib/LegacyHelperTest.php index 1dfc3dace6c..4a253940931 100644 --- a/tests/lib/LegacyHelperTest.php +++ b/tests/lib/LegacyHelperTest.php @@ -108,58 +108,98 @@ class LegacyHelperTest extends \Test\TestCase { $this->assertEquals('/filename', OC_Helper::buildNotExistingFileNameForView('/', 'filename', $viewMock)); $this->assertEquals('dir/filename.ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock)); - $viewMock->expects($this->at(0)) - ->method('file_exists') - ->willReturn(true); // filename.ext exists + $viewMock = $this->createMock(View::class); + $viewMock->expects($this->exactly(2)) + ->method('file_exists') + ->withConsecutive( + // Conflict on filename.ext + ['dir/filename.ext'], + ['dir/filename (2).ext'], + ) + ->will($this->onConsecutiveCalls(true, false)); $this->assertEquals('dir/filename (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock)); - $viewMock->expects($this->at(0)) - ->method('file_exists') - ->willReturn(true); // filename.ext exists - $viewMock->expects($this->at(1)) - ->method('file_exists') - ->willReturn(true); // filename (2).ext exists + $viewMock = $this->createMock(View::class); + $viewMock->expects($this->exactly(3)) + ->method('file_exists') + ->withConsecutive( + ['dir/filename.ext'], + ['dir/filename (2).ext'], + ['dir/filename (3).ext'], + ) + ->will($this->onConsecutiveCalls(true, true, false)); $this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock)); - $viewMock->expects($this->at(0)) - ->method('file_exists') - ->willReturn(true); // filename (1).ext exists + $viewMock = $this->createMock(View::class); + $viewMock->expects($this->exactly(2)) + ->method('file_exists') + ->withConsecutive( + ['dir/filename (1).ext'], + ['dir/filename (2).ext'], + ) + ->will($this->onConsecutiveCalls(true, false)); $this->assertEquals('dir/filename (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (1).ext', $viewMock)); - $viewMock->expects($this->at(0)) - ->method('file_exists') - ->willReturn(true); // filename (2).ext exists + $viewMock = $this->createMock(View::class); + $viewMock->expects($this->exactly(2)) + ->method('file_exists') + ->withConsecutive( + ['dir/filename (2).ext'], + ['dir/filename (3).ext'], + ) + ->will($this->onConsecutiveCalls(true, false)); $this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock)); - $viewMock->expects($this->at(0)) - ->method('file_exists') - ->willReturn(true); // filename (2).ext exists - $viewMock->expects($this->at(1)) - ->method('file_exists') - ->willReturn(true); // filename (3).ext exists + $viewMock = $this->createMock(View::class); + $viewMock->expects($this->exactly(3)) + ->method('file_exists') + ->withConsecutive( + ['dir/filename (2).ext'], + ['dir/filename (3).ext'], + ['dir/filename (4).ext'], + ) + ->will($this->onConsecutiveCalls(true, true, false)); $this->assertEquals('dir/filename (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock)); - $viewMock->expects($this->at(0)) - ->method('file_exists') - ->willReturn(true); // filename(1).ext exists + $viewMock = $this->createMock(View::class); + $viewMock->expects($this->exactly(2)) + ->method('file_exists') + ->withConsecutive( + ['dir/filename(1).ext'], + ['dir/filename(2).ext'], + ) + ->will($this->onConsecutiveCalls(true, false)); $this->assertEquals('dir/filename(2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1).ext', $viewMock)); - $viewMock->expects($this->at(0)) - ->method('file_exists') - ->willReturn(true); // filename(1) (1).ext exists + $viewMock = $this->createMock(View::class); + $viewMock->expects($this->exactly(2)) + ->method('file_exists') + ->withConsecutive( + ['dir/filename(1) (1).ext'], + ['dir/filename(1) (2).ext'], + ) + ->will($this->onConsecutiveCalls(true, false)); $this->assertEquals('dir/filename(1) (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock)); - $viewMock->expects($this->at(0)) - ->method('file_exists') - ->willReturn(true); // filename(1) (1).ext exists - $viewMock->expects($this->at(1)) - ->method('file_exists') - ->willReturn(true); // filename(1) (2).ext exists + $viewMock = $this->createMock(View::class); + $viewMock->expects($this->exactly(3)) + ->method('file_exists') + ->withConsecutive( + ['dir/filename(1) (1).ext'], + ['dir/filename(1) (2).ext'], + ['dir/filename(1) (3).ext'], + ) + ->will($this->onConsecutiveCalls(true, true, false)); $this->assertEquals('dir/filename(1) (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock)); - $viewMock->expects($this->at(0)) - ->method('file_exists') - ->willReturn(true); // filename(1) (2) (3).ext exists + $viewMock = $this->createMock(View::class); + $viewMock->expects($this->exactly(2)) + ->method('file_exists') + ->withConsecutive( + ['dir/filename(1) (2) (3).ext'], + ['dir/filename(1) (2) (4).ext'], + ) + ->will($this->onConsecutiveCalls(true, false)); $this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock)); } |