Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / vendor / drush / drush / isolation / tests / SiteAliasFileDiscoveryTest.php
1 <?php
2 namespace Drush\SiteAlias;
3
4 use PHPUnit\Framework\TestCase;
5 use Consolidation\SiteAlias\SiteAliasFileDiscovery;
6
7 class SiteAliasFileDiscoveryTest extends TestCase
8 {
9     use \Drush\FixtureFactory;
10     use \Drush\FunctionUtils;
11
12     function setUp()
13     {
14         $this->sut = new SiteAliasFileDiscovery();
15     }
16
17     public function testSearchForSingleAliasFile()
18     {
19         $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/single');
20
21         $path = $this->sut->findSingleSiteAliasFile('single');
22         $this->assertLocation('single', $path);
23         $this->assertBasename('single.site.yml', $path);
24     }
25
26     public function testSearchForMissingSingleAliasFile()
27     {
28         $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/single');
29
30         $path = $this->sut->findSingleSiteAliasFile('missing');
31         $this->assertFalse($path);
32     }
33
34     public function testFindAllLegacyAliasFiles()
35     {
36         $this->sut->addSearchLocation($this->fixturesDir() . '/sitealiases/legacy');
37
38         $result = $this->sut->findAllLegacyAliasFiles();
39         $paths = $this->simplifyToBasenamesWithLocation($result);
40         $this->assertEquals('legacy/cc.aliases.drushrc.php,legacy/one.alias.drushrc.php,legacy/pantheon.aliases.drushrc.php,legacy/server.aliases.drushrc.php', implode(',', $paths));
41     }
42
43     protected function assertLocation($expected, $path)
44     {
45         $this->assertEquals($expected, basename(dirname($path)));
46     }
47
48     protected function assertBasename($expected, $path)
49     {
50         $this->assertEquals($expected, basename($path));
51     }
52
53     protected function simplifyToBasenamesWithLocation($result)
54     {
55         if (!is_array($result)) {
56             return $result;
57         }
58
59         $result = array_map(
60             function ($item) {
61                 return basename(dirname($item)) . '/' . basename($item);
62             }
63             ,
64             $result
65         );
66
67         sort($result);
68
69         return $result;
70     }
71 }