Skip to content

Commit

Permalink
Updating tests and local commands
Browse files Browse the repository at this point in the history
  • Loading branch information
stovak committed Jul 1, 2021
1 parent e37761b commit 7c74cd5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 15 deletions.
5 changes: 5 additions & 0 deletions src/Collections/TerminusCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use League\Container\ContainerAwareInterface;
use League\Container\ContainerAwareTrait;
use Pantheon\Terminus\Exceptions\TerminusException;
use Pantheon\Terminus\Exceptions\TerminusNotFoundException;
use Pantheon\Terminus\Models\TerminusModel;
use Pantheon\Terminus\Request\RequestAwareInterface;
Expand Down Expand Up @@ -52,11 +53,15 @@ public function __construct(array $options = [])
*/
public function add($model_data, array $options = [])
{
if (is_string($model_data)) {
throw new TerminusException($model_data);
}
$options = array_merge(
['id' => $model_data->id, 'collection' => $this],
$options
);
$nickname = \uniqid($model_data->id);

$this->getContainer()->add($nickname, $this->collected_class)
->addArguments([$model_data, $options]);
$model = $this->getContainer()->get($nickname);
Expand Down
5 changes: 4 additions & 1 deletion src/Commands/Local/CloneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ class CloneCommand extends TerminusCommand implements SiteAwareInterface, Config
* @param string $site Site
*
* @usage <site> Clone's a local copy into "$HOME/pantheon-local-copies"
*@return string
* @return string
* @throws \Pantheon\Terminus\Exceptions\TerminusException
*
*/
public function clone($site) : string
{
$siteData = $site;

if (!$siteData instanceof Site) {
$siteData = $this->getSite($site);
if (!$siteData instanceof Site) {
Expand All @@ -55,8 +56,10 @@ public function clone($site) : string
}

$env = $siteData->getEnvironments()->get('dev');

$clone_path = $siteData->getLocalCopyFolder();
$connection = $env->connectionInfo();

if (!is_dir($clone_path . DIRECTORY_SEPARATOR . ".git")) {
$this->execute(
"git clone %s %s",
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Local/CommitAndPushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CommitAndPushCommand extends TerminusCommand implements SiteAwareInterface
*
* @authorize
*
* @command local:clone
* @command local:commitAndPush
* @aliases lc
*
* @param string $site Site
Expand Down
1 change: 1 addition & 0 deletions src/Commands/Local/GetLiveDBCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,6 @@ public function downloadLiveDbBackup($site, $options = ['overwrite' => false])
$db_local_filename
);
$this->logger->notice("DB Backup Downloaded to: {path}", ["path" => $db_local_filename]);
return $db_local_filename;
}
}
1 change: 1 addition & 0 deletions src/Commands/Local/GetLiveFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ public function downloadLiveFilesBackup($site, $options = ['overwrite' => false]
throw new TerminusException("Cannot download backup file.");
}
$this->logger->notice("Files Backup Downloaded to: {path}", ["path" => $files_local_filename]);
return $files_local_filename;
}
}
51 changes: 38 additions & 13 deletions tests/Functional/LocalCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,61 @@ public function setUp(): void
public function testLocalClone()
{
$sitename = getenv('TERMINUS_SITE');
$local_sites_folder = realpath(getenv('TERMINUS_LOCAL_SITES')) . DIRECTORY_SEPARATOR .
'pantheon-local-copies';
$willBeCreated = $local_sites_folder . DIRECTORY_SEPARATOR . $sitename;
$this->terminus("local:clone {$sitename}", null);
$this->assertTrue(is_dir($willBeCreated));
$result = $this->terminus("local:clone {$sitename}", null);
if (!is_string($result)) {
throw new \Exception("The response from the local clone command didn't return the path.");
}
$shouldExist = $result . DIRECTORY_SEPARATOR . '.git';
$this->assertTrue(
is_dir($shouldExist),
"The sites .git directory does not exist: {$shouldExist}"
);
}

/**
* @test
* @covers \Pantheon\Terminus\Commands\Local\CommitAndPushCommand
* @covers \Pantheon\Terminus\Commands\Local\GetLiveFilesCommand
* @covers \Pantheon\Terminus\Commands\Local\GetLiveDBCommand
*
* @group local
* @gropu long
*/
public function testCommitDbFiles()
public function testCommitDb()
{
$sitename = getenv('TERMINUS_SITE');
$result = $this->terminus("local:getLiveDB {$sitename}.live");
$this->assertTrue(
is_file($result),
"The db file failed to download."
);
}

/**
* @test
* @covers \Pantheon\Terminus\Commands\Local\GetLiveFilesCommand
*
* @group local
* @gropu long
*/
public function testCommitFiles()
{
$this->fail("To Be Written");
$sitename = getenv('TERMINUS_SITE');
$result = $this->terminus("local:getLiveFiles {$sitename}.live");
$this->assertTrue(
is_file($result),
'The site file failed to download.'
);
}

/**
* @after
*/
public function tearDown(): void
{
$local_sites_folder = realpath(getenv('TERMINUS_LOCAL_SITES')) . DIRECTORY_SEPARATOR .
'pantheon-local-copies';
if (is_dir($local_sites_folder)) {
exec("rm -Rf {$local_sites_folder}");
$sitename = getenv('TERMINUS_SITE');
$local_site_folder = realpath(getenv('TERMINUS_LOCAL_SITES')) . DIRECTORY_SEPARATOR .
'pantheon-local-copies' . DIRECTORY_SEPARATOR . $sitename;
if (is_dir($local_site_folder)) {
exec("rm -Rf {$local_site_folder}");
}
}
}
1 change: 1 addition & 0 deletions tests/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ default:
machine_token_id: 'dcr_q4tFMiYiK9DfJO15'
cache_dir: '[[system_temp]]/.terminus/cache'
executable: 'bin/t3'
local_copies: '~/pantheon-local-copies'

0 comments on commit 7c74cd5

Please sign in to comment.