aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/AppFramework/Http
diff options
context:
space:
mode:
authorStanimir Bozhilov <stanimir.bozhilov.1998@gmail.com>2022-12-19 09:07:38 +0100
committerGitHub <noreply@github.com>2022-12-19 09:07:38 +0100
commit7dcd6eb561f4bba7ed36ce1178c725278dd9b80e (patch)
tree8de1664f1a18df2e3b7b3dafadb3e0b6c3a8b439 /tests/lib/AppFramework/Http
parented902d58b62150a46c745b5e87c895fc3fc67509 (diff)
parente12aaa298861743f798d9adf644d626ac8e89a95 (diff)
downloadnextcloud-server-7dcd6eb561f4bba7ed36ce1178c725278dd9b80e.tar.gz
nextcloud-server-7dcd6eb561f4bba7ed36ce1178c725278dd9b80e.zip
Merge branch 'master' into add-scim-json-support
Signed-off-by: Stanimir Bozhilov <stanimir.bozhilov.1998@gmail.com>
Diffstat (limited to 'tests/lib/AppFramework/Http')
-rw-r--r--tests/lib/AppFramework/Http/DispatcherTest.php21
-rw-r--r--tests/lib/AppFramework/Http/RequestStream.php26
-rw-r--r--tests/lib/AppFramework/Http/RequestTest.php15
3 files changed, 41 insertions, 21 deletions
diff --git a/tests/lib/AppFramework/Http/DispatcherTest.php b/tests/lib/AppFramework/Http/DispatcherTest.php
index 8f591f26e58..016bd7efb58 100644
--- a/tests/lib/AppFramework/Http/DispatcherTest.php
+++ b/tests/lib/AppFramework/Http/DispatcherTest.php
@@ -51,11 +51,12 @@ class TestController extends Controller {
/**
* @param int $int
* @param bool $bool
+ * @param double $foo
* @param int $test
- * @param int $test2
+ * @param integer $test2
* @return array
*/
- public function exec($int, $bool, $test = 4, $test2 = 1) {
+ public function exec($int, $bool, $foo, $test = 4, $test2 = 1) {
$this->registerResponder('text', function ($in) {
return new JSONResponse(['text' => $in]);
});
@@ -315,7 +316,8 @@ class DispatcherTest extends \Test\TestCase {
[
'post' => [
'int' => '3',
- 'bool' => 'false'
+ 'bool' => 'false',
+ 'double' => 1.2,
],
'method' => 'POST'
],
@@ -346,6 +348,7 @@ class DispatcherTest extends \Test\TestCase {
'post' => [
'int' => '3',
'bool' => 'false',
+ 'double' => 1.2,
'test2' => 7
],
'method' => 'POST',
@@ -377,7 +380,8 @@ class DispatcherTest extends \Test\TestCase {
[
'post' => [
'int' => '3',
- 'bool' => 'false'
+ 'bool' => 'false',
+ 'double' => 1.2,
],
'urlParams' => [
'format' => 'text'
@@ -410,7 +414,8 @@ class DispatcherTest extends \Test\TestCase {
[
'post' => [
'int' => '3',
- 'bool' => 'false'
+ 'bool' => 'false',
+ 'double' => 1.2,
],
'urlParams' => [
'format' => 'json'
@@ -443,7 +448,8 @@ class DispatcherTest extends \Test\TestCase {
[
'post' => [
'int' => '3',
- 'bool' => 'false'
+ 'bool' => 'false',
+ 'double' => 1.2,
],
'server' => [
'HTTP_ACCEPT' => 'application/text, test',
@@ -477,7 +483,8 @@ class DispatcherTest extends \Test\TestCase {
[
'post' => [
'int' => '3',
- 'bool' => 'false'
+ 'bool' => 'false',
+ 'double' => 1.2,
],
'get' => [
'format' => 'text'
diff --git a/tests/lib/AppFramework/Http/RequestStream.php b/tests/lib/AppFramework/Http/RequestStream.php
index 3868ed16505..1a99685e340 100644
--- a/tests/lib/AppFramework/Http/RequestStream.php
+++ b/tests/lib/AppFramework/Http/RequestStream.php
@@ -7,24 +7,26 @@ namespace Test\AppFramework\Http;
* Used to simulate php://input for Request tests
*/
class RequestStream {
- protected $position;
- protected $varname;
+ protected int $position = 0;
+ protected string $varname = '';
+ /* @var resource */
+ public $context;
- public function stream_open($path, $mode, $options, &$opened_path) {
+ public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool {
$url = parse_url($path);
- $this->varname = $url["host"];
+ $this->varname = $url["host"] ?? '';
$this->position = 0;
return true;
}
- public function stream_read($count) {
+ public function stream_read(int $count): string {
$ret = substr($GLOBALS[$this->varname], $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
- public function stream_write($data) {
+ public function stream_write(string $data): int {
$left = substr($GLOBALS[$this->varname], 0, $this->position);
$right = substr($GLOBALS[$this->varname], $this->position + strlen($data));
$GLOBALS[$this->varname] = $left . $data . $right;
@@ -32,15 +34,15 @@ class RequestStream {
return strlen($data);
}
- public function stream_tell() {
+ public function stream_tell(): int {
return $this->position;
}
- public function stream_eof() {
+ public function stream_eof(): bool {
return $this->position >= strlen($GLOBALS[$this->varname]);
}
- public function stream_seek($offset, $whence) {
+ public function stream_seek(int $offset, int $whence = SEEK_SET): bool {
switch ($whence) {
case SEEK_SET:
if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) {
@@ -74,7 +76,7 @@ class RequestStream {
}
}
- public function stream_stat() {
+ public function stream_stat(): array {
$size = strlen($GLOBALS[$this->varname]);
$time = time();
$data = [
@@ -96,10 +98,10 @@ class RequestStream {
//return false;
}
- public function stream_metadata($path, $option, $var) {
+ public function stream_metadata(string $path, int $option, $var): bool {
if ($option == STREAM_META_TOUCH) {
$url = parse_url($path);
- $varname = $url["host"];
+ $varname = $url["host"] ?? '';
if (!isset($GLOBALS[$varname])) {
$GLOBALS[$varname] = '';
}
diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php
index 16875cfb0d8..78e656f5fc3 100644
--- a/tests/lib/AppFramework/Http/RequestTest.php
+++ b/tests/lib/AppFramework/Http/RequestTest.php
@@ -256,9 +256,20 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('someothertestvalue', $result['propertyB']);
}
- public function testNotJsonPost() {
+ public function notJsonDataProvider() {
+ return [
+ ['this is not valid json'],
+ ['"just a string"'],
+ ['{"just a string"}'],
+ ];
+ }
+
+ /**
+ * @dataProvider notJsonDataProvider
+ */
+ public function testNotJsonPost($testData) {
global $data;
- $data = 'this is not valid json';
+ $data = $testData;
$vars = [
'method' => 'POST',
'server' => ['CONTENT_TYPE' => 'application/json; utf-8']