@@ -17,76 +17,76 @@ |
||
| 17 | 17 | use OCP\Server; |
| 18 | 18 | |
| 19 | 19 | class BinaryFinderTest extends TestCase { |
| 20 | - private ICache $cache; |
|
| 21 | - private ICacheFactory $cacheFactory; |
|
| 22 | - private $oldEnv; |
|
| 20 | + private ICache $cache; |
|
| 21 | + private ICacheFactory $cacheFactory; |
|
| 22 | + private $oldEnv; |
|
| 23 | 23 | |
| 24 | - protected function setUp(): void { |
|
| 25 | - $this->oldEnv = getenv('PATH'); |
|
| 26 | - // BinaryFinder always includes the "PATH" environment variable into the search path, |
|
| 27 | - // which we want to avoid in this test because they are not usually found in webserver |
|
| 28 | - // deployments. |
|
| 29 | - putenv('PATH=""'); |
|
| 30 | - $this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
| 31 | - $this->cache = new ArrayCache(); |
|
| 32 | - $this->cacheFactory->method('createLocal')->with('findBinaryPath')->willReturn($this->cache); |
|
| 33 | - } |
|
| 24 | + protected function setUp(): void { |
|
| 25 | + $this->oldEnv = getenv('PATH'); |
|
| 26 | + // BinaryFinder always includes the "PATH" environment variable into the search path, |
|
| 27 | + // which we want to avoid in this test because they are not usually found in webserver |
|
| 28 | + // deployments. |
|
| 29 | + putenv('PATH=""'); |
|
| 30 | + $this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
| 31 | + $this->cache = new ArrayCache(); |
|
| 32 | + $this->cacheFactory->method('createLocal')->with('findBinaryPath')->willReturn($this->cache); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - protected function tearDown(): void { |
|
| 36 | - putenv('PATH=' . $this->oldEnv); |
|
| 37 | - } |
|
| 35 | + protected function tearDown(): void { |
|
| 36 | + putenv('PATH=' . $this->oldEnv); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function testDefaultFindsCat() { |
|
| 40 | - $config = $this->createMock(IConfig::class); |
|
| 41 | - $config |
|
| 42 | - ->method('getSystemValue') |
|
| 43 | - ->with('binary_search_paths', $this->anything()) |
|
| 44 | - ->willReturnCallback(function ($key, $default) { |
|
| 45 | - return $default; |
|
| 46 | - }); |
|
| 47 | - $finder = new BinaryFinder($this->cacheFactory, $config); |
|
| 48 | - $this->assertStringEndsWith('/cat', $finder->findBinaryPath('cat')); |
|
| 49 | - $this->assertStringEndsWith('/cat', $this->cache->get('cat')); |
|
| 50 | - } |
|
| 39 | + public function testDefaultFindsCat() { |
|
| 40 | + $config = $this->createMock(IConfig::class); |
|
| 41 | + $config |
|
| 42 | + ->method('getSystemValue') |
|
| 43 | + ->with('binary_search_paths', $this->anything()) |
|
| 44 | + ->willReturnCallback(function ($key, $default) { |
|
| 45 | + return $default; |
|
| 46 | + }); |
|
| 47 | + $finder = new BinaryFinder($this->cacheFactory, $config); |
|
| 48 | + $this->assertStringEndsWith('/cat', $finder->findBinaryPath('cat')); |
|
| 49 | + $this->assertStringEndsWith('/cat', $this->cache->get('cat')); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function testDefaultDoesNotFindCata() { |
|
| 53 | - $config = $this->createMock(IConfig::class); |
|
| 54 | - $config |
|
| 55 | - ->method('getSystemValue') |
|
| 56 | - ->with('binary_search_paths', $this->anything()) |
|
| 57 | - ->willReturnCallback(function ($key, $default) { |
|
| 58 | - return $default; |
|
| 59 | - }); |
|
| 60 | - $finder = new BinaryFinder($this->cacheFactory, $config); |
|
| 61 | - $this->assertFalse($finder->findBinaryPath('cata')); |
|
| 62 | - $this->assertFalse($this->cache->get('cata')); |
|
| 63 | - } |
|
| 52 | + public function testDefaultDoesNotFindCata() { |
|
| 53 | + $config = $this->createMock(IConfig::class); |
|
| 54 | + $config |
|
| 55 | + ->method('getSystemValue') |
|
| 56 | + ->with('binary_search_paths', $this->anything()) |
|
| 57 | + ->willReturnCallback(function ($key, $default) { |
|
| 58 | + return $default; |
|
| 59 | + }); |
|
| 60 | + $finder = new BinaryFinder($this->cacheFactory, $config); |
|
| 61 | + $this->assertFalse($finder->findBinaryPath('cata')); |
|
| 62 | + $this->assertFalse($this->cache->get('cata')); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function testCustomPathFindsCat() { |
|
| 66 | - $tmpdir = Server::get(ITempManager::class)->getTemporaryFolder(); |
|
| 67 | - touch($tmpdir . '/cat'); |
|
| 68 | - chmod($tmpdir . '/cat', 100); |
|
| 65 | + public function testCustomPathFindsCat() { |
|
| 66 | + $tmpdir = Server::get(ITempManager::class)->getTemporaryFolder(); |
|
| 67 | + touch($tmpdir . '/cat'); |
|
| 68 | + chmod($tmpdir . '/cat', 100); |
|
| 69 | 69 | |
| 70 | - $config = $this->createMock(IConfig::class); |
|
| 71 | - $config |
|
| 72 | - ->method('getSystemValue') |
|
| 73 | - ->with('binary_search_paths', $this->anything()) |
|
| 74 | - ->willReturn([$tmpdir]); |
|
| 75 | - $finder = new BinaryFinder($this->cacheFactory, $config); |
|
| 76 | - $this->assertEquals($tmpdir . '/cat', $finder->findBinaryPath('cat')); |
|
| 77 | - $this->assertEquals($tmpdir . '/cat', $this->cache->get('cat')); |
|
| 78 | - } |
|
| 70 | + $config = $this->createMock(IConfig::class); |
|
| 71 | + $config |
|
| 72 | + ->method('getSystemValue') |
|
| 73 | + ->with('binary_search_paths', $this->anything()) |
|
| 74 | + ->willReturn([$tmpdir]); |
|
| 75 | + $finder = new BinaryFinder($this->cacheFactory, $config); |
|
| 76 | + $this->assertEquals($tmpdir . '/cat', $finder->findBinaryPath('cat')); |
|
| 77 | + $this->assertEquals($tmpdir . '/cat', $this->cache->get('cat')); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - public function testWrongCustomPathDoesNotFindCat() { |
|
| 81 | - $tmpdir = Server::get(ITempManager::class)->getTemporaryFolder(); |
|
| 80 | + public function testWrongCustomPathDoesNotFindCat() { |
|
| 81 | + $tmpdir = Server::get(ITempManager::class)->getTemporaryFolder(); |
|
| 82 | 82 | |
| 83 | - $config = $this->createMock(IConfig::class); |
|
| 84 | - $config |
|
| 85 | - ->method('getSystemValue') |
|
| 86 | - ->with('binary_search_paths') |
|
| 87 | - ->willReturn([$tmpdir]); |
|
| 88 | - $finder = new BinaryFinder($this->cacheFactory, $config); |
|
| 89 | - $this->assertFalse($finder->findBinaryPath('cat')); |
|
| 90 | - $this->assertFalse($this->cache->get('cat')); |
|
| 91 | - } |
|
| 83 | + $config = $this->createMock(IConfig::class); |
|
| 84 | + $config |
|
| 85 | + ->method('getSystemValue') |
|
| 86 | + ->with('binary_search_paths') |
|
| 87 | + ->willReturn([$tmpdir]); |
|
| 88 | + $finder = new BinaryFinder($this->cacheFactory, $config); |
|
| 89 | + $this->assertFalse($finder->findBinaryPath('cat')); |
|
| 90 | + $this->assertFalse($this->cache->get('cat')); |
|
| 91 | + } |
|
| 92 | 92 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | /** |
| 5 | 5 | * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
| 6 | 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | protected function tearDown(): void { |
| 36 | - putenv('PATH=' . $this->oldEnv); |
|
| 36 | + putenv('PATH='.$this->oldEnv); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public function testDefaultFindsCat() { |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $config |
| 42 | 42 | ->method('getSystemValue') |
| 43 | 43 | ->with('binary_search_paths', $this->anything()) |
| 44 | - ->willReturnCallback(function ($key, $default) { |
|
| 44 | + ->willReturnCallback(function($key, $default) { |
|
| 45 | 45 | return $default; |
| 46 | 46 | }); |
| 47 | 47 | $finder = new BinaryFinder($this->cacheFactory, $config); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $config |
| 55 | 55 | ->method('getSystemValue') |
| 56 | 56 | ->with('binary_search_paths', $this->anything()) |
| 57 | - ->willReturnCallback(function ($key, $default) { |
|
| 57 | + ->willReturnCallback(function($key, $default) { |
|
| 58 | 58 | return $default; |
| 59 | 59 | }); |
| 60 | 60 | $finder = new BinaryFinder($this->cacheFactory, $config); |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | public function testCustomPathFindsCat() { |
| 66 | 66 | $tmpdir = Server::get(ITempManager::class)->getTemporaryFolder(); |
| 67 | - touch($tmpdir . '/cat'); |
|
| 68 | - chmod($tmpdir . '/cat', 100); |
|
| 67 | + touch($tmpdir.'/cat'); |
|
| 68 | + chmod($tmpdir.'/cat', 100); |
|
| 69 | 69 | |
| 70 | 70 | $config = $this->createMock(IConfig::class); |
| 71 | 71 | $config |
@@ -73,8 +73,8 @@ discard block |
||
| 73 | 73 | ->with('binary_search_paths', $this->anything()) |
| 74 | 74 | ->willReturn([$tmpdir]); |
| 75 | 75 | $finder = new BinaryFinder($this->cacheFactory, $config); |
| 76 | - $this->assertEquals($tmpdir . '/cat', $finder->findBinaryPath('cat')); |
|
| 77 | - $this->assertEquals($tmpdir . '/cat', $this->cache->get('cat')); |
|
| 76 | + $this->assertEquals($tmpdir.'/cat', $finder->findBinaryPath('cat')); |
|
| 77 | + $this->assertEquals($tmpdir.'/cat', $this->cache->get('cat')); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | public function testWrongCustomPathDoesNotFindCat() { |