getMockBuilder(\OC_FileChunking::class) ->setMethods(['getCache']) ->setConstructorArgs([[ 'name' => 'file', 'transferid' => '42', 'chunkcount' => $total, ]]) ->getMock(); $cache = $this->createMock(ICache::class); $cache->expects($this->atLeastOnce()) ->method('hasKey') ->willReturnCallback(function ($key) use ($present) { $data = explode('-', $key); return in_array($data[3], $present); }); $fileChunking->method('getCache')->willReturn($cache); $this->assertEquals($expected, $fileChunking->isComplete()); } }