1
0
mirror of https://github.com/danog/amp.git synced 2024-11-26 20:15:00 +01:00

Automatically add \ for buitins (#186)

Fixes #185.
This commit is contained in:
Markus Staab 2017-11-29 13:36:50 +01:00 committed by Niklas Keller
parent a8cb7f264e
commit 34bf671f13
14 changed files with 91 additions and 90 deletions

View File

@ -13,6 +13,7 @@ return PhpCsFixer\Config::create()
"cast_spaces" => true, "cast_spaces" => true,
"combine_consecutive_unsets" => true, "combine_consecutive_unsets" => true,
"function_to_constant" => true, "function_to_constant" => true,
"native_function_invocation" => true,
"no_multiline_whitespace_before_semicolons" => true, "no_multiline_whitespace_before_semicolons" => true,
"no_unused_imports" => true, "no_unused_imports" => true,
"no_useless_else" => true, "no_useless_else" => true,

View File

@ -5,17 +5,17 @@ require __DIR__ . '/../../vendor/autoload.php';
use Amp\Loop; use Amp\Loop;
if (stream_set_blocking(STDIN, false) !== true) { if (\stream_set_blocking(STDIN, false) !== true) {
fwrite(STDERR, "Unable to set STDIN to non-blocking" . PHP_EOL); \fwrite(STDERR, "Unable to set STDIN to non-blocking" . PHP_EOL);
exit(1); exit(1);
} }
print "Write something and hit enter" . PHP_EOL; print "Write something and hit enter" . PHP_EOL;
Loop::onReadable(STDIN, function ($watcher, $stream) { Loop::onReadable(STDIN, function ($watcher, $stream) {
$chunk = fread($stream, 8192); $chunk = \fread($stream, 8192);
print "Read " . strlen($chunk) . " bytes" . PHP_EOL; print "Read " . \strlen($chunk) . " bytes" . PHP_EOL;
}); });
Loop::run(); Loop::run();

View File

@ -30,10 +30,10 @@ Loop::run(function () {
asyncCall($generator, $emitter); asyncCall($generator, $emitter);
while (yield $iterator->advance()) { while (yield $iterator->advance()) {
printf("Emitter emitted %d\n", $iterator->getCurrent()); \printf("Emitter emitted %d\n", $iterator->getCurrent());
yield new Delayed(500); // Listener consumption takes 500 ms. yield new Delayed(500); // Listener consumption takes 500 ms.
} }
} catch (\Exception $exception) { } catch (\Exception $exception) {
printf("Exception: %s\n", $exception); \printf("Exception: %s\n", $exception);
} }
}); });

View File

@ -29,10 +29,10 @@ Loop::run(function () {
$iterator = $emitter->iterate(); $iterator = $emitter->iterate();
while (yield $iterator->advance()) { while (yield $iterator->advance()) {
printf("Emitter emitted %d\n", $iterator->getCurrent()); \printf("Emitter emitted %d\n", $iterator->getCurrent());
yield new Delayed(100); // Listener consumption takes 100 ms. yield new Delayed(100); // Listener consumption takes 100 ms.
} }
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
printf("Exception: %s\n", $exception); \printf("Exception: %s\n", $exception);
} }
}); });

View File

@ -24,10 +24,10 @@ Loop::run(function () {
}); });
while (yield $iterator->advance()) { while (yield $iterator->advance()) {
printf("Producer emitted %d\n", $iterator->getCurrent()); \printf("Producer emitted %d\n", $iterator->getCurrent());
yield new Delayed(100); // Listener consumption takes 100 ms. yield new Delayed(100); // Listener consumption takes 100 ms.
} }
} catch (\Exception $exception) { } catch (\Exception $exception) {
printf("Exception: %s\n", $exception); \printf("Exception: %s\n", $exception);
} }
}); });

View File

