-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
288 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Drall\Command; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* A command to get a list of keys in the $sites array. | ||
*/ | ||
class SiteKeysCommand extends BaseCommand { | ||
|
||
protected function configure() { | ||
parent::configure(); | ||
|
||
$this->setName('site:keys'); | ||
$this->setAliases(['sk']); | ||
$this->setDescription('List the keys of the $sites array.'); | ||
$this->addUsage('site:keys'); | ||
$this->addUsage('--drall-group=GROUP site:keys'); | ||
$this->addUsage('--drall-filter=FILTER site:keys'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
$this->preExecute($input, $output); | ||
|
||
$keys = $this->siteDetector() | ||
->getSiteKeys( | ||
$this->getDrallGroup($input), | ||
$this->getDrallFilter($input), | ||
); | ||
|
||
if (count($keys) === 0) { | ||
$this->logger->warning('No Drupal sites found.'); | ||
return 0; | ||
} | ||
|
||
foreach ($keys as $key) { | ||
$output->writeln($key); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?php | ||
|
||
namespace Drall\Test\Integration\Commands; | ||
|
||
use Drall\IntegrationTestCase; | ||
|
||
/** | ||
* @covers \Drall\Command\SiteDirectoriesCommand | ||
*/ | ||
class SiteKeysCommandTest extends IntegrationTestCase { | ||
|
||
/** | ||
* Run site:keys with no Drupal installation. | ||
*/ | ||
public function testWithNoDrupal(): void { | ||
chdir('/tmp'); | ||
$output = shell_exec('drall site:keys'); | ||
$this->assertOutputEquals("[warning] No Drupal sites found." . PHP_EOL, $output); | ||
} | ||
|
||
/** | ||
* Run site:keys with a Drupal installation. | ||
*/ | ||
public function testExecute(): void { | ||
$output = shell_exec('drall site:keys'); | ||
$this->assertOutputEquals(<<<EOF | ||
tmnt.com | ||
cowabunga.com | ||
tmnt.drall.local | ||
donatello.com | ||
8080.donatello.com | ||
donnie.drall.local | ||
leonardo.com | ||
leo.drall.local | ||
michelangelo.com | ||
mikey.drall.local | ||
raphael.com | ||
ralph.drall.local | ||
EOF, $output); | ||
} | ||
|
||
/** | ||
* Run site:keys with --drall-filter. | ||
*/ | ||
public function testExecuteWithFilter(): void { | ||
$output = shell_exec('drall site:keys --drall-filter="[email protected]\$@"'); | ||
$this->assertOutputEquals(<<<EOF | ||
tmnt.drall.local | ||
donnie.drall.local | ||
leo.drall.local | ||
mikey.drall.local | ||
ralph.drall.local | ||
EOF, $output); | ||
} | ||
|
||
/** | ||
* Run site:keys with --drall-group. | ||
*/ | ||
public function testWithGroup(): void { | ||
$output = shell_exec('drall site:keys --drall-group=bluish'); | ||
$this->assertOutputEquals(<<<EOF | ||
donatello.com | ||
8080.donatello.com | ||
donnie.drall.local | ||
leonardo.com | ||
leo.drall.local | ||
EOF, $output); | ||
} | ||
|
||
/** | ||
* Run site:keys with DRALL_GROUP env var. | ||
*/ | ||
public function testWithGroupEnvVar(): void { | ||
$output = shell_exec('DRALL_GROUP=bluish drall site:keys'); | ||
$this->assertOutputEquals(<<<EOF | ||
donatello.com | ||
8080.donatello.com | ||
donnie.drall.local | ||
leonardo.com | ||
leo.drall.local | ||
EOF, $output); | ||
} | ||
|
||
public function testWithComposerRoot() { | ||
chdir('/'); | ||
$output = shell_exec('drall --root=' . $this->drupalDir() . ' site:keys'); | ||
$this->assertEquals(<<<EOF | ||
tmnt.com | ||
cowabunga.com | ||
tmnt.drall.local | ||
donatello.com | ||
8080.donatello.com | ||
donnie.drall.local | ||
leonardo.com | ||
leo.drall.local | ||
michelangelo.com | ||
mikey.drall.local | ||
raphael.com | ||
ralph.drall.local | ||
EOF, $output); | ||
} | ||
|
||
public function testWithDrupalRoot() { | ||
chdir('/'); | ||
$output = shell_exec('drall --root=' . $this->drupalDir() . '/web site:keys'); | ||
$this->assertEquals(<<<EOF | ||
tmnt.com | ||
cowabunga.com | ||
tmnt.drall.local | ||
donatello.com | ||
8080.donatello.com | ||
donnie.drall.local | ||
leonardo.com | ||
leo.drall.local | ||
michelangelo.com | ||
mikey.drall.local | ||
raphael.com | ||
ralph.drall.local | ||
EOF, $output); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace Unit\Command; | ||
|
||
use Consolidation\SiteAlias\SiteAliasManager; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use DrupalFinder\DrupalFinder; | ||
use Drall\Drall; | ||
use Drall\Service\SiteDetector; | ||
use Drall\TestCase; | ||
|
||
/** | ||
* @covers \Drall\Command\BaseCommand | ||
* @covers \Drall\Command\SiteDirectoriesCommand | ||
*/ | ||
class SiteKeysCommandTest extends TestCase { | ||
|
||
public function testExecute() { | ||
$drupalFinder = new DrupalFinder(); | ||
$siteAliasManager = new SiteAliasManager(); | ||
|
||
$siteDetectorMock = $this->getMockBuilder(SiteDetector::class) | ||
->setConstructorArgs([$drupalFinder, $siteAliasManager]) | ||
->onlyMethods(['getSiteKeys']) | ||
->getMock(); | ||
$siteDetectorMock | ||
->expects($this->once()) | ||
->method('getSiteKeys') | ||
->willReturn(['donatello.com', 'leonardo.com']); | ||
|
||
$app = new Drall($siteDetectorMock); | ||
$tester = new CommandTester($app->find('site:keys')); | ||
$tester->execute([]); | ||
|
||
$tester->assertCommandIsSuccessful(); | ||
|
||
$this->assertEquals( | ||
<<<EOF | ||
donatello.com | ||
leonardo.com | ||
EOF, | ||
$tester->getDisplay() | ||
); | ||
} | ||
|
||
public function testExecuteWithGroup() { | ||
$drupalFinder = new DrupalFinder(); | ||
$siteAliasManager = new SiteAliasManager(); | ||
|
||
$siteDetectorMock = $this->getMockBuilder(SiteDetector::class) | ||
->setConstructorArgs([$drupalFinder, $siteAliasManager]) | ||
->onlyMethods(['getSiteKeys']) | ||
->getMock(); | ||
$siteDetectorMock | ||
->expects($this->once()) | ||
->method('getSiteKeys') | ||
->with('bluish') | ||
->willReturn(['tmnt.com']); | ||
|
||
$app = new Drall($siteDetectorMock); | ||
$tester = new CommandTester($app->find('site:keys')); | ||
$tester->execute(['--drall-group' => 'bluish']); | ||
|
||
$tester->assertCommandIsSuccessful(); | ||
|
||
$this->assertEquals( | ||
<<<EOF | ||
tmnt.com | ||
EOF, | ||
$tester->getDisplay() | ||
); | ||
} | ||
|
||
public function testExecuteWithNoSiteDirectories() { | ||
$drupalFinder = new DrupalFinder(); | ||
$siteAliasManager = new SiteAliasManager(); | ||
|
||
$siteDetectorMock = $this->getMockBuilder(SiteDetector::class) | ||
->setConstructorArgs([$drupalFinder, $siteAliasManager]) | ||
->onlyMethods(['getSiteKeys']) | ||
->getMock(); | ||
$siteDetectorMock | ||
->expects($this->once()) | ||
->method('getSiteKeys') | ||
->willReturn([]); | ||
|
||
$app = new Drall($siteDetectorMock); | ||
$tester = new CommandTester($app->find('site:keys')); | ||
$tester->execute([]); | ||
|
||
$tester->assertCommandIsSuccessful(); | ||
|
||
$this->assertEquals( | ||
'[warning] No Drupal sites found.' . PHP_EOL, | ||
$tester->getDisplay() | ||
); | ||
} | ||
|
||
} |