mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
Add more tests for http_build_query()
Some with unusual types like resource and null A lot more tests for objects
This commit is contained in:
parent
c177ea91d4
commit
ec7c7a7550
9 changed files with 134 additions and 0 deletions
|
@ -0,0 +1,17 @@
|
|||
--TEST--
|
||||
http_build_query() function with object
|
||||
--FILE--
|
||||
<?php
|
||||
class KeyVal {
|
||||
public $public = "input";
|
||||
protected $protected = "hello";
|
||||
private $private = "world";
|
||||
}
|
||||
|
||||
$o = new KeyVal();
|
||||
|
||||
// Percent encoded "public=input"
|
||||
var_dump(http_build_query($o));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(12) "public=input"
|
|
@ -0,0 +1,11 @@
|
|||
--TEST--
|
||||
http_build_query() function with empty object
|
||||
--FILE--
|
||||
<?php
|
||||
class EmptyObj {}
|
||||
$o = new EmptyObj();
|
||||
|
||||
var_dump(http_build_query($o));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(0) ""
|
|
@ -0,0 +1,22 @@
|
|||
--TEST--
|
||||
http_build_query() function with object that is just stringable (GH-10229)
|
||||
--FILE--
|
||||
<?php
|
||||
class StringableObject {
|
||||
public function __toString() : string {
|
||||
return "Stringable";
|
||||
}
|
||||
}
|
||||
|
||||
$o = new StringableObject();
|
||||
|
||||
var_dump(http_build_query(['hello', $o]));
|
||||
var_dump(http_build_query($o));
|
||||
var_dump(http_build_query(['hello', $o], numeric_prefix: 'prefix_'));
|
||||
var_dump(http_build_query($o, numeric_prefix: 'prefix_'));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(7) "0=hello"
|
||||
string(0) ""
|
||||
string(14) "prefix_0=hello"
|
||||
string(0) ""
|
|
@ -0,0 +1,20 @@
|
|||
--TEST--
|
||||
http_build_query() function with recursif object
|
||||
--FILE--
|
||||
<?php
|
||||
class KeyValStringable {
|
||||
public $public = "input";
|
||||
protected $protected = "hello";
|
||||
private $private = "world";
|
||||
|
||||
public function __toString(): string {
|
||||
return "Stringable";
|
||||
}
|
||||
}
|
||||
|
||||
$o = new KeyValStringable();
|
||||
|
||||
var_dump(http_build_query($o));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(12) "public=input"
|
|
@ -0,0 +1,20 @@
|
|||
--TEST--
|
||||
http_build_query() function with nested object
|
||||
--FILE--
|
||||
<?php
|
||||
class KeyVal {
|
||||
public $public = "input";
|
||||
protected $protected = "hello";
|
||||
private $private = "world";
|
||||
}
|
||||
|
||||
$o = new KeyVal();
|
||||
$nested = new KeyVal();
|
||||
|
||||
$o->public = $nested;
|
||||
|
||||
// Percent encoded "public[public]=input"
|
||||
var_dump(http_build_query($o));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(24) "public%5Bpublic%5D=input"
|
|
@ -0,0 +1,17 @@
|
|||
--TEST--
|
||||
http_build_query() function with recursif object
|
||||
--FILE--
|
||||
<?php
|
||||
class KeyVal {
|
||||
public $public = "input";
|
||||
protected $protected = "hello";
|
||||
private $private = "world";
|
||||
}
|
||||
|
||||
$o = new KeyVal();
|
||||
$o->public = $o;
|
||||
|
||||
var_dump(http_build_query($o));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(0) ""
|
|
@ -0,0 +1,8 @@
|
|||
--TEST--
|
||||
http_build_query() function with null in array
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(http_build_query([null]));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(0) ""
|
|
@ -0,0 +1,11 @@
|
|||
--TEST--
|
||||
http_build_query() function with reference in array
|
||||
--FILE--
|
||||
<?php
|
||||
$v = 'value';
|
||||
$ref = &$v;
|
||||
|
||||
var_dump(http_build_query([$ref]));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(7) "0=value"
|
|
@ -0,0 +1,8 @@
|
|||
--TEST--
|
||||
http_build_query() function with resource in array
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(http_build_query([STDIN]));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(0) ""
|
Loading…
Add table
Add a link
Reference in a new issue