Skip to content

Commit 7c74cd5

Browse files
committed
Updating tests and local commands
1 parent e37761b commit 7c74cd5

File tree

7 files changed

+51
-15
lines changed

7 files changed

+51
-15
lines changed

src/Collections/TerminusCollection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use League\Container\ContainerAwareInterface;
66
use League\Container\ContainerAwareTrait;
7+
use Pantheon\Terminus\Exceptions\TerminusException;
78
use Pantheon\Terminus\Exceptions\TerminusNotFoundException;
89
use Pantheon\Terminus\Models\TerminusModel;
910
use Pantheon\Terminus\Request\RequestAwareInterface;
@@ -52,11 +53,15 @@ public function __construct(array $options = [])
5253
*/
5354
public function add($model_data, array $options = [])
5455
{
56+
if (is_string($model_data)) {
57+
throw new TerminusException($model_data);
58+
}
5559
$options = array_merge(
5660
['id' => $model_data->id, 'collection' => $this],
5761
$options
5862
);
5963
$nickname = \uniqid($model_data->id);
64+
6065
$this->getContainer()->add($nickname, $this->collected_class)
6166
->addArguments([$model_data, $options]);
6267
$model = $this->getContainer()->get($nickname);

src/Commands/Local/CloneCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ class CloneCommand extends TerminusCommand implements SiteAwareInterface, Config
3737
* @param string $site Site
3838
*
3939
* @usage <site> Clone's a local copy into "$HOME/pantheon-local-copies"
40-
*@return string
40+
* @return string
4141
* @throws \Pantheon\Terminus\Exceptions\TerminusException
4242
*
4343
*/
4444
public function clone($site) : string
4545
{
4646
$siteData = $site;
47+
4748
if (!$siteData instanceof Site) {
4849
$siteData = $this->getSite($site);
4950
if (!$siteData instanceof Site) {
@@ -55,8 +56,10 @@ public function clone($site) : string
5556
}
5657

5758
$env = $siteData->getEnvironments()->get('dev');
59+
5860
$clone_path = $siteData->getLocalCopyFolder();
5961
$connection = $env->connectionInfo();
62+
6063
if (!is_dir($clone_path . DIRECTORY_SEPARATOR . ".git")) {
6164
$this->execute(
6265
"git clone %s %s",

src/Commands/Local/CommitAndPushCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CommitAndPushCommand extends TerminusCommand implements SiteAwareInterface
3131
*
3232
* @authorize
3333
*
34-
* @command local:clone
34+
* @command local:commitAndPush
3535
* @aliases lc
3636
*
3737
* @param string $site Site

src/Commands/Local/GetLiveDBCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,6 @@ public function downloadLiveDbBackup($site, $options = ['overwrite' => false])
121121
$db_local_filename
122122
);
123123
$this->logger->notice("DB Backup Downloaded to: {path}", ["path" => $db_local_filename]);
124+
return $db_local_filename;
124125
}
125126
}

src/Commands/Local/GetLiveFilesCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,6 @@ public function downloadLiveFilesBackup($site, $options = ['overwrite' => false]
124124
throw new TerminusException("Cannot download backup file.");
125125
}
126126
$this->logger->notice("Files Backup Downloaded to: {path}", ["path" => $files_local_filename]);
127+
return $files_local_filename;
127128
}
128129
}

tests/Functional/LocalCommandsTest.php

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,61 @@ public function setUp(): void
4242
public function testLocalClone()
4343
{
4444
$sitename = getenv('TERMINUS_SITE');
45-
$local_sites_folder = realpath(getenv('TERMINUS_LOCAL_SITES')) . DIRECTORY_SEPARATOR .
46-
'pantheon-local-copies';
47-
$willBeCreated = $local_sites_folder . DIRECTORY_SEPARATOR . $sitename;
48-
$this->terminus("local:clone {$sitename}", null);
49-
$this->assertTrue(is_dir($willBeCreated));
45+
$result = $this->terminus("local:clone {$sitename}", null);
46+
if (!is_string($result)) {
47+
throw new \Exception("The response from the local clone command didn't return the path.");
48+
}
49+
$shouldExist = $result . DIRECTORY_SEPARATOR . '.git';
50+
$this->assertTrue(
51+
is_dir($shouldExist),
52+
"The sites .git directory does not exist: {$shouldExist}"
53+
);
5054
}
5155

5256
/**
5357
* @test
54-
* @covers \Pantheon\Terminus\Commands\Local\CommitAndPushCommand
55-
* @covers \Pantheon\Terminus\Commands\Local\GetLiveFilesCommand
5658
* @covers \Pantheon\Terminus\Commands\Local\GetLiveDBCommand
5759
*
5860
* @group local
5961
* @gropu long
6062
*/
61-
public function testCommitDbFiles()
63+
public function testCommitDb()
64+
{
65+
$sitename = getenv('TERMINUS_SITE');
66+
$result = $this->terminus("local:getLiveDB {$sitename}.live");
67+
$this->assertTrue(
68+
is_file($result),
69+
"The db file failed to download."
70+
);
71+
}
72+
73+
/**
74+
* @test
75+
* @covers \Pantheon\Terminus\Commands\Local\GetLiveFilesCommand
76+
*
77+
* @group local
78+
* @gropu long
79+
*/
80+
public function testCommitFiles()
6281
{
63-
$this->fail("To Be Written");
82+
$sitename = getenv('TERMINUS_SITE');
83+
$result = $this->terminus("local:getLiveFiles {$sitename}.live");
84+
$this->assertTrue(
85+
is_file($result),
86+
'The site file failed to download.'
87+
);
6488
}
6589

6690
/**
6791
* @after
6892
*/
6993
public function tearDown(): void
7094
{
71-
$local_sites_folder = realpath(getenv('TERMINUS_LOCAL_SITES')) . DIRECTORY_SEPARATOR .
72-
'pantheon-local-copies';
73-
if (is_dir($local_sites_folder)) {
74-
exec("rm -Rf {$local_sites_folder}");
95+
$sitename = getenv('TERMINUS_SITE');
96+
$local_site_folder = realpath(getenv('TERMINUS_LOCAL_SITES')) . DIRECTORY_SEPARATOR .
97+
'pantheon-local-copies' . DIRECTORY_SEPARATOR . $sitename;
98+
if (is_dir($local_site_folder)) {
99+
exec("rm -Rf {$local_site_folder}");
75100
}
76101
}
77102
}

tests/config/behat.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ default:
2222
machine_token_id: 'dcr_q4tFMiYiK9DfJO15'
2323
cache_dir: '[[system_temp]]/.terminus/cache'
2424
executable: 'bin/t3'
25+
local_copies: '~/pantheon-local-copies'

0 commit comments

Comments
 (0)