Skip to content

Commit bbdf0b3

Browse files
authored
Throw exception for unparseable URLs (#22)
1 parent 20bab4d commit bbdf0b3

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Models/Request.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Shift\CurlConverter\Models;
44

55
use Illuminate\Support\Str;
6+
use InvalidArgumentException;
67

78
class Request
89
{
@@ -36,6 +37,10 @@ public static function create(array $data): self
3637
{
3738
$url = parse_url($data['url']);
3839

40+
if ($url === false) {
41+
throw new InvalidArgumentException(sprintf('The "%s" URL is invalid.', $data['url']));
42+
}
43+
3944
$request = new self(self::buildUrl($url), $data['method'] ?? 'GET');
4045

4146
if (isset($url['query'])) {

tests/Feature/Console/Commands/CurlCommandTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tests\Feature\Console\Commands;
44

55
use Illuminate\Support\Facades\Artisan;
6+
use InvalidArgumentException;
67
use Tests\TestCase;
78

89
class CurlCommandTest extends TestCase
@@ -20,6 +21,14 @@ public function it_converts_curl_requests_to_http_client_code($fixture)
2021
$this->assertSame($this->fixture($fixture . '.out'), $output);
2122
}
2223

24+
public function test_it_throw_exception_when_for_invalid_url()
25+
{
26+
$this->expectException(InvalidArgumentException::class);
27+
$this->expectExceptionMessage('The "https://{domain:port}/api/{id}/" URL is invalid.');
28+
29+
Artisan::call('shift:curl -X GET "https://{domain:port}/api/{id}/"');
30+
}
31+
2332
public function curlCommandFixtures()
2433
{
2534
return [

0 commit comments

Comments
 (0)