Skip to content

Commit

Permalink
Merge pull request #31 from madewithlove/share
Browse files Browse the repository at this point in the history
Add share functionality
  • Loading branch information
WouterSioen committed Jan 6, 2020
2 parents 2505b7c + 2d0f5e0 commit 28d0806
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -63,6 +63,7 @@ The following options are available:
-r, --referrer[=REFERRER] The referrer header, used as HTTP_REFERER in apache
-s, --server-name[=SERVER-NAME] The configured server name, used as SERVER_NAME in apache
-e, --expected-url[=EXPECTED-URL] When configured, errors when the output url does not equal this url
--share When passed, you'll receive a share url for your test run
-h, --help Display a help message
```

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -6,7 +6,7 @@
"symfony/console": "^3.0 || ^4.0 || ^5.0",
"php-http/guzzle6-adapter": "^2.0",
"http-interop/http-factory-guzzle": "^1.0",
"madewithlove/htaccess-api-client": "^1.2"
"madewithlove/htaccess-api-client": "^1.3"
},
"bin": [
"bin/htaccess"
Expand Down
16 changes: 16 additions & 0 deletions src/HtaccessCommand.php
Expand Up @@ -32,6 +32,7 @@ protected function configure()
$this->addOption('referrer', 'r', InputOption::VALUE_OPTIONAL, 'The referrer header, used as HTTP_REFERER in apache');
$this->addOption('server-name', 's', InputOption::VALUE_OPTIONAL, 'The configured server name, used as SERVER_NAME in apache');
$this->addOption('expected-url', 'e', InputOption::VALUE_OPTIONAL, 'When configured, errors when the output url does not equal this url');
$this->addOption('share', null, InputOption::VALUE_NONE, 'When passed, you\'ll receive a share url for your test run');
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand Down Expand Up @@ -82,6 +83,21 @@ function (ResultLine $resultLine): array {
)
);

if ($input->getOption('share')) {
try {
$share = $this->htaccessClient->share(
$url,
$htaccess,
$input->getOption('referrer'),
$input->getOption('server-name')
);

$io->text('You can share this test run on ' . $share->getShareUrl());
} catch (HtaccessException $exception) {
// when sharing failed, just ignore it
}
}

if ($input->getOption('expected-url') && $result->getOutputUrl() !== $input->getOption('expected-url')) {
$io->error('The output url is "' . $result->getOutputUrl() . '", while we expected "' . $input->getOption('expected-url') . '"');

Expand Down

0 comments on commit 28d0806

Please sign in to comment.