Skip to content

Commit

Permalink
Changed self:cc to remove cached command files
Browse files Browse the repository at this point in the history
  • Loading branch information
tesladethray committed Jan 30, 2017
1 parent f840c33 commit 5523283
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 114 deletions.
137 changes: 69 additions & 68 deletions composer.lock

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions config/constants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@
---

# App
TERMINUS_VERSION: '1.0.0'
TERMINUS_VERSION: '1.0.0'

# Connectivity
TERMINUS_HOST: 'terminus.pantheon.io'
TERMINUS_PORT: 443
TERMINUS_PROTOCOL: 'https'
TERMINUS_SSH_HOST: null
TERMINUS_HOST: 'terminus.pantheon.io'
TERMINUS_PORT: 443
TERMINUS_PROTOCOL: 'https'
TERMINUS_SSH_HOST: null

# User Prompts
TERMINUS_DASHBOARD_HOST: 'dashboard.pantheon.io'
TERMINUS_DASHBOARD_PROTOCOL: 'https'

# Localization
TERMINUS_DATE_FORMAT: 'Y-m-d H:i:s'
TERMINUS_TIME_ZONE: 'UTC'
TERMINUS_DATE_FORMAT: 'Y-m-d H:i:s'
TERMINUS_TIME_ZONE: 'UTC'

# File Storage
TERMINUS_CACHE_DIR: '[[ TERMINUS_USER_HOME ]]/.terminus/cache'
TERMINUS_PLUGINS_DIR: '[[ TERMINUS_USER_HOME ]]/.terminus/plugins'
TERMINUS_TOKENS_DIR: '[[ TERMINUS_CACHE_DIR ]]/tokens'
TERMINUS_ASSETS_DIR: '[[ TERMINUS_ROOT ]]/assets'
TERMINUS_TEMPLATES_DIR: '[[ TERMINUS_ROOT ]]/templates'
TERMINUS_CACHE_DIR: '[[ TERMINUS_USER_HOME ]]/.terminus/cache'
TERMINUS_PLUGINS_DIR: '[[ TERMINUS_USER_HOME ]]/.terminus/plugins'
TERMINUS_COMMAND_CACHE_DIR: '[[ TERMINUS_CACHE_DIR ]]/commands'
TERMINUS_TOKENS_DIR: '[[ TERMINUS_CACHE_DIR ]]/tokens'
TERMINUS_ASSETS_DIR: '[[ TERMINUS_ROOT ]]/assets'

# Helpers
TERMINUS_USER: null
TERMINUS_SITE: null
TERMINUS_ENV: null
TERMINUS_ORG: null
TERMINUS_USER: null
TERMINUS_SITE: null
TERMINUS_ENV: null
TERMINUS_ORG: null

# Testing
TERMINUS_TEST_MODE: false
TERMINUS_VCR_CASSETTE: null
TERMINUS_VCR_MODE: null
TERMINUS_TEST_MODE: false
TERMINUS_VCR_CASSETTE: null
TERMINUS_VCR_MODE: null

# Set by Terminus - DO NOT USE
# Terminus
Expand Down
3 changes: 3 additions & 0 deletions src/Collections/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public function fetch(array $arg_options = [])

