forked from laravel-shift/curl-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurlCommandTest.php
More file actions
77 lines (67 loc) · 3.26 KB
/
CurlCommandTest.php
File metadata and controls
77 lines (67 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Tests\Feature\Console\Commands;
use Illuminate\Support\Facades\Artisan;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
final class CurlCommandTest extends TestCase
{
#[Test]
#[DataProvider('curlCommandFixtures')]
public function it_converts_curl_requests_to_http_client_code($fixture): void
{
$code = Artisan::call('shift:' . $this->fixture($fixture . '.in'));
$output = trim(Artisan::output());
$this->assertSame(0, $code);
$this->assertSame($this->fixture($fixture . '.out'), $output);
}
public function test_it_throw_exception_when_for_invalid_url(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "https://{domain:port}/api/{id}/" URL is invalid.');
Artisan::call('shift:curl -X GET "https://{domain:port}/api/{id}/"');
}
public function test_it_throw_exception_when_for_invalid_headers(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "foo" header must be a key/value pair separated by ":".');
Artisan::call("shift:curl https://example.com --header 'foo'");
}
public static function curlCommandFixtures(): array
{
return [
'GET request' => ['basic-get'],
'POST request' => ['basic-post'],
'POST request with data' => ['post-with-data'],
'POST request with JSON data' => ['post-json'],
'POST request with multipart/form-data' => ['post-with-form-data'],
'Request with data defaults to POST' => ['request-with-data'],
'Request with form fields defaults to POST' => ['request-with-form-data'],
'Request with collapsable headers' => ['with-collapsable-headers'],
'PUT request with data' => ['put-with-data'],
'GET request with headers' => ['with-headers'],
'GET request with query string' => ['with-query-string'],
'Mailgun example request' => ['mailgun-example'],
'Digital Ocean example request' => ['digital-ocean-example'],
'Stripe example request' => ['stripe-example'],
'Stripe query params' => ['stripe-query-params'],
'Initial connection timeout' => ['connect-timeout'],
'Entire transaction timeout' => ['max-timeout'],
'Ignore location flag' => ['ignore-location-flag'],
'Missing URL scheme' => ['missing-url-scheme'],
'GET request with compressed flag' => ['with-compressed-option'],
'GET request with insecure flag' => ['with-insecure-option'],
'GET request with short k flag' => ['with-insecure-k-option'],
'Request with raw data' => ['with-raw-data'],
'POST request with mixed data' => ['raw-data-mixed'],
'Request with cert (path only)' => ['with-cert-path-only'],
'Request with cert (path and password)' => ['with-cert-path-and-password'],
'Request with cert and key' => ['with-cert-and-key'],
];
}
private function fixture(string $fixture)
{
return trim(file_get_contents('tests/fixtures/' . $fixture));
}
}