|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use Tester\Assert; |
| 6 | +use Tester\Helpers; |
| 7 | + |
| 8 | +require __DIR__ . '/../bootstrap.php'; |
| 9 | + |
| 10 | +Assert::same('', Helpers::findCommonDirectory([])); |
| 11 | + |
| 12 | +Assert::match(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures.helpers', Helpers::findCommonDirectory([ |
| 13 | + __DIR__ . '/fixtures.helpers/a', |
| 14 | + __DIR__ . '/fixtures.helpers/aa', |
| 15 | +])); |
| 16 | + |
| 17 | +Assert::match(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures.helpers', Helpers::findCommonDirectory([ |
| 18 | + __DIR__ . '/fixtures.helpers/a/file.txt', |
| 19 | + __DIR__ . '/fixtures.helpers/aa/file.txt', |
| 20 | +])); |
| 21 | + |
| 22 | +Assert::match(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures.helpers' . DIRECTORY_SEPARATOR . 'a', Helpers::findCommonDirectory([ |
| 23 | + __DIR__ . '/fixtures.helpers/a/', |
| 24 | + __DIR__ . '/fixtures.helpers/a/file.txt', |
| 25 | +])); |
| 26 | + |
| 27 | +Assert::match(getcwd(), Helpers::findCommonDirectory([ |
| 28 | + '.', |
| 29 | +])); |
| 30 | + |
| 31 | +Assert::match(dirname(getcwd()), Helpers::findCommonDirectory([ |
| 32 | + '..', |
| 33 | +])); |
| 34 | + |
| 35 | + |
| 36 | +// Root directories always end by directory separator. |
| 37 | +if (is_dir('C:/')) { |
| 38 | + Assert::match('C:\\', Helpers::findCommonDirectory([ |
| 39 | + 'C:', |
| 40 | + ])); |
| 41 | +} |
| 42 | + |
| 43 | +if (is_dir('/')) { |
| 44 | + Assert::match(realpath('/'), Helpers::findCommonDirectory([ // realpath() - may point to C:\ in Cygwin |
| 45 | + '/', |
| 46 | + ])); |
| 47 | +} |
| 48 | + |
| 49 | + |
| 50 | +Assert::exception(function () { |
| 51 | + Helpers::findCommonDirectory(['']); |
| 52 | +}, RuntimeException::class, 'Path must not be empty.'); |
| 53 | + |
| 54 | +Assert::exception(function () { |
| 55 | + Helpers::findCommonDirectory(['does-not-exist']); |
| 56 | +}, RuntimeException::class, "File or directory 'does-not-exist' does not exist."); |
0 commit comments