if (!$options['team_only']) {
$memberships = $this->getUser()->getOrgMemberships()->fetch()->all();
if (is_null($memberships)) {
$memberships = [];
}
if (!is_null($org_id = $options['org_id']) && ($org_id != 'all')) {
$memberships = array_filter($memberships, function ($membership) use ($org_id) {
return $membership->id == $org_id;
Expand Down
14 changes: 13 additions & 1 deletion src/Commands/Self/ClearCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
use League\Container\ContainerAwareInterface;
use League\Container\ContainerAwareTrait;
use Pantheon\Terminus\Commands\TerminusCommand;
use Pantheon\Terminus\Helpers\LocalMachineHelper;
use Robo\Common\ConfigAwareTrait;
use Robo\Contract\ConfigAwareInterface;

/**
* Class ClearCacheCommand
* @package Pantheon\Terminus\Commands\Self
*/
class ClearCacheCommand extends TerminusCommand implements ContainerAwareInterface
class ClearCacheCommand extends TerminusCommand implements ConfigAwareInterface, ContainerAwareInterface
{
use ConfigAwareTrait;
use ContainerAwareTrait;

/**
Expand All @@ -24,6 +28,14 @@ class ClearCacheCommand extends TerminusCommand implements ContainerAwareInterfa
*/
public function clearCache()
{
$local_machine = $this->getContainer()->get(LocalMachineHelper::class);
$fs = $local_machine->getFilesystem();
$finder = $local_machine->getFinder();

$finder->files()->in($this->getConfig()->get('command_cache_dir'));
foreach ($finder as $file) {
$fs->remove($file);
}
$this->log()->notice('The local Terminus cache has been cleared.');
}
}
12 changes: 12 additions & 0 deletions src/Helpers/LocalMachineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Robo\Common\ConfigAwareTrait;
use Robo\Contract\ConfigAwareInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Process\Process;

/**
Expand Down Expand Up @@ -66,6 +67,17 @@ public function getFilesystem()
return new Filesystem();
}

/**
* Returns a finder object
*
* @return Finder
*/
public function getFinder()
{
return new Finder();
}

/**
/**
* Opens the given URL in a browser on the local machine.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Terminus.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private function configureContainer()
->invokeMethod('setSites', ['sites']);

// Install our command cache into the command factory
$commandCacheDir = $this->getConfig()->get('cache_dir') . '/commands';
$commandCacheDir = $this->getConfig()->get('command_cache_dir');
$commandCacheDataStore = new FileStore($commandCacheDir);

$factory = $container->get('commandFactory');
Expand Down
10 changes: 5 additions & 5 deletions tests/features/multidev-list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Feature: Listing a site's environments
@vcr site-info.yml
Scenario: Listing all multidev environments belonging to a site
When I run "terminus multidev:list [[test_site_name]]"
Then I should get: "---------- --------------------- -------------------------------------- --------------- --------- --------------"
And I should get: "Name Created Domain OnServer Dev? Locked? Initialized?"
And I should get: "---------- --------------------- -------------------------------------- --------------- --------- --------------"
And I should get: "multidev 2016-08-16 22:09:01 multidev-behat-tests.pantheonsite.io true false true"
And I should get: "---------- --------------------- -------------------------------------- --------------- --------- --------------"
Then I should get: "---------- ------------------ -------------------------------------- --------------- --------- --------------"
And I should get: "Name Created Domain OnServer Dev? Locked? Initialized?"
And I should get: "---------- ------------------ -------------------------------------- --------------- --------- --------------"
And I should get: "multidev 2016-08-16 15:09 multidev-behat-tests.pantheonsite.io true false true"
And I should get: "---------- ------------------ -------------------------------------- --------------- --------- --------------"
32 changes: 16 additions & 16 deletions tests/features/site-list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ Feature: Listing sites
Scenario: Listing a user's sites when they haven't any
When I run "terminus site:list"
Then I should get: "You have no sites."
And I should get: "------ ---- --------------- ----------- ------- --------- -------------"
And I should get: "Name ID Service Level Framework Owner Created Memberships"
And I should get: "------ ---- --------------- ----------- ------- --------- -------------"
And I should get: "------ ---- --------------- ----------- ------- --------- ------------- ------------"
And I should get: "Name ID Service Level Framework Owner Created Memberships Is Frozen?"
And I should get: "------ ---- --------------- ----------- ------- --------- ------------- ------------"

@vcr site-list.yml
Scenario: Listing a user's sites
Given a site named "[[test_site_name]]"
When I run "terminus site:list --owner=me"
Then I should get: "------------- -------------------------------------- --------------- ----------- -------------------------------------- --------------------- --------------------------------------------"
And I should get: "Name ID Service Level Framework Owner Created Memberships"
And I should get: "------------- -------------------------------------- --------------- ----------- -------------------------------------- --------------------- --------------------------------------------"
And I should get: "[[test_site_name]] 11111111-1111-1111-1111-111111111111 free wordpress 11111111-1111-1111-1111-111111111111 2016-08-16 22:09:01 11111111-1111-1111-1111-111111111111: Team"
And I should get: "------------- -------------------------------------- --------------- ----------- -------------------------------------- --------------------- --------------------------------------------"
Then I should get: "------------- -------------------------------------- --------------- ----------- -------------------------------------- ------------------ -------------------------------------------- ------------"
And I should get: "Name ID Service Level Framework Owner Created Memberships Is Frozen?"
And I should get: "------------- -------------------------------------- --------------- ----------- -------------------------------------- ------------------ -------------------------------------------- ------------"
And I should get: "behat-tests 11111111-1111-1111-1111-111111111111 free wordpress 11111111-1111-1111-1111-111111111111 2016-08-16 15:09 11111111-1111-1111-1111-111111111111: Team false"
And I should get: "------------- -------------------------------------- --------------- ----------- -------------------------------------- ------------------ -------------------------------------------- ------------"

@vcr site-list.yml
Scenario: Filter sites list by name
Given a site named "[[test_site_name]]"
When I run "terminus site:list --name=[[test_site_name]]"
Then I should get: "------------- -------------------------------------- --------------- ----------- -------------------------------------- --------------------- --------------------------------------------"
And I should get: "Name ID Service Level Framework Owner Created Memberships"
And I should get: "------------- -------------------------------------- --------------- ----------- -------------------------------------- --------------------- --------------------------------------------"
And I should get: "[[test_site_name]] 11111111-1111-1111-1111-111111111111 free wordpress 11111111-1111-1111-1111-111111111111 2016-08-16 22:09:01 11111111-1111-1111-1111-111111111111: Team"
And I should get: "------------- -------------------------------------- --------------- ----------- -------------------------------------- --------------------- --------------------------------------------"
Then I should get: "------------- -------------------------------------- --------------- ----------- -------------------------------------- ------------------ -------------------------------------------- ------------"
And I should get: "Name ID Service Level Framework Owner Created Memberships Is Frozen?"
And I should get: "------------- -------------------------------------- --------------- ----------- -------------------------------------- ------------------ -------------------------------------------- ------------"
And I should get: "behat-tests 11111111-1111-1111-1111-111111111111 free wordpress 11111111-1111-1111-1111-111111111111 2016-08-16 15:09 11111111-1111-1111-1111-111111111111: Team false"
And I should get: "------------- -------------------------------------- --------------- ----------- -------------------------------------- ------------------ -------------------------------------------- ------------"

@vcr site-list.yml
Scenario: Filter sites list by name, excluding the test site
Given a site named "[[test_site_name]]"
When I run "terminus site:list --name=missing"
Then I should get: "You have no sites."
And I should get: "------ ---- --------------- ----------- ------- --------- -------------"
And I should get: "Name ID Service Level Framework Owner Created Memberships"
And I should get: "------ ---- --------------- ----------- ------- --------- -------------"
And I should get: "------ ---- --------------- ----------- ------- --------- ------------- ------------"
And I should get: "Name ID Service Level Framework Owner Created Memberships Is Frozen?"
And I should get: "------ ---- --------------- ----------- ------- --------- ------------- ------------"
95 changes: 91 additions & 4 deletions tests/unit_tests/Commands/Self/ClearCacheCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

namespace Pantheon\Terminus\UnitTests\Commands\Self;

use League\Container\Container;
use Pantheon\Terminus\Commands\Self\ClearCacheCommand;
use Pantheon\Terminus\Config\TerminusConfig;
use Pantheon\Terminus\Helpers\LocalMachineHelper;
use Pantheon\Terminus\UnitTests\Commands\CommandTestCase;
use phpDocumentor\Reflection\File;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\Tests\Iterator\Iterator;

/**
* Class ClearCacheCommandTest
Expand All @@ -12,21 +19,101 @@
*/
class ClearCacheCommandTest extends CommandTestCase
{
/**
* @var TerminusConfig
*/
protected $config;
/**
* @var Filesystem
*/
protected $filesystem;
/**
* @var Finder
*/
protected $finder;

/**
* @inheritdoc
*/
public function setUp()
{
parent::setUp();

$container = $this->getMockBuilder(Container::class)
->disableOriginalConstructor()
->getMock();
$local_machine = $this->getMockBuilder(LocalMachineHelper::class)
->disableOriginalConstructor()
->getMock();
$this->config = $this->getMockBuilder(TerminusConfig::class)
->disableOriginalConstructor()
->getMock();
$this->filesystem = $this->getMockBuilder(Filesystem::class)
->disableOriginalConstructor()
->getMock();
$this->finder = $this->getMockBuilder(Finder::class)
->disableOriginalConstructor()
->getMock();

$container->expects($this->once())
->method('get')
->with($this->equalTo(LocalMachineHelper::class))
->willReturn($local_machine);
$local_machine->expects($this->once())
->method('getFilesystem')
->with()
->willReturn($this->filesystem);
$local_machine->expects($this->once())
->method('getFinder')
->with()
->willReturn($this->finder);
$this->finder->expects($this->once())
->method('files')
->with()
->willReturn($this->finder);

$this->command = new ClearCacheCommand();
$this->command->setLogger($this->logger);
$this->command->setContainer($container);
$this->command->setConfig($this->config);
}

/**
* Tests the self:clear-cache command
*/
public function testClearCache()
{
$dir_name = 'some dir';
$dirs = ['dir1', 'dir2', 'dir3', 'dir4',];
$iterator = new Iterator($dirs);

$this->config->expects(($this->once()))
->method('get')
->with($this->equalTo('command_cache_dir'))
->willReturn($dir_name);
$this->finder->expects($this->once())
->method('in')
->with($this->equalTo($dir_name))
->willReturn($this->finder);
$this->finder->expects($this->once())
->method('getIterator')
->with()
->willReturn($iterator);

for ($i = 0; $i < count($dirs); $i++) {
$this->filesystem->expects($this->at($i))
->method('remove')
->with($this->equalTo($dirs[$i]));
}

$this->logger->expects($this->once())
->method('log')
->with(
$this->equalTo('notice'),
$this->equalTo('The local Terminus cache has been cleared.')
);

$command = new ClearCacheCommand();
$command->setLogger($this->logger);

$command->clearCache();
$out = $this->command->clearCache();
$this->assertNull($out);
}
}

0 comments on commit 5523283

Please sign in to comment.