Skip to content

Commit

Permalink
System Agnostic Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cholladay0816 committed Mar 10, 2021
1 parent 2ac3f55 commit 683dc0c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
12 changes: 6 additions & 6 deletions tests/Client/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
$jar = CookieJar::fromArray(['Foo' => 'Bar', 'identity' => 'xyz'], 'local.example');
$curl = $this->curlFormatter->format($request, ['cookies' => $jar]);

expect($curl)->not()->toContain("-H 'Host: local.example'");
expect($curl)->toContain("-b 'Foo=Bar; identity=xyz'");
expect(str_replace('"', '\'', $curl))->not()->toContain("-H 'Host: local.example'");
expect(str_replace('"', '\'', $curl))->toContain("-b 'Foo=Bar; identity=xyz'");
});

test('POST', function () {
$request = new Request('POST', 'http://local.example', [], Utils::streamFor('foo=bar&hello=world'));
$curl = $this->curlFormatter->format($request);

expect($curl)->toContain("-d 'foo=bar&hello=world'");
expect(str_replace('"', '\'', $curl))->toContain("-d 'foo=bar&hello=world'");
});

test('PUT', function () {
$request = new Request('PUT', 'http://local.example', [], Utils::streamFor('foo=bar&hello=world'));
$curl = $this->curlFormatter->format($request);

expect($curl)->toContain("-d 'foo=bar&hello=world'");
expect(str_replace('"', '\'', $curl))->toContain("-d 'foo=bar&hello=world'");
expect($curl)->toContain('-X PUT');
});

Expand All @@ -48,12 +48,12 @@
$request = new Request('HEAD', 'http://local.example');
$curl = $this->curlFormatter->format($request);

expect($curl)->toContain("curl 'http://local.example' --head");
expect(str_replace('"', '\'', $curl))->toContain("curl 'http://local.example' --head");
});

test('OPTIONS', function () {
$request = new Request('OPTIONS', 'http://local.example');
$curl = $this->curlFormatter->format($request);

expect($curl)->toContain('-X OPTIONS');
});
});
21 changes: 11 additions & 10 deletions tests/Formatter/CurlFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,47 @@
$request = new Request('GET', 'http://example.local');
$curl = $this->curlFormatter->format($request);

$this->assertEquals("curl 'http://example.local'", $curl);
$this->assertEquals("curl 'http://example.local'", str_replace('"', '\'', $curl));
});

test('simple get', function () {
$request = new Request('GET', 'http://example.local');
$curl = $this->curlFormatter->format($request);

$this->assertEquals("curl 'http://example.local'", $curl);
$this->assertEquals("curl 'http://example.local'", str_replace('"', '\'', $curl));
});

test('simple GET with header', function () {
$request = new Request('GET', 'http://example.local', ['foo' => 'bar']);
$curl = $this->curlFormatter->format($request);

$this->assertEquals("curl 'http://example.local' -H 'foo: bar'", $curl);
$this->assertEquals("curl 'http://example.local' -H 'foo: bar'", str_replace('"', '\'', $curl));
});

test('simple GET with multiple header', function () {
$request = new Request('GET', 'http://example.local', ['foo' => 'bar', 'Accept-Encoding' => 'gzip,deflate,sdch']);
$curl = $this->curlFormatter->format($request);

$this->assertEquals("curl 'http://example.local' -H 'foo: bar' -H 'Accept-Encoding: gzip,deflate,sdch'", $curl);
$this->assertEquals("curl 'http://example.local' -H 'foo: bar' -H 'Accept-Encoding: gzip,deflate,sdch'", str_replace('"', '\'', $curl));
});

test('GET With Query String', function () {
$request = new Request('GET', 'http://example.local?foo=bar');
$curl = $this->curlFormatter->format($request);

$this->assertEquals("curl 'http://example.local?foo=bar'", $curl);
$this->assertEquals("curl 'http://example.local?foo=bar'", str_replace('"', '\'', $curl));

$request = new Request('GET', 'http://example.local?foo=bar');
$curl = $this->curlFormatter->format($request);

$this->assertEquals("curl 'http://example.local?foo=bar'", $curl);
$this->assertEquals("curl 'http://example.local?foo=bar'", str_replace('"', '\'', $curl));

$body = Utils::streamFor(http_build_query(['foo' => 'bar', 'hello' => 'world'], '', '&'));

$request = new Request('GET', 'http://example.local',[],$body);
$curl = $this->curlFormatter->format($request);

$this->assertEquals("curl 'http://example.local' -G -d 'foo=bar&hello=world'",$curl);
$this->assertEquals("curl 'http://example.local' -G -d 'foo=bar&hello=world'", str_replace('"', '\'', $curl));
});

test('POST', function () {
Expand All @@ -71,7 +71,8 @@
$curl = $this->curlFormatter->format($request);

expect($curl)->not()->toContain(" -G ");
expect($curl)->toContain("-d 'foo=bar&hello=world'");
expect(str_replace('"', '\'', $curl))->toContain("-d 'foo=bar&hello=world'");

});

test('large POST request', function () {
Expand Down Expand Up @@ -110,15 +111,15 @@
$request = new Request('PUT', 'http://example.local', [], Utils::streamFor('foo=bar&hello=world'));
$curl = $this->curlFormatter->format($request);

expect($curl)->toContain("-d 'foo=bar&hello=world'");
expect(str_replace('"', '\'', $curl))->toContain("-d 'foo=bar&hello=world'");
expect($curl)->toContain("-X PUT");
});

test('proper body relative', function () {
$request = new Request('PUT', 'http://example.local', [], Utils::streamFor('foo=bar&hello=world'));
$curl = $this->curlFormatter->format($request);

expect($curl)->toContain("-d 'foo=bar&hello=world'");
expect(str_replace('"', '\'', $curl))->toContain("-d 'foo=bar&hello=world'");
expect($curl)->toContain("-X PUT");
});

Expand Down

0 comments on commit 683dc0c

Please sign in to comment.