-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from deliciousbrains/list-sites-command
List sites command
- Loading branch information
Showing
5 changed files
with
172 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Commands\Sites; | ||
|
||
use App\Commands\BaseCommand; | ||
|
||
class ListCommand extends BaseCommand | ||
{ | ||
protected $signature = 'sites:list {server_id? : Only list sites belonging to this server} {--format=} {--profile=}'; | ||
|
||
protected $description = 'Retrieves a list of sites'; | ||
|
||
protected function action() | ||
{ | ||
$serverId = $this->argument('server_id'); | ||
|
||
if ($serverId) { | ||
$sites = collect($this->spinupwp->sites->listForServer((int) $serverId)); | ||
} else { | ||
$sites = collect($this->spinupwp->sites->list()); | ||
} | ||
|
||
if ($this->displayFormat() === 'json') { | ||
return $sites; | ||
} | ||
|
||
return $sites->map(fn ($site) => [ | ||
'ID' => $site->id, | ||
'Server ID' => $site->server_id, | ||
'Domain' => $site->domain, | ||
'Site User' => $site->site_user, | ||
'PHP' => $site->php_version, | ||
'Page Cache' => $site->page_cache['enabled'], | ||
'HTTPS' => $site->https['enabled'], | ||
]); | ||
} | ||
} |
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,80 @@ | ||
<?php | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
|
||
$response = [ | ||
[ | ||
'id' => 1, | ||
'server_id' => 1, | ||
'domain' => 'hellfishmedia.com', | ||
'site_user' => 'hellfish', | ||
'php_version' => '8.0', | ||
'page_cache' => [ | ||
'enabled' => true, | ||
], | ||
'https' => [ | ||
'enabled' => true, | ||
], | ||
], | ||
[ | ||
'id' => 2, | ||
'server_id' => 2, | ||
'domain' => 'staging.hellfishmedia.com', | ||
'site_user' => 'staging-hellfish', | ||
'php_version' => '8.0', | ||
'page_cache' => [ | ||
'enabled' => false, | ||
], | ||
'https' => [ | ||
'enabled' => false, | ||
], | ||
], | ||
]; | ||
beforeEach(function () use ($response) { | ||
setTestConfigFile(); | ||
$this->clientMock->shouldReceive('request')->with('GET', 'sites?page=1', [])->andReturn( | ||
new Response(200, [], json_encode([ | ||
'data' => $response, | ||
])) | ||
); | ||
}); | ||
|
||
afterEach(function () { | ||
deleteTestConfigFile(); | ||
}); | ||
|
||
it('list command with no api token configured', function () { | ||
$this->spinupwp->setApiKey(''); | ||
$this->artisan('sites:list --profile=johndoe') | ||
->assertExitCode(1); | ||
}); | ||
|
||
test('sites json list command', function () use ($response) { | ||
$this->artisan('sites:list')->expectsOutput(json_encode($response, JSON_PRETTY_PRINT)); | ||
}); | ||
|
||
test('sites table list command', function () { | ||
$this->artisan('sites:list --format table')->expectsTable( | ||
['ID', 'Server ID', 'Domain', 'Site User', 'PHP', 'Page Cache', 'HTTPS'], | ||
[ | ||
[ | ||
1, | ||
1, | ||
'hellfishmedia.com', | ||
'hellfish', | ||
'8.0', | ||
'Y', | ||
'Y', | ||
], | ||
[ | ||
2, | ||
2, | ||
'staging.hellfishmedia.com', | ||
'staging-hellfish', | ||
'8.0', | ||
'N', | ||
'N', | ||
], | ||
] | ||
); | ||
}); |