ReflectionClosure3Test.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // Fake
  3. use Foo\Bar;
  4. use Foo\Baz as Qux;
  5. test('resolve arguments', function () {
  6. $f1 = function (?Bar $p) {
  7. };
  8. $e1 = 'function (?\Foo\Bar $p) {
  9. }';
  10. $f2 = function (?Bar\Test $p) {
  11. };
  12. $e2 = 'function (?\Foo\Bar\Test $p) {
  13. }';
  14. $f3 = function (?Qux $p) {
  15. };
  16. $e3 = 'function (?\Foo\Baz $p) {
  17. }';
  18. $f4 = function (?Qux\Test $p) {
  19. };
  20. $e4 = 'function (?\Foo\Baz\Test $p) {
  21. }';
  22. $f5 = function (?array $p, ?string $x) {
  23. };
  24. $e5 = 'function (?array $p, ?string $x) {
  25. }';
  26. expect($f1)->toBeCode($e1);
  27. expect($f2)->toBeCode($e2);
  28. expect($f3)->toBeCode($e3);
  29. expect($f4)->toBeCode($e4);
  30. expect($f5)->toBeCode($e5);
  31. });
  32. test('resolve return type', function () {
  33. $f1 = function (): ?Bar {
  34. };
  35. $e1 = 'function (): ?\Foo\Bar {
  36. }';
  37. $f2 = function (): ?Bar\Test {
  38. };
  39. $e2 = 'function (): ?\Foo\Bar\Test {
  40. }';
  41. $f3 = function (): ?Qux {
  42. };
  43. $e3 = 'function (): ?\Foo\Baz {
  44. }';
  45. $f4 = function (): ?Qux\Test {
  46. };
  47. $e4 = 'function (): ?\Foo\Baz\Test {
  48. }';
  49. $f5 = function (): ?\Foo {
  50. };
  51. $e5 = 'function (): ?\Foo {
  52. }';
  53. $f6 = function (): ?Foo {
  54. };
  55. $e6 = 'function (): ?\Foo {
  56. }';
  57. $f7 = function (): ?array {
  58. };
  59. $e7 = 'function (): ?array {
  60. }';
  61. $f8 = function (): ?string {
  62. };
  63. $e8 = 'function (): ?string {
  64. }';
  65. $f9 = function (): void {
  66. };
  67. $e9 = 'function (): void {
  68. }';
  69. expect($f1)->toBeCode($e1);
  70. expect($f2)->toBeCode($e2);
  71. expect($f3)->toBeCode($e3);
  72. expect($f4)->toBeCode($e4);
  73. expect($f5)->toBeCode($e5);
  74. expect($f6)->toBeCode($e6);
  75. expect($f7)->toBeCode($e7);
  76. expect($f8)->toBeCode($e8);
  77. expect($f9)->toBeCode($e9);
  78. });