Skip to content

Commit 620afcd

Browse files
committed
5124: Updated Drush test command
1 parent 221fb5b commit 620afcd

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

web/profiles/custom/os2loop/modules/os2loop_cura_login/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ curl "http://$(docker compose port nginx 8080)/os2loop-cura-login/start"
3737
drush os2loop-cura-login:get-login-url --help
3838
```
3939

40-
``` shell
41-
drush --uri='http://nginx:8080' os2loop-cura-login:get-login-url [email protected] --secret=$(drush config:get --format string os2loop_cura_login.settings signing_secret --include-overridden) --algorithm=$(drush config:get --format string os2loop_cura_login.settings signing_algorithm --include-overridden)
40+
``` shell name=drush-get-login-url
41+
drush --uri='http://nginx:8080' os2loop-cura-login:get-login-url [email protected] \
42+
--algorithm=$(drush config:get --format string os2loop_cura_login.settings cura.signing_algorithm --include-overridden) \
43+
--secret=$(drush config:get --format string os2loop_cura_login.settings cura.signing_secret --include-overridden)
4244
```
4345

4446
## Development and debugging

web/profiles/custom/os2loop/modules/os2loop_cura_login/src/Drush/Commands/Os2loopCuraLoginCommands.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Drupal\Component\Datetime\TimeInterface;
66
use Drupal\Core\DependencyInjection\AutowireTrait;
7+
use Drupal\Core\Serialization\Yaml;
78
use Drupal\Core\Url;
89
use Drush\Attributes as CLI;
910
use Drush\Commands\DrushCommands;
@@ -12,7 +13,7 @@
1213
use Symfony\Component\HttpFoundation\Request;
1314

1415
/**
15-
* A Drush commandfile.
16+
* A Drush command file.
1617
*/
1718
final class Os2loopCuraLoginCommands extends DrushCommands {
1819
use AutowireTrait;
@@ -53,30 +54,32 @@ public function getLoginUrl(
5354
];
5455
$jwt = JWT::encode($payload, $options['secret'], $options['algorithm']);
5556

57+
$routeName = 'os2loop_cura_login.start';
5658
$routeParameters = [];
5759
$requestOptions = [];
5860
if ($name = $options['get']) {
5961
$method = Request::METHOD_GET;
6062
$routeParameters[$name] = $jwt;
63+
if ('jwt' === $name) {
64+
$routeName = 'os2loop_cura_login.start_get_jwt';
65+
}
6166
}
6267
else {
6368
$method = Request::METHOD_POST;
64-
$requestOptions['body'] = ['payload' => $jwt];
69+
$requestOptions['form_params'] = ['payload' => $jwt];
6570
}
66-
$url = Url::fromRoute('os2loop_cura_login.start', $routeParameters)->setAbsolute()->toString(TRUE)->getGeneratedUrl();
71+
$url = Url::fromRoute($routeName, $routeParameters)->setAbsolute()->toString(TRUE)->getGeneratedUrl();
6772
$this->io()->writeln($method === Request::METHOD_POST
6873
? sprintf('POST\'ing to %s', $url)
6974
: sprintf('GET\'ing %s', $url),
7075
);
71-
$request = $this->httpClient->request($method, $url, $requestOptions);
76+
$response = $this->httpClient->request($method, $url, $requestOptions);
7277

73-
header('content-type: text/plain');
74-
echo var_export([
75-
$url,
76-
$request->getStatusCode(),
77-
$request->getBody()->getContents(),
78-
], TRUE);
79-
die(__FILE__ . ':' . __LINE__ . ':' . __METHOD__);
78+
$this->io()->writeln([
79+
$response->getStatusCode(),
80+
Yaml::encode($response->getHeaders()),
81+
$response->getBody()->getContents(),
82+
]);
8083
}
8184

8285
}

0 commit comments

Comments
 (0)