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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
<?php
use Foo\Bar;
use Foo\{
Bar as Baz,
};
use ReflectionClosure4Class as SomeAlias;
test('resolve arguments', function () {
$f1 = function (object $p) {
};
$e1 = 'function (object $p) {
}';
expect($f1)->toBeCode($e1);
});
test('resolve return type', function () {
$f1 = function (): object {
};
$e1 = 'function (): object {
}';
expect($f1)->toBeCode($e1);
});
test('trailing comma', function () {
$f1 = function (): Baz {
};
$e1 = 'function (): \Foo\Bar {
}';
expect($f1)->toBeCode($e1);
});
test('instantiate non qualified class name', function () {
$f = function () {
new NonExisting\B();
};
$e = 'function () {
new \NonExisting\B();
}';
expect($f)->toBeCode($e);
});
test('instantiate partially qualified namespace', function () {
$f = function (Bar\Test $p) {
};
$e = 'function (\Foo\Bar\Test $p) {
}';
expect($f)->toBeCode($e);
});
test('fully qualified', function () {
$f = function () {
new \A();
};
$e = 'function () {
new \A();
}';
expect($f)->toBeCode($e);
});
test('namespaced object inside closure', function () {
$closure = function () {
$object = new ReflectionClosure4Class();
expect($object)->toBeInstanceOf(ReflectionClosure4Class::class);
expect($object)->toBeInstanceOf(SomeAlias::class);
};
$executable = s($closure);
$executable();
})->with('serializers');
class ReflectionClosure4Class
{
// ..
}
|