Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Collections/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ public function filterByName($regex = '(.*)')
return $this->filterByRegex('name', $regex);
}

/**
* Filters the members of this collection by their label.
*
* @param string $regex
* Non-delimited PHP regex to filter site names by
*
* @return Sites
*/
public function filterByLabel($regex = '(.*)')
{
return $this->filterByRegex('label', $regex);
}

/**
* Filters an array of sites by the plan name.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/Org/Site/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ class ListCommand extends TerminusCommand implements SiteAwareInterface
*
* @field-labels
* name: Name
* label: Label
* id: ID
* plan_name: Plan
* framework: Framework
* owner: Owner
* created: Created
* tags: Tags
* frozen: Is Frozen?
* @default-fields name,id,plan_name,framework,owner,created,tags,frozen
* @return RowsOfFields
*
* @param string $organization Organization name, label, or ID
Expand Down
1 change: 1 addition & 0 deletions src/Commands/Site/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ListCommand extends SiteCommand
*
* @field-labels
* name: Name
* label: Label
* id: ID
* plan_name: Plan
* framework: Framework
Expand Down
79 changes: 79 additions & 0 deletions tests/Functional/OrgCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,85 @@ public function testOrgSiteListCommand()
);
}

/**
* @test
* @covers \Pantheon\Terminus\Commands\Org\Site\ListCommand
*
* @group org
* @group short
*/
public function testOrgSiteListCommandWithLabelField()
{
$orgSites = $this->terminusJsonResponse(
sprintf(
"org:site:list --fields=id,label %s",
$this->getOrg()
)
);
$this->assertIsArray(
$orgSites,
"Response from org list should be an array of orgs"
);
$site = array_shift($orgSites);

$this->assertIsArray(
$site,
"row from org list array of orgs should be an org item"
);
$this->assertArrayHasKey(
'id',
$site,
"Sites from org list should have an id property"
);
$this->assertArrayHasKey(
'label',
$site,
"Sites from org list should have a label property"
);
}

/**
* @test
* @covers \Pantheon\Terminus\Commands\Org\Site\ListCommand
*
* @group org
* @group short
*/
public function testOrgSiteListCommandWithLabelFilter()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I'm the one that asked for stuff to be broken out to more cases— consider whether every assertion still should be in the subsequent filter test or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this comment is stale, but the 4 assertions i see below all look reasonable to me, especially considering that none of their arguments include method calls so on the surface it appears that they should all be very computationally inexpensive.

{
$partial_site_name = substr($this->getSiteName(), 0, -1);
$orgSites = $this->terminusJsonResponse(
sprintf(
"org:site:list --fields=id,label --filter='label*=%s' %s",
$partial_site_name,
$this->getOrg()
)
);
$this->assertIsArray(
$orgSites,
"Response from org list should be an array of orgs"
);

$this->assertGreaterThan(0, count($orgSites));

$site = array_shift($orgSites);

$this->assertIsArray(
$site,
"row from org list array of orgs should be an org item"
);
$this->assertArrayHasKey(
'id',
$site,
"Sites from org list should have an id property"
);
$this->assertArrayHasKey(
'label',
$site,
"Sites from org list should have a name property"
);
}

/**
* @test
* @covers \Pantheon\Terminus\Commands\Org\Upstream\ListCommand
Expand Down
41 changes: 41 additions & 0 deletions tests/Functional/SiteCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,47 @@ public function testSiteListCommand()
$this->assertArrayHasKey('memberships', $site);
}

/**
* @test
* @covers \Pantheon\Terminus\Commands\Site\ListCommand
*
* @group site
* @group short
*/
public function testSiteListCommandWithLabelField()
{
$siteList = $this->terminusJsonResponse(sprintf('site:list --org=%s --fields=id,label', $this->getOrg()));
$this->assertIsArray($siteList);
$this->assertGreaterThan(0, count($siteList));

$site = array_shift($siteList);
$this->assertArrayHasKey('id', $site);
$this->assertArrayHasKey('label', $site);
}

/**
* @test
* @covers \Pantheon\Terminus\Commands\Site\ListCommand
*
* @group site
* @group short
*/
public function testSiteListCommandWithLabelFilter()
{
$partial_site_name = substr($this->getSiteName(), 0, -1);
$siteList = $this->terminusJsonResponse(sprintf(
'site:list --org=%s --fields=id,label --filter=\'label*=%s\'',
$this->getOrg(),
$partial_site_name
));
$this->assertIsArray($siteList);
$this->assertGreaterThan(0, count($siteList));

$site = array_shift($siteList);
$this->assertArrayHasKey('id', $site);
$this->assertArrayHasKey('label', $site);
}

/**
* @test
* @covers \Pantheon\Terminus\Commands\Site\Org\ListCommand
Expand Down
Loading