@ -13,7 +13,7 @@ namespace Amp\Internal;
* @internal * @internal
*/ */
function formatStacktrace(array $trace): string { function formatStacktrace(array $trace): string {
return implode("\n", array_map(function ($e, $i) { return \implode("\n", \array_map(function ($e, $i) {
$line = "#{$i} {$e['file']}:{$e['line']} "; $line = "#{$i} {$e['file']}:{$e['line']} ";
if ($e["type"]) { if ($e["type"]) {
@ -21,7 +21,7 @@ function formatStacktrace(array $trace): string {
} }
return $line . $e["function"] . "()"; return $line . $e["function"] . "()";
}, $trace, array_keys($trace))); }, $trace, \array_keys($trace)));
} }
/** /**

View File

@ -40,10 +40,10 @@ class AdaptTest extends \PHPUnit\Framework\TestCase {
->method("then") ->method("then")
->with( ->with(
$this->callback(function ($resolve) { $this->callback(function ($resolve) {
return is_callable($resolve); return \is_callable($resolve);
}), }),
$this->callback(function ($reject) { $this->callback(function ($reject) {
return is_callable($reject); return \is_callable($reject);
}) })
); );

View File

@ -9,7 +9,7 @@ class DelayedTest extends \PHPUnit\Framework\TestCase {
public function testDelayed() { public function testDelayed() {
$time = 100; $time = 100;
$value = "test"; $value = "test";
$start = microtime(true); $start = \microtime(true);
Loop::run(function () use (&$result, $time, $value) { Loop::run(function () use (&$result, $time, $value) {
$promise = new Delayed($time, $value); $promise = new Delayed($time, $value);
@ -21,14 +21,14 @@ class DelayedTest extends \PHPUnit\Framework\TestCase {
$promise->onResolve($callback); $promise->onResolve($callback);
}); });
$this->assertGreaterThanOrEqual($time - 1 /* 1ms grace period */, (microtime(true) - $start) * 1000); $this->assertGreaterThanOrEqual($time - 1 /* 1ms grace period */, (\microtime(true) - $start) * 1000);
$this->assertSame($value, $result); $this->assertSame($value, $result);
} }
public function testUnreference() { public function testUnreference() {
$time = 100; $time = 100;
$value = "test"; $value = "test";
$start = microtime(true); $start = \microtime(true);
$invoked = false; $invoked = false;
Loop::run(function () use (&$invoked, $time, $value) { Loop::run(function () use (&$invoked, $time, $value) {
@ -42,7 +42,7 @@ class DelayedTest extends \PHPUnit\Framework\TestCase {
$promise->onResolve($callback); $promise->onResolve($callback);
}); });
$this->assertLessThanOrEqual($time - 1 /* 1ms grace period */, (microtime(true) - $start) * 1000); $this->assertLessThanOrEqual($time - 1 /* 1ms grace period */, (\microtime(true) - $start) * 1000);
$this->assertFalse($invoked); $this->assertFalse($invoked);
} }
@ -52,7 +52,7 @@ class DelayedTest extends \PHPUnit\Framework\TestCase {
public function testReference() { public function testReference() {
$time = 100; $time = 100;
$value = "test"; $value = "test";
$start = microtime(true); $start = \microtime(true);
$invoked = false; $invoked = false;
Loop::run(function () use (&$invoked, $time, $value) { Loop::run(function () use (&$invoked, $time, $value) {
@ -67,7 +67,7 @@ class DelayedTest extends \PHPUnit\Framework\TestCase {
$promise->onResolve($callback); $promise->onResolve($callback);
}); });
$this->assertGreaterThanOrEqual($time - 1 /* 1ms grace period */, (microtime(true) - $start) * 1000); $this->assertGreaterThanOrEqual($time - 1 /* 1ms grace period */, (\microtime(true) - $start) * 1000);
$this->assertTrue($invoked); $this->assertTrue($invoked);
} }
} }

View File

@ -107,7 +107,7 @@ class IteratorFromIterableTest extends \PHPUnit\Framework\TestCase {
public function testInterval() { public function testInterval() {
Loop::run(function () { Loop::run(function () {
$count = 3; $count = 3;
$iterator = Iterator\fromIterable(range(1, $count), self::TIMEOUT); $iterator = Iterator\fromIterable(\range(1, $count), self::TIMEOUT);
$i = 0; $i = 0;
while (yield $iterator->advance()) { while (yield $iterator->advance()) {
@ -124,7 +124,7 @@ class IteratorFromIterableTest extends \PHPUnit\Framework\TestCase {
public function testSlowConsumer() { public function testSlowConsumer() {
$count = 5; $count = 5;
Loop::run(function () use ($count) { Loop::run(function () use ($count) {
$iterator = Iterator\fromIterable(range(1, $count), self::TIMEOUT); $iterator = Iterator\fromIterable(\range(1, $count), self::TIMEOUT);
for ($i = 0; yield $iterator->advance(); ++$i) { for ($i = 0; yield $iterator->advance(); ++$i) {
yield new Delayed(self::TIMEOUT * 2); yield new Delayed(self::TIMEOUT * 2);

View File

@ -12,15 +12,15 @@ use Amp\Loop\UnsupportedFeatureException;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use React\Promise\RejectedPromise as RejectedReactPromise; use React\Promise\RejectedPromise as RejectedReactPromise;
if (!defined("SIGUSR1")) { if (!\defined("SIGUSR1")) {
define("SIGUSR1", 30); \define("SIGUSR1", 30);
} }
if (!defined("SIGUSR2")) { if (!\defined("SIGUSR2")) {
define("SIGUSR2", 31); \define("SIGUSR2", 31);
} }
if (!defined("PHP_INT_MIN")) { if (!\defined("PHP_INT_MIN")) {
define("PHP_INT_MIN", ~PHP_INT_MAX); \define("PHP_INT_MIN", ~PHP_INT_MAX);
} }
abstract class DriverTest extends TestCase { abstract class DriverTest extends TestCase {
@ -43,7 +43,7 @@ abstract class DriverTest extends TestCase {
// Required for error handler to work // Required for error handler to work
Loop::set($this->loop); Loop::set($this->loop);
gc_collect_cycles(); \gc_collect_cycles();
} }
public function tearDown() { public function tearDown() {
@ -226,7 +226,7 @@ abstract class DriverTest extends TestCase {
$invoked = true; $invoked = true;
}); });
usleep(1000 * 10); \usleep(1000 * 10);
}); });
$this->assertTrue($invoked); $this->assertTrue($invoked);
} }
@ -276,15 +276,15 @@ abstract class DriverTest extends TestCase {
$this->start(function (Driver $loop) use ($type, $args, &$invoked) { $this->start(function (Driver $loop) use ($type, $args, &$invoked) {
if ($type == "onReadable") { if ($type == "onReadable") {
$ends = stream_socket_pair(\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $ends = \stream_socket_pair(\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
fwrite($ends[0], "trigger readability watcher"); \fwrite($ends[0], "trigger readability watcher");
$args = [$ends[1]]; $args = [$ends[1]];
} else { } else {
array_pop($args); \array_pop($args);
} }
$expectedData = 20.75; $expectedData = 20.75;
if (substr($type, 0, 2) == "on") { if (\substr($type, 0, 2) == "on") {
$args[] = function ($watcherId, $arg, int $data) use ($loop, &$invoked, $expectedData) { $args[] = function ($watcherId, $arg, int $data) use ($loop, &$invoked, $expectedData) {
$invoked = true; $invoked = true;
$this->assertSame((int) $expectedData, $data); $this->assertSame((int) $expectedData, $data);
@ -300,7 +300,7 @@ abstract class DriverTest extends TestCase {
}; };
} }
$args[] = $expectedData; $args[] = $expectedData;
call_user_func_array([$loop, $type], $args); \call_user_func_array([$loop, $type], $args);
if ($type == "onSignal") { if ($type == "onSignal") {
$loop->defer(function () { $loop->defer(function () {
@ -341,8 +341,8 @@ abstract class DriverTest extends TestCase {
$loop = $this->loop; $loop = $this->loop;
$func = [$loop, $type]; $func = [$loop, $type];
if (substr($type, 0, 2) === "on") { if (\substr($type, 0, 2) === "on") {
$type = "on_" . lcfirst(substr($type, 2)); $type = "on_" . \lcfirst(\substr($type, 2));
} }
// being referenced is the default // being referenced is the default
@ -407,8 +407,8 @@ abstract class DriverTest extends TestCase {
$loop = $this->loop; $loop = $this->loop;
$func = [$loop, $type]; $func = [$loop, $type];
if (substr($type, 0, 2) === "on") { if (\substr($type, 0, 2) === "on") {
$type = "on_" . lcfirst(substr($type, 2)); $type = "on_" . \lcfirst(\substr($type, 2));
} }
$watcherId = \call_user_func_array($func, $args); $watcherId = \call_user_func_array($func, $args);
@ -478,7 +478,7 @@ abstract class DriverTest extends TestCase {
} }
$this->start(function (Driver $loop) use ($type, $args, $runs) { $this->start(function (Driver $loop) use ($type, $args, $runs) {
$initialMem = memory_get_usage(); $initialMem = \memory_get_usage();
$cb = function ($runs) use ($loop, $type, $args) { $cb = function ($runs) use ($loop, $type, $args) {
$func = [$loop, $type]; $func = [$loop, $type];
for ($watchers = [], $i = 0; $i < $runs; $i++) { for ($watchers = [], $i = 0; $i < $runs; $i++) {
@ -541,11 +541,11 @@ abstract class DriverTest extends TestCase {
$fn = function ($watcherId, $socket, $i) use (&$fn, $loop) { $fn = function ($watcherId, $socket, $i) use (&$fn, $loop) {
$loop->cancel($watcherId); $loop->cancel($watcherId);
if ($socket) { if ($socket) {
fwrite($socket, "."); \fwrite($socket, ".");
} }
if ($i) { if ($i) {
// explicitly use *different* streams with *different* resource ids // explicitly use *different* streams with *different* resource ids
$ends = stream_socket_pair(\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $ends = \stream_socket_pair(\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
$loop->onWritable($ends[0], $fn, --$i); $loop->onWritable($ends[0], $fn, --$i);
$loop->onReadable($ends[1], function ($watcherId) use ($loop) { $loop->onReadable($ends[1], function ($watcherId) use ($loop) {
$loop->cancel($watcherId); $loop->cancel($watcherId);
@ -571,15 +571,15 @@ abstract class DriverTest extends TestCase {
$loop->run(); $loop->run();
} }
}; };
$closureMem = memory_get_usage() - $initialMem; $closureMem = \memory_get_usage() - $initialMem;
$cb($runs); /* just to set up eventual structures inside loop without counting towards memory comparison */ $cb($runs); /* just to set up eventual structures inside loop without counting towards memory comparison */
gc_collect_cycles(); \gc_collect_cycles();
$initialMem = memory_get_usage() - $closureMem; $initialMem = \memory_get_usage() - $closureMem;
$cb($runs); $cb($runs);
unset($cb); unset($cb);
gc_collect_cycles(); \gc_collect_cycles();
$endMem = memory_get_usage(); $endMem = \memory_get_usage();
/* this is allowing some memory usage due to runtime caches etc., but nothing actually leaking */ /* this is allowing some memory usage due to runtime caches etc., but nothing actually leaking */
$this->assertLessThan($runs * 4, $endMem - $initialMem); // * 4, as 4 is minimal sizeof(void *) $this->assertLessThan($runs * 4, $endMem - $initialMem); // * 4, as 4 is minimal sizeof(void *)
@ -591,19 +591,19 @@ abstract class DriverTest extends TestCase {
* indicates the order within the tick. * indicates the order within the tick.
*/ */
public function testExecutionOrderGuarantees() { public function testExecutionOrderGuarantees() {
$this->expectOutputString("01 02 03 04 " . str_repeat("05 ", 8) . "10 11 12 " . str_repeat("13 ", 4) . "20 " . str_repeat("21 ", 4) . "30 40 41 "); $this->expectOutputString("01 02 03 04 " . \str_repeat("05 ", 8) . "10 11 12 " . \str_repeat("13 ", 4) . "20 " . \str_repeat("21 ", 4) . "30 40 41 ");
$this->start(function (Driver $loop) use (&$ticks) { $this->start(function (Driver $loop) use (&$ticks) {
// Wrap in extra defer, so driver creation time doesn't count for timers, as timers are driver creation // Wrap in extra defer, so driver creation time doesn't count for timers, as timers are driver creation
// relative instead of last tick relative before first tick. // relative instead of last tick relative before first tick.
$loop->defer(function () use ($loop, &$ticks) { $loop->defer(function () use ($loop, &$ticks) {
$f = function () use ($loop) { $f = function () use ($loop) {
$args = func_get_args(); $args = \func_get_args();
return function ($watcherId) use ($loop, &$args) { return function ($watcherId) use ($loop, &$args) {
if (!$args) { if (!$args) {
$this->fail("Watcher callback called too often"); $this->fail("Watcher callback called too often");
} }
$loop->cancel($watcherId); $loop->cancel($watcherId);
echo array_shift($args) . array_shift($args), " "; echo \array_shift($args) . \array_shift($args), " ";
}; };
}; };
@ -673,7 +673,7 @@ abstract class DriverTest extends TestCase {
$loop->defer(function () use ($loop, $del5, $f) { $loop->defer(function () use ($loop, $del5, $f) {
$loop->enable($del5); $loop->enable($del5);
$loop->defer(function () use ($loop, $f) { $loop->defer(function () use ($loop, $f) {
usleep(700000); // to have $msDelay == 500 and $msDelay == 600 run at the same tick (but not $msDelay == 150) \usleep(700000); // to have $msDelay == 500 and $msDelay == 600 run at the same tick (but not $msDelay == 150)
$loop->defer(function () use ($loop, $f) { $loop->defer(function () use ($loop, $f) {
$loop->defer($f(4, 0)); $loop->defer($f(4, 0));
}); });
@ -1237,7 +1237,7 @@ abstract class DriverTest extends TestCase {
} }
public function testLoopStopPreventsTimerExecution() { public function testLoopStopPreventsTimerExecution() {
$t = microtime(1); $t = \microtime(1);
$this->start(function (Driver $loop) { $this->start(function (Driver $loop) {
$loop->delay($msDelay = 10000, function () { $loop->delay($msDelay = 10000, function () {
$this->fail("Timer was executed despite stopped loop"); $this->fail("Timer was executed despite stopped loop");
@ -1246,7 +1246,7 @@ abstract class DriverTest extends TestCase {
$loop->stop(); $loop->stop();
}); });
}); });
$this->assertTrue($t + 0.1 > microtime(1)); $this->assertTrue($t + 0.1 > \microtime(1));
} }
public function testDeferEnabledInNextTick() { public function testDeferEnabledInNextTick() {
@ -1349,8 +1349,8 @@ abstract class DriverTest extends TestCase {
break; break;
case "onReadable": case "onReadable":
$ends = stream_socket_pair(\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $ends = \stream_socket_pair(\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
fwrite($ends[0], "trigger readability watcher"); \fwrite($ends[0], "trigger readability watcher");
$args[] = $ends[1]; $args[] = $ends[1];
break; break;
@ -1372,7 +1372,7 @@ abstract class DriverTest extends TestCase {
}; };
} }
call_user_func_array([$this->loop, $watcher], $args); \call_user_func_array([$this->loop, $watcher], $args);
if ($watcher == "onSignal") { if ($watcher == "onSignal") {
$this->loop->delay(100, function () { $this->loop->delay(100, function () {
@ -1391,7 +1391,7 @@ abstract class DriverTest extends TestCase {
} }
public function testMultipleWatchersOnSameDescriptor() { public function testMultipleWatchersOnSameDescriptor() {
$sockets = stream_socket_pair(\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $sockets = \stream_socket_pair(\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
\fwrite($sockets[1], "testing"); \fwrite($sockets[1], "testing");
$invoked = 0; $invoked = 0;
@ -1489,11 +1489,11 @@ abstract class DriverTest extends TestCase {
$emits = 3; $emits = 3;
$this->loop->defer(function () use (&$time, $emits) { $this->loop->defer(function () use (&$time, $emits) {
$time = microtime(true); $time = \microtime(true);
for ($i = 0; $i < $emits; ++$i) { for ($i = 0; $i < $emits; ++$i) {
yield new Delayed(100); yield new Delayed(100);
} }
$time = microtime(true) - $time; $time = \microtime(true) - $time;
}); });
$this->loop->run(); $this->loop->run();

View File

@ -2,7 +2,7 @@
Test order of destruction not interfering with access to UV handles Test order of destruction not interfering with access to UV handles
--SKIPIF-- --SKIPIF--
<?php <?php
extension_loaded("uv") or die("SKIP: ext/uv required for this test"); \extension_loaded("uv") or die("SKIP: ext/uv required for this test");
?> ?>
--FILE-- --FILE--
<?php <?php

View File

@ -20,8 +20,8 @@ class LoopTest extends TestCase {
public function testOnReadable() { public function testOnReadable() {
Loop::run(function () { Loop::run(function () {
$ends = stream_socket_pair(\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); $ends = \stream_socket_pair(\stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
fwrite($ends[0], "trigger readability watcher"); \fwrite($ends[0], "trigger readability watcher");
Loop::onReadable($ends[1], function () { Loop::onReadable($ends[1], function () {
$this->assertTrue(true); $this->assertTrue(true);

View File

@ -82,11 +82,11 @@ class ProducerTest extends TestCase {
$emits = 3; $emits = 3;
Loop::run(function () use (&$time, $emits) { Loop::run(function () use (&$time, $emits) {
$producer = new Producer(function (callable $emit) use (&$time, $emits) { $producer = new Producer(function (callable $emit) use (&$time, $emits) {
$time = microtime(true); $time = \microtime(true);
for ($i = 0; $i < $emits; ++$i) { for ($i = 0; $i < $emits; ++$i) {
yield $emit($i); yield $emit($i);
} }
$time = microtime(true) - $time; $time = \microtime(true) - $time;
}); });
while (yield $producer->advance()) { while (yield $producer->advance()) {

View File

@ -77,7 +77,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, $succeeder) = $this->promise(); list($promise, $succeeder) = $this->promise();
$succeeder($value); $succeeder($value);
$promise->onResolve(function ($e, $v) use (&$invoked, $value) { $promise->onResolve(function ($e, $v) use (&$invoked, $value) {
$this->assertSame(null, $e); $this->assertNull($e);
$this->assertSame($value, $v); $this->assertSame($value, $v);
$invoked = true; $invoked = true;
}); });
@ -89,26 +89,26 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
$invoked = 0; $invoked = 0;
$promise->onResolve(function ($e, $v) use (&$invoked) { $promise->onResolve(function ($e, $v) use (&$invoked) {
$this->assertSame(null, $e); $this->assertNull($e);
$this->assertSame(true, $v); $this->assertTrue($v);
$invoked++; $invoked++;
}); });
$promise->onResolve(function ($e, $v) use (&$invoked) { $promise->onResolve(function ($e, $v) use (&$invoked) {
$this->assertSame(null, $e); $this->assertNull($e);
$this->assertSame(true, $v); $this->assertTrue($v);
$invoked++; $invoked++;
}); });
$succeeder(true); $succeeder(true);
$promise->onResolve(function ($e, $v) use (&$invoked) { $promise->onResolve(function ($e, $v) use (&$invoked) {
$this->assertSame(null, $e); $this->assertNull($e);
$this->assertSame(true, $v); $this->assertTrue($v);
$invoked++; $invoked++;
}); });
$promise->onResolve(function ($e, $v) use (&$invoked) { $promise->onResolve(function ($e, $v) use (&$invoked) {
$this->assertSame(null, $e); $this->assertNull($e);
$this->assertSame(true, $v); $this->assertTrue($v);
$invoked++; $invoked++;
}); });
@ -118,7 +118,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
public function testPromiseExceptionFailure() { public function testPromiseExceptionFailure() {
list($promise, , $failer) = $this->promise(); list($promise, , $failer) = $this->promise();
$promise->onResolve(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "RuntimeException"); $this->assertSame(\get_class($e), "RuntimeException");
$invoked = true; $invoked = true;
}); });
$failer(new \RuntimeException); $failer(new \RuntimeException);
@ -129,7 +129,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, , $failer) = $this->promise(); list($promise, , $failer) = $this->promise();
$failer(new \RuntimeException); $failer(new \RuntimeException);
$promise->onResolve(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "RuntimeException"); $this->assertSame(\get_class($e), "RuntimeException");
$invoked = true; $invoked = true;
}); });
$this->assertTrue($invoked); $this->assertTrue($invoked);
@ -140,22 +140,22 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
$invoked = 0; $invoked = 0;
$promise->onResolve(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "RuntimeException"); $this->assertSame(\get_class($e), "RuntimeException");
$invoked++; $invoked++;
}); });
$promise->onResolve(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "RuntimeException"); $this->assertSame(\get_class($e), "RuntimeException");
$invoked++; $invoked++;
}); });
$failer(new \RuntimeException); $failer(new \RuntimeException);
$promise->onResolve(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "RuntimeException"); $this->assertSame(\get_class($e), "RuntimeException");
$invoked++; $invoked++;
}); });
$promise->onResolve(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "RuntimeException"); $this->assertSame(\get_class($e), "RuntimeException");
$invoked++; $invoked++;
}); });
@ -169,7 +169,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, , $failer) = $this->promise(); list($promise, , $failer) = $this->promise();
$promise->onResolve(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "Error"); $this->assertSame(\get_class($e), "Error");
$invoked = true; $invoked = true;
}); });
$failer(new \Error); $failer(new \Error);
@ -184,7 +184,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, , $failer) = $this->promise(); list($promise, , $failer) = $this->promise();
$failer(new \Error); $failer(new \Error);
$promise->onResolve(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "Error"); $this->assertSame(\get_class($e), "Error");
$invoked = true; $invoked = true;
}); });
$this->assertTrue($invoked); $this->assertTrue($invoked);
@ -225,8 +225,8 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, $succeeder) = $this->promise(); list($promise, $succeeder) = $this->promise();
$succeeder(true); $succeeder(true);
$promise->onResolve(function ($e, $v) use (&$invoked, $promise) { $promise->onResolve(function ($e, $v) use (&$invoked, $promise) {
$this->assertSame(null, $e); $this->assertNull($e);
$this->assertSame(true, $v); $this->assertTrue($v);
$invoked++; $invoked++;
throw new \Exception; throw new \Exception;
@ -234,8 +234,8 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, $succeeder) = $this->promise(); list($promise, $succeeder) = $this->promise();
$promise->onResolve(function ($e, $v) use (&$invoked, $promise) { $promise->onResolve(function ($e, $v) use (&$invoked, $promise) {
$this->assertSame(null, $e); $this->assertNull($e);
$this->assertSame(true, $v); $this->assertTrue($v);
$invoked++; $invoked++;
throw new \Exception; throw new \Exception;
@ -256,15 +256,15 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, $succeeder) = $this->promise(); list($promise, $succeeder) = $this->promise();
$promise->onResolve(function ($e, $v) use (&$invoked, $promise) { $promise->onResolve(function ($e, $v) use (&$invoked, $promise) {
$this->assertSame(null, $e); $this->assertNull($e);
$this->assertSame(true, $v); $this->assertTrue($v);
$invoked++; $invoked++;
throw new \Exception; throw new \Exception;
}); });
$promise->onResolve(function ($e, $v) use (&$invoked, $promise) { $promise->onResolve(function ($e, $v) use (&$invoked, $promise) {
$this->assertSame(null, $e); $this->assertNull($e);
$this->assertSame(true, $v); $this->assertTrue($v);
$invoked++; $invoked++;
}); });
$succeeder(true); $succeeder(true);
@ -337,7 +337,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
$promise->onResolve(function () { }); $promise->onResolve(function () { });
$promise->onResolve(function () use (&$invoked) { $promise->onResolve(function () use (&$invoked) {
$invoked = true; $invoked = true;
$this->assertLessThan(30, count(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))); $this->assertLessThan(30, \count(\debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)));
}); });
$last = $promise; $last = $promise;