1<?php 2 3namespace React\Promise; 4 5class FunctionCheckTypehintTest extends TestCase 6{ 7 /** @test */ 8 public function shouldAcceptClosureCallbackWithTypehint() 9 { 10 $this->assertTrue(_checkTypehint(function (\InvalidArgumentException $e) { 11 }, new \InvalidArgumentException())); 12 $this->assertfalse(_checkTypehint(function (\InvalidArgumentException $e) { 13 }, new \Exception())); 14 } 15 16 /** @test */ 17 public function shouldAcceptFunctionStringCallbackWithTypehint() 18 { 19 $this->assertTrue(_checkTypehint('React\Promise\testCallbackWithTypehint', new \InvalidArgumentException())); 20 $this->assertfalse(_checkTypehint('React\Promise\testCallbackWithTypehint', new \Exception())); 21 } 22 23 /** @test */ 24 public function shouldAcceptInvokableObjectCallbackWithTypehint() 25 { 26 $this->assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new \InvalidArgumentException())); 27 $this->assertfalse(_checkTypehint(new TestCallbackWithTypehintClass(), new \Exception())); 28 } 29 30 /** @test */ 31 public function shouldAcceptObjectMethodCallbackWithTypehint() 32 { 33 $this->assertTrue(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \InvalidArgumentException())); 34 $this->assertfalse(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \Exception())); 35 } 36 37 /** @test */ 38 public function shouldAcceptStaticClassCallbackWithTypehint() 39 { 40 $this->assertTrue(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException())); 41 $this->assertfalse(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \Exception())); 42 } 43 44 /** @test */ 45 public function shouldAcceptClosureCallbackWithoutTypehint() 46 { 47 $this->assertTrue(_checkTypehint(function (\InvalidArgumentException $e) { 48 }, new \InvalidArgumentException())); 49 } 50 51 /** @test */ 52 public function shouldAcceptFunctionStringCallbackWithoutTypehint() 53 { 54 $this->assertTrue(_checkTypehint('React\Promise\testCallbackWithoutTypehint', new \InvalidArgumentException())); 55 } 56 57 /** @test */ 58 public function shouldAcceptInvokableObjectCallbackWithoutTypehint() 59 { 60 $this->assertTrue(_checkTypehint(new TestCallbackWithoutTypehintClass(), new \InvalidArgumentException())); 61 } 62 63 /** @test */ 64 public function shouldAcceptObjectMethodCallbackWithoutTypehint() 65 { 66 $this->assertTrue(_checkTypehint([new TestCallbackWithoutTypehintClass(), 'testCallback'], new \InvalidArgumentException())); 67 } 68 69 /** @test */ 70 public function shouldAcceptStaticClassCallbackWithoutTypehint() 71 { 72 $this->assertTrue(_checkTypehint(['React\Promise\TestCallbackWithoutTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException())); 73 } 74} 75 76function testCallbackWithTypehint(\InvalidArgumentException $e) 77{ 78} 79 80function testCallbackWithoutTypehint() 81{ 82} 83 84class TestCallbackWithTypehintClass 85{ 86 public function __invoke(\InvalidArgumentException $e) 87 { 88 89 } 90 91 public function testCallback(\InvalidArgumentException $e) 92 { 93 94 } 95 96 public static function testCallbackStatic(\InvalidArgumentException $e) 97 { 98 99 } 100} 101 102class TestCallbackWithoutTypehintClass 103{ 104 public function __invoke() 105 { 106 107 } 108 109 public function testCallback() 110 { 111 112 } 113 114 public static function testCallbackStatic() 115 { 116 117 } 118} 119