- Add test case for Zend class to array declaration with parameters rejection - Add test case for Zend class to array declaration with wrong return type - Add test case for known Zend class missing required toArray method - Add test case for known Zend class resolving toArray through magic call - Add test case for native class rejecting toArray parameters at declaration - Update existing native class keyword return type test file - Create new test file for native class to array parameters validation - Add dynamic method test for toArray dispatch supporting real methods and __callmaster
parent
3def25cc3c
commit
02fc0fb319
13 changed files with 208 additions and 13 deletions
@ -0,0 +1,10 @@ |
||||
<?php |
||||
|
||||
#[Native] |
||||
class NativeToArrayWithParameters |
||||
{ |
||||
public function toArray(int $mode = 0): array |
||||
{ |
||||
return []; |
||||
} |
||||
} |
||||
@ -0,0 +1,14 @@ |
||||
<?php |
||||
|
||||
class ZendMagicToArray |
||||
{ |
||||
public function __call(string $name, array $arguments): array |
||||
{ |
||||
return [$name]; |
||||
} |
||||
} |
||||
|
||||
function main(): void |
||||
{ |
||||
(new ZendMagicToArray())->toArray(); |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
<?php |
||||
|
||||
class ZendWithoutToArray |
||||
{ |
||||
} |
||||
|
||||
function main(): void |
||||
{ |
||||
(new ZendWithoutToArray())->toArray(); |
||||
} |
||||
@ -0,0 +1,9 @@ |
||||
<?php |
||||
|
||||
class ZendToArrayWithParameters |
||||
{ |
||||
public function toArray(int $mode = 0): array |
||||
{ |
||||
return []; |
||||
} |
||||
} |
||||
@ -0,0 +1,9 @@ |
||||
<?php |
||||
|
||||
class ZendToArrayWrongReturn |
||||
{ |
||||
public function toArray(): string |
||||
{ |
||||
return ''; |
||||
} |
||||
} |
||||
@ -0,0 +1,70 @@ |
||||
--TEST-- |
||||
Dynamic toArray() dispatch supports real methods and __call |
||||
--FILE-- |
||||
<?php |
||||
|
||||
class DynamicToArrayValue |
||||
{ |
||||
public function toArray(): array |
||||
{ |
||||
return ['value' => 42]; |
||||
} |
||||
} |
||||
|
||||
class DynamicToArrayMagicOnly |
||||
{ |
||||
public function __call(string $name, array $arguments): array |
||||
{ |
||||
return ['magic' => $name]; |
||||
} |
||||
} |
||||
|
||||
function eraseToMixed(object $value): mixed |
||||
{ |
||||
return $value; |
||||
} |
||||
|
||||
function callDynamicToArray(mixed $value): array |
||||
{ |
||||
return $value->toArray(); |
||||
} |
||||
|
||||
function dumpDynamicToArrayError(object $value): void |
||||
{ |
||||
try { |
||||
callDynamicToArray(eraseToMixed($value)); |
||||
} catch (Error $error) { |
||||
echo $error->getMessage(), "\n"; |
||||
} |
||||
} |
||||
|
||||
function main(): void |
||||
{ |
||||
var_dump(callDynamicToArray(eraseToMixed(new DynamicToArrayValue()))); |
||||
dumpDynamicToArrayError(new stdClass()); |
||||
var_dump((new DynamicToArrayMagicOnly())->toArray()); |
||||
var_dump(callDynamicToArray(eraseToMixed(new DynamicToArrayMagicOnly()))); |
||||
|
||||
$plain = new stdClass(); |
||||
$plain->value = 7; |
||||
var_dump((array) $plain); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
array(1) { |
||||
["value"]=> |
||||
int(42) |
||||
} |
||||
Invalid callback stdClass::toArray, class stdClass does not have a method "toArray" |
||||
array(1) { |
||||
["magic"]=> |
||||
string(7) "toArray" |
||||
} |
||||
array(1) { |
||||
["magic"]=> |
||||
string(7) "toArray" |
||||
} |
||||
array(1) { |
||||
["value"]=> |
||||
int(7) |
||||
} |
||||
Loading…
Reference in new issue