diff --git a/tests/lib/BinaryFinderTest.php b/tests/lib/BinaryFinderTest.php index af7bf8b9126b6..fd289ae19400b 100644 --- a/tests/lib/BinaryFinderTest.php +++ b/tests/lib/BinaryFinderTest.php @@ -13,6 +13,8 @@ use OCP\ICache; use OCP\ICacheFactory; use OCP\IConfig; +use OCP\ITempManager; +use OCP\Server; class BinaryFinderTest extends TestCase { private ICache $cache; @@ -43,8 +45,8 @@ public function testDefaultFindsCat() { return $default; }); $finder = new BinaryFinder($this->cacheFactory, $config); - $this->assertEquals($finder->findBinaryPath('cat'), '/usr/bin/cat'); - $this->assertEquals($this->cache->get('cat'), '/usr/bin/cat'); + $this->assertStringEndsWith('/cat', $finder->findBinaryPath('cat')); + $this->assertStringEndsWith('/cat', $this->cache->get('cat')); } public function testDefaultDoesNotFindCata() { @@ -61,22 +63,28 @@ public function testDefaultDoesNotFindCata() { } public function testCustomPathFindsCat() { + $tmpdir = Server::get(ITempManager::class)->getTemporaryFolder(); + touch($tmpdir . '/cat'); + chmod($tmpdir . '/cat', 100); + $config = $this->createMock(IConfig::class); $config ->method('getSystemValue') ->with('binary_search_paths', $this->anything()) - ->willReturn(['/usr/bin']); + ->willReturn([$tmpdir]); $finder = new BinaryFinder($this->cacheFactory, $config); - $this->assertEquals($finder->findBinaryPath('cat'), '/usr/bin/cat'); - $this->assertEquals($this->cache->get('cat'), '/usr/bin/cat'); + $this->assertEquals($tmpdir . '/cat', $finder->findBinaryPath('cat')); + $this->assertEquals($tmpdir . '/cat', $this->cache->get('cat')); } public function testWrongCustomPathDoesNotFindCat() { + $tmpdir = Server::get(ITempManager::class)->getTemporaryFolder(); + $config = $this->createMock(IConfig::class); $config ->method('getSystemValue') ->with('binary_search_paths') - ->willReturn(['/wrong']); + ->willReturn([$tmpdir]); $finder = new BinaryFinder($this->cacheFactory, $config); $this->assertFalse($finder->findBinaryPath('cat')); $this->assertFalse($this->cache->get('cat'));