1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
<?php
test('named arguments', function () {
$f1 = function (string $firstName, string $lastName) {
return $firstName.' '.$lastName;
};
expect('Marco Deleu')->toBe(s($f1)(
lastName: 'Deleu',
firstName: 'Marco'
));
})->with('serializers');
test('single named argument within closures', function () {
$f1 = function () {
return (new SerializerPhp80NamedArguments)->publicMethod(
namedArgument: 'string'
);
};
expect('string')->toBe(s($f1)());
})->with('serializers');
test('multiple named arguments within closures', function () {
$f1 = function () {
return (new SerializerPhp80NamedArguments)->publicMethod(
namedArgument: 'string', namedArgumentB: 1
);
};
expect('string1')->toBe(s($f1)());
})->with('serializers');
test('multiple named arguments within nested closures', function () {
$f1 = function () {
$fn = fn ($namedArgument, $namedArgumentB) => (
new SerializerPhp80NamedArguments
)->publicMethod(namedArgument: $namedArgument, namedArgumentB: $namedArgumentB);
return $fn(namedArgument: 'string', namedArgumentB: 1);
};
expect('string1')->toBe(s($f1)());
})->with('serializers');
class SerializerPhp80NamedArguments
{
public function publicMethod(string $namedArgument, $namedArgumentB = null)
{
return $namedArgument.(string) $namedArgumentB;
}
}
|