1313use OCP \ICache ;
1414use OCP \ICacheFactory ;
1515use OCP \IConfig ;
16+ use OCP \ITempManager ;
17+ use OCP \Server ;
1618
1719class BinaryFinderTest extends TestCase {
1820 private ICache $ cache ;
@@ -43,8 +45,8 @@ public function testDefaultFindsCat() {
4345 return $ default ;
4446 });
4547 $ finder = new BinaryFinder ($ this ->cacheFactory , $ config );
46- $ this ->assertEquals ( $ finder ->findBinaryPath ('cat ' ), ' /usr/bin/cat ' );
47- $ this ->assertEquals ( $ this ->cache ->get ('cat ' ), ' /usr/bin/cat ' );
48+ $ this ->assertStringEndsWith ( ' /cat ' , $ finder ->findBinaryPath ('cat ' ));
49+ $ this ->assertStringEndsWith ( ' /cat ' , $ this ->cache ->get ('cat ' ));
4850 }
4951
5052 public function testDefaultDoesNotFindCata () {
@@ -61,22 +63,28 @@ public function testDefaultDoesNotFindCata() {
6163 }
6264
6365 public function testCustomPathFindsCat () {
66+ $ tmpdir = Server::get (ITempManager::class)->getTemporaryFolder ();
67+ touch ($ tmpdir . '/cat ' );
68+ chmod ($ tmpdir . '/cat ' , 100 );
69+
6470 $ config = $ this ->createMock (IConfig::class);
6571 $ config
6672 ->method ('getSystemValue ' )
6773 ->with ('binary_search_paths ' , $ this ->anything ())
68- ->willReturn ([' /usr/bin ' ]);
74+ ->willReturn ([$ tmpdir ]);
6975 $ finder = new BinaryFinder ($ this ->cacheFactory , $ config );
70- $ this ->assertEquals ($ finder ->findBinaryPath ('cat ' ), ' /usr/bin/cat ' );
71- $ this ->assertEquals ($ this ->cache ->get ('cat ' ), ' /usr/bin/cat ' );
76+ $ this ->assertEquals ($ tmpdir . ' /cat ' , $ finder ->findBinaryPath ('cat ' ));
77+ $ this ->assertEquals ($ tmpdir . ' /cat ' , $ this ->cache ->get ('cat ' ));
7278 }
7379
7480 public function testWrongCustomPathDoesNotFindCat () {
81+ $ tmpdir = Server::get (ITempManager::class)->getTemporaryFolder ();
82+
7583 $ config = $ this ->createMock (IConfig::class);
7684 $ config
7785 ->method ('getSystemValue ' )
7886 ->with ('binary_search_paths ' )
79- ->willReturn ([' /wrong ' ]);
87+ ->willReturn ([$ tmpdir ]);
8088 $ finder = new BinaryFinder ($ this ->cacheFactory , $ config );
8189 $ this ->assertFalse ($ finder ->findBinaryPath ('cat ' ));
8290 $ this ->assertFalse ($ this ->cache ->get ('cat ' ));
0 commit comments