ReflectionClosure4Test.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. use Foo\Bar;
  3. use Foo\{
  4. Bar as Baz,
  5. };
  6. use ReflectionClosure4Class as SomeAlias;
  7. test('resolve arguments', function () {
  8. $f1 = function (object $p) {
  9. };
  10. $e1 = 'function (object $p) {
  11. }';
  12. expect($f1)->toBeCode($e1);
  13. });
  14. test('resolve return type', function () {
  15. $f1 = function (): object {
  16. };
  17. $e1 = 'function (): object {
  18. }';
  19. expect($f1)->toBeCode($e1);
  20. });
  21. test('trailing comma', function () {
  22. $f1 = function (): Baz {
  23. };
  24. $e1 = 'function (): \Foo\Bar {
  25. }';
  26. expect($f1)->toBeCode($e1);
  27. });
  28. test('instantiate non qualified class name', function () {
  29. $f = function () {
  30. new NonExisting\B();
  31. };
  32. $e = 'function () {
  33. new \NonExisting\B();
  34. }';
  35. expect($f)->toBeCode($e);
  36. });
  37. test('instantiate partially qualified namespace', function () {
  38. $f = function (Bar\Test $p) {
  39. };
  40. $e = 'function (\Foo\Bar\Test $p) {
  41. }';
  42. expect($f)->toBeCode($e);
  43. });
  44. test('fully qualified', function () {
  45. $f = function () {
  46. new \A();
  47. };
  48. $e = 'function () {
  49. new \A();
  50. }';
  51. expect($f)->toBeCode($e);
  52. });
  53. test('namespaced object inside closure', function () {
  54. $closure = function () {
  55. $object = new ReflectionClosure4Class();
  56. expect($object)->toBeInstanceOf(ReflectionClosure4Class::class);
  57. expect($object)->toBeInstanceOf(SomeAlias::class);
  58. };
  59. $executable = s($closure);
  60. $executable();
  61. })->with('serializers');
  62. class ReflectionClosure4Class
  63. {
  64. // ..
  65. }