Fix Unit test errors, correct logic

pull/620/head
n0nag0n 2 weeks ago
parent 1b57f9eb2b
commit ce088c86dc

@ -211,10 +211,8 @@ class Request
$this->data->setData($data); $this->data->setData($data);
} }
} }
} // Check PUT, PATCH, DELETE for application/x-www-form-urlencoded data
} else if (in_array($this->method, [ 'PUT', 'DELETE', 'PATCH' ], true) === true) {
// Check PUT, PATCH, DELETE for data
if ($this->method === 'PUT' || $this->method === 'DELETE' || $this->method === 'PATCH') {
$body = $this->getBody(); $body = $this->getBody();
if ($body !== '') { if ($body !== '') {
$data = []; $data = [];

@ -162,7 +162,8 @@ class RequestTest extends TestCase
'url' => '/vagrant/public/flightphp', 'url' => '/vagrant/public/flightphp',
'base' => '/vagrant/public', 'base' => '/vagrant/public',
'query' => new Collection(), 'query' => new Collection(),
'type' => '' 'type' => '',
'method' => 'GET'
]); ]);
$this->assertEquals('/flightphp', $request->url); $this->assertEquals('/flightphp', $request->url);
} }
@ -172,7 +173,8 @@ class RequestTest extends TestCase
$request = new Request([ $request = new Request([
'url' => '', 'url' => '',
'base' => '/vagrant/public', 'base' => '/vagrant/public',
'type' => '' 'type' => '',
'method' => 'GET'
]); ]);
$this->assertEquals('/', $request->url); $this->assertEquals('/', $request->url);
} }
@ -183,7 +185,6 @@ class RequestTest extends TestCase
$tmpfile = tmpfile(); $tmpfile = tmpfile();
$stream_path = stream_get_meta_data($tmpfile)['uri']; $stream_path = stream_get_meta_data($tmpfile)['uri'];
file_put_contents($stream_path, '{"foo":"bar"}'); file_put_contents($stream_path, '{"foo":"bar"}');
$_SERVER['REQUEST_METHOD'] = 'POST';
$request = new Request([ $request = new Request([
'url' => '/something/fancy', 'url' => '/something/fancy',
'base' => '/vagrant/public', 'base' => '/vagrant/public',
@ -191,12 +192,36 @@ class RequestTest extends TestCase
'length' => 13, 'length' => 13,
'data' => new Collection(), 'data' => new Collection(),
'query' => new Collection(), 'query' => new Collection(),
'stream_path' => $stream_path 'stream_path' => $stream_path,
'method' => 'POST'
]); ]);
$this->assertEquals([ 'foo' => 'bar' ], $request->data->getData()); $this->assertEquals([ 'foo' => 'bar' ], $request->data->getData());
$this->assertEquals('{"foo":"bar"}', $request->getBody()); $this->assertEquals('{"foo":"bar"}', $request->getBody());
} }
public function testInitWithFormBody()
{
// create dummy file to pull request body from
$tmpfile = tmpfile();
$stream_path = stream_get_meta_data($tmpfile)['uri'];
file_put_contents($stream_path, 'foo=bar&baz=qux');
$request = new Request([
'url' => '/something/fancy',
'base' => '/vagrant/public',
'type' => 'application/x-www-form-urlencoded',
'length' => 15,
'data' => new Collection(),
'query' => new Collection(),
'stream_path' => $stream_path,
'method' => 'PATCH'
]);
$this->assertEquals([
'foo' => 'bar',
'baz' => 'qux'
], $request->data->getData());
$this->assertEquals('foo=bar&baz=qux', $request->getBody());
}
public function testGetHeader() public function testGetHeader()
{ {
$_SERVER['HTTP_X_CUSTOM_HEADER'] = 'custom header value'; $_SERVER['HTTP_X_CUSTOM_HEADER'] = 'custom header value';

Loading…
Cancel
Save