Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OTTO-161] Support directories in --to option for backup:get #2053

Merged
merged 4 commits into from
Jan 28, 2020
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
14 changes: 8 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ All notable changes to this project will be documented in this file. This projec
- The role parameter in `org:people:role` is now being validated before attempting the change. (#2033)
- The role parameter in `site:team:add` is now being validated before attempting the change. (#2033)
- The role parameter in `site:team:role` is now being validated before attempting the change. (#2033)
- `Request::download($url, $target)` now accepts directories in addition to files as its `$target` parameter. (#2053)
- The `backup:get` command's `--to` option now accepts directories in addition to files. (#2053)

### Deprecated
- Deprecated the `--cc` option on `env:deploy`. Please use `env:clear-cache` instead. (#2022)
Expand All @@ -32,7 +34,7 @@ All notable changes to this project will be documented in this file. This projec
- Added `domain:primary:remove` command to remove a domain's primary designation. (#2011)

## 2.1.0 - 2019-09-03
### Added
### Added
- Added `--filter` option to `backup:list` command (#1992)
- Added `--filter` option to `branch:list` command (#1992)
- Added `--filter` option to `domain:list` command (#1992)
Expand All @@ -54,20 +56,20 @@ All notable changes to this project will be documented in this file. This projec
### Deprecated
- `backup:list` `--element=VALUE` option is deprecated. Use `--filter="type=VALUE"` instead. (#1992)
- `site:list` `--framework=VALUE` option is deprecated. Use `--filter="framework=VALUE"` instead. (#1992)
- `site:list` `--name=VALUE` option is deprecated. Use `--filter="name=VALUE"` instead. (#1992)
- `site:list` `--plan=VALUE` option is deprecated. Use `--filter="plan_name=VALUE"` instead. (#1992)
- `site:list` `--name=VALUE` option is deprecated. Use `--filter="name=VALUE"` instead. (#1992)
- `site:list` `--plan=VALUE` option is deprecated. Use `--filter="plan_name=VALUE"` instead. (#1992)
- `org:site:list` `--plan=VALUE` option is deprecated. Use `--filter="plan_name=VALUE"` instead. (#1992)
- `org:site:list` `--tags=VALUE` option is deprecated. Use `--filter="tags=VALUE"` instead. (#1992)
- `org:upstream:list` `--framework=VALUE` option is deprecated. Use `--filter="framework=VALUE"` instead. (#1992)
- `org:upstream:list` `--name=VALUE` option is deprecated. Use `--filter="label=VALUE"` instead. (#1992)
- `org:upstream:list` `--name=VALUE` option is deprecated. Use `--filter="label=VALUE"` instead. (#1992)
- `upstream:list` `--framework=VALUE` option is deprecated. Use `--filter="framework=VALUE"` instead. (#1992)
- `upstream:list` `--name=VALUE` option is deprecated. Use `--filter="label=VALUE"` instead. (#1992)
- `upstream:list` `--name=VALUE` option is deprecated. Use `--filter="label=VALUE"` instead. (#1992)

### Obsolete
- 'pantheon-systems/terminus-aliases-plugin' ignored as load time, as its functionality is now provided in Terminus core. (#1994)
- PHP 5.5 no longer actively supported, as it is EOL, and no longer testable on Travis.

### Changed
### Changed
- `drush:aliases` now produces both Drush 8 and Drush 9 aliases. Wildcard alias records always used (requires Drush 8.3.0 or later). (#1994)
- `site:info`'s value of the `region` field has been changed to use human-readable region names. (#1985)
- `site:list`'s value of the `region` field has been changed to use human-readable region names. (#1985)
Expand Down
10 changes: 9 additions & 1 deletion src/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ class Request implements ConfigAwareInterface, ContainerAwareInterface, LoggerAw
* Download file from target URL
*
* @param string $url URL to download from
* @param string $target Target file's name
* @param string $target Target file or directory's name
* @throws TerminusException
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Can line 54 be updated to mention that you can use a directory now? (Something like "Target file or directory's name")

public function download($url, $target)
{
if (is_dir($target)) {
if (substr($target, -1) == DIRECTORY_SEPARATOR) {
$target = $target . strtok(basename($url), '?');
} else {
$target = $target . DIRECTORY_SEPARATOR . strtok(basename($url), '?');
}
}

if ($this->getContainer()->get(LocalMachineHelper::class)->getFilesystem()->exists($target)) {
throw new TerminusException('Target file {target} already exists.', compact('target'));
}
Expand Down
41 changes: 41 additions & 0 deletions tests/unit_tests/Request/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,47 @@ public function testDownloadPathExists()
$this->assertNull($out);
}

/**
* Tests a successful download with the target being a directory
*/
public function testDownloadTargetDirectory()
{
$domain = 'pantheon.io';
$url = "http://$domain/somefile.tar.gz";
$target = './';
$target_with_file = './somefile.tar.gz';

$this->container->expects($this->at(0))
->method('get')
->with($this->equalTo(LocalMachineHelper::class))
->willReturn($this->local_machine_helper);
$this->local_machine_helper->expects($this->once())
->method('getFilesystem')
->with()
->willReturn($this->filesystem);
$this->filesystem->expects($this->once())
->method('exists')
->with($target_with_file)
->willReturn(false);
$this->container->expects($this->at(1))
->method('get')
->with(
$this->equalTo(Client::class),
$this->equalTo([['base_uri' => $domain, RequestOptions::VERIFY => true,],])
)
->willReturn($this->client);
$this->client->expects($this->once())
->method('request')
->with(
$this->equalTo('GET'),
$this->equalTo($url),
$this->equalTo(['sink' => $target_with_file,])
);

$out = $this->request->download($url, $target);
$this->assertNull($out);
}

public function testRequest()
{
$this->session->method('get')->with('session')->willReturn(false);
Expand Down