88use PHPUnit \Framework \TestCase ;
99
1010use function Chemem \Asyncify \call ;
11- use function Chemem \Bingo \Functional \toException ;
1211use function React \Async \await ;
1312
1413use const Chemem \Asyncify \Internal \PHP_THREADABLE ;
@@ -88,6 +87,23 @@ function (int $next) {
8887 [2 ]
8988 ],
9089 '/(Invalid argument)/i '
90+ ],
91+ [
92+ [
93+ (
94+ PHP_THREADABLE ?
95+ function (int $ val ) {
96+ if ($ next < 10 ) {
97+ \trigger_error ('Value is less than 10 ' );
98+
99+ return $ val * 2 ;
100+ }
101+ } :
102+ '(function (int $x) { if ($x < 10) { \trigger_error("Value is less than 10"); return $x; } return $x * 2; }) '
103+ ),
104+ [2 ]
105+ ],
106+ '/(Value is less than 10)/i '
91107 ]
92108 ];
93109 }
@@ -97,20 +113,33 @@ function (int $next) {
97113 */
98114 public function testcallRunsSynchronousPHPFunctionAsynchronously ($ args , $ result ): void
99115 {
100- $ exec = toException (
101- function (...$ args ) {
102- return await (call (...$ args ));
103- },
104- function (\Throwable $ err ) {
105- return $ err ->getMessage ();
106- }
107- )(...$ args );
116+ $ exec = null ;
117+ try {
118+ $ exec = await (
119+ call (...$ args )
120+ );
121+ } catch (\Throwable $ err ) {
122+ $ exec = $ err ->getMessage ();
123+ }
124+
125+ $ this ->assertTrue (
126+ call ($ args [0 ]) instanceof \Closure
127+ );
108128
109129 if (\is_string ($ result )) {
110- $ this ->assertMatchesRegularExpression (
111- $ result ,
112- $ exec
113- );
130+ if (PHP_VERSION_ID < 73000 ) {
131+ $ this ->assertTrue (
132+ (bool ) \preg_match (
133+ $ result ,
134+ $ exec
135+ )
136+ );
137+ } else {
138+ $ this ->assertMatchesRegularExpression (
139+ $ result ,
140+ $ exec
141+ );
142+ }
114143 } else {
115144 $ this ->assertEquals (
116145 $ result ,
@@ -124,21 +153,30 @@ function (\Throwable $err) {
124153 */
125154 public function testAsynccallMethodRunsSynchronousPHPFunctionAsynchronously ($ args , $ result ): void
126155 {
127- $ exec = toException (
128- function (... $ args ) {
129- $ async = Async::create ();
130- return await ($ async -> call (... $ args ));
131- },
132- function ( \ Throwable $ err ) {
133- return $ err-> getMessage ();
134- }
135- )(... $ args );
156+ $ exec = null ;
157+ try {
158+ $ async = Async::create ();
159+ $ exec = await (
160+ $ async -> call (... $ args )
161+ );
162+ } catch ( \ Throwable $ err) {
163+ $ exec = $ err -> getMessage ();
164+ }
136165
137166 if (\is_string ($ result )) {
138- $ this ->assertMatchesRegularExpression (
139- $ result ,
140- $ exec
141- );
167+ if (PHP_VERSION_ID < 73000 ) {
168+ $ this ->assertTrue (
169+ (bool ) \preg_match (
170+ $ result ,
171+ $ exec
172+ )
173+ );
174+ } else {
175+ $ this ->assertMatchesRegularExpression (
176+ $ result ,
177+ $ exec
178+ );
179+ }
142180 } else {
143181 $ this ->assertEquals (
144182 $ result ,
0 commit comments