mirror of
https://github.com/danog/amp.git
synced 2025-01-21 21:01:16 +01:00
Update php-cs-fixer to version 2 and upgrade rules
This also fixes the code style according to the new rules.
This commit is contained in:
parent
0e376fbed9
commit
79ab41e5bf
8
.editorconfig
Normal file
8
.editorconfig
Normal file
@ -0,0 +1,8 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = spaces
|
||||
charset = utf-8
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ composer.lock
|
||||
phpunit.xml
|
||||
vendor
|
||||
humbug.json
|
||||
.php_cs.cache
|
||||
|
33
.php_cs
33
.php_cs
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
return Symfony\CS\Config\Config::create()
|
||||
->level(Symfony\CS\FixerInterface::NONE_LEVEL)
|
||||
->fixers([
|
||||
"psr1",
|
||||
"psr2",
|
||||
"-braces",
|
||||
"-psr0",
|
||||
"ordered_use",
|
||||
"short_array_syntax",
|
||||
"no_useless_else",
|
||||
"no_useless_return",
|
||||
"multiline_spaces_before_semicolon",
|
||||
"combine_consecutive_unsets",
|
||||
"unused_use",
|
||||
"whitespacy_lines",
|
||||
"spaces_cast",
|
||||
"single_blank_line_before_namespace",
|
||||
"short_scalar_cast",
|
||||
"short_bool_cast",
|
||||
"self_accessor",
|
||||
"remove_leading_slash_use",
|
||||
"phpdoc_types",
|
||||
"extra_empty_lines",
|
||||
"duplicate_semicolon",
|
||||
])
|
||||
->finder(
|
||||
Symfony\CS\Finder\DefaultFinder::create()
|
||||
->in(__DIR__ . "/examples")
|
||||
->in(__DIR__ . "/lib")
|
||||
->in(__DIR__ . "/test")
|
||||
);
|
41
.php_cs.dist
Normal file
41
.php_cs.dist
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
return PhpCsFixer\Config::create()
|
||||
->setRiskyAllowed(true)
|
||||
->setRules([
|
||||
"@PSR1" => true,
|
||||
"@PSR2" => true,
|
||||
"braces" => [
|
||||
"allow_single_line_closure" => true,
|
||||
"position_after_functions_and_oop_constructs" => "same",
|
||||
],
|
||||
"array_syntax" => ["syntax" => "short"],
|
||||
"cast_spaces" => true,
|
||||
"combine_consecutive_unsets" => true,
|
||||
"function_to_constant" => true,
|
||||
"no_multiline_whitespace_before_semicolons" => true,
|
||||
"no_unused_imports" => true,
|
||||
"no_useless_else" => true,
|
||||
"no_useless_return" => true,
|
||||
"no_whitespace_before_comma_in_array" => true,
|
||||
"no_whitespace_in_blank_line" => true,
|
||||
"non_printable_character" => true,
|
||||
"normalize_index_brace" => true,
|
||||
"ordered_imports" => true,
|
||||
"php_unit_construct" => true,
|
||||
"php_unit_dedicate_assert" => true,
|
||||
"php_unit_fqcn_annotation" => true,
|
||||
"php_unit_strict" => true,
|
||||
"phpdoc_summary" => true,
|
||||
"phpdoc_types" => true,
|
||||
"psr4" => true,
|
||||
"return_type_declaration" => ["space_before" => "none"],
|
||||
"short_scalar_cast" => true,
|
||||
"single_blank_line_before_namespace" => true,
|
||||
])
|
||||
->setFinder(
|
||||
PhpCsFixer\Finder::create()
|
||||
->in(__DIR__ . "/examples")
|
||||
->in(__DIR__ . "/lib")
|
||||
->in(__DIR__ . "/test")
|
||||
);
|
@ -37,7 +37,7 @@
|
||||
"require-dev": {
|
||||
"amphp/phpunit-util": "dev-master",
|
||||
"react/promise": "^2",
|
||||
"friendsofphp/php-cs-fixer": "~1.9",
|
||||
"friendsofphp/php-cs-fixer": "^2.3",
|
||||
"phpunit/phpunit": "^6.0.9"
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -21,4 +21,4 @@ Loop::run(function () {
|
||||
});
|
||||
});
|
||||
|
||||
print "-- after Loop::run()" . PHP_EOL;
|
||||
print "-- after Loop::run()" . PHP_EOL;
|
||||
|
@ -46,4 +46,4 @@ Loop::run(function () {
|
||||
} catch (\Exception $exception) {
|
||||
printf("Exception: %s\n", $exception);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -46,4 +46,4 @@ Loop::run(function () {
|
||||
} catch (\Throwable $exception) {
|
||||
printf("Exception: %s\n", $exception);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -38,8 +38,7 @@ Loop::run(function () {
|
||||
};
|
||||
|
||||
yield new Coroutine($generator($producer));
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
printf("Exception: %s\n", $exception);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -65,4 +65,4 @@ if (\PHP_VERSION_ID < 70100) {
|
||||
return \Closure::fromCallable([self::class, $method]);
|
||||
}
|
||||
}
|
||||
} // @codeCoverageIgnoreEnd
|
||||
} // @codeCoverageIgnoreEnd
|
||||
|
@ -43,4 +43,4 @@ function createTypeError(array $expected, $given): \TypeError {
|
||||
}
|
||||
|
||||
return new \TypeError("{$expectedType}; {$givenType} given");
|
||||
}
|
||||
}
|
||||
|
@ -48,4 +48,4 @@ class LazyPromise implements Promise {
|
||||
|
||||
$this->promise->onResolve($onResolved);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -366,4 +366,4 @@ final class Loop {
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
Loop::set((new DriverFactory)->create());
|
||||
// @codeCoverageIgnoreEnd
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
@ -678,4 +678,4 @@ abstract class Driver {
|
||||
"running" => (bool) $this->running,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,4 +25,4 @@ class DriverFactory {
|
||||
return new NativeDriver;
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
@ -8,5 +8,4 @@ namespace Amp\Loop;
|
||||
* This might happen if ext-pcntl is missing and the loop driver doesn't support another way to dispatch signals.
|
||||
*/
|
||||
class UnsupportedFeatureException extends \Exception {
|
||||
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ interface Promise {
|
||||
* @return mixed Return type and value are unspecified.
|
||||
*/
|
||||
public function onResolve(callable $onResolved);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace Amp;
|
||||
|
||||
/**
|
||||
* A "safe" struct trait for public property aggregators
|
||||
* A "safe" struct trait for public property aggregators.
|
||||
*
|
||||
* This trait is intended to make using public properties a little safer by throwing when
|
||||
* nonexistent property names are read or written.
|
||||
|
@ -45,7 +45,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
|
||||
Promise\all($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals([1, 2, 3], $result);
|
||||
$this->assertSame([1, 2, 3], $result);
|
||||
}
|
||||
|
||||
public function testArrayKeysPreserved() {
|
||||
@ -65,7 +65,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
|
||||
Promise\all($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
Promise\any($promises)->onResolve($callback);
|
||||
|
||||
$this->assertEquals([[], [1, 2, 3]], $result);
|
||||
$this->assertSame([[], [1, 2, 3]], $result);
|
||||
}
|
||||
|
||||
public function testFailedPromisesArray() {
|
||||
@ -41,7 +41,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
Promise\any($promises)->onResolve($callback);
|
||||
|
||||
$this->assertEquals([[$exception, $exception, $exception], []], $result);
|
||||
$this->assertSame([[$exception, $exception, $exception], []], $result);
|
||||
}
|
||||
|
||||
public function testMixedPromisesArray() {
|
||||
@ -54,7 +54,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
Promise\any($promises)->onResolve($callback);
|
||||
|
||||
$this->assertEquals([[1 => $exception], [0 => 1, 2 => 3]], $result);
|
||||
$this->assertSame([[1 => $exception], [0 => 1, 2 => 3]], $result);
|
||||
}
|
||||
|
||||
public function testPendingAwatiablesArray() {
|
||||
@ -72,7 +72,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
Promise\any($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals([[], [1, 2, 3]], $result);
|
||||
$this->assertSame([[], [1, 2, 3]], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,7 +96,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
Promise\any($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -615,8 +615,7 @@ class CoroutineTest extends TestCase {
|
||||
/**
|
||||
* @depends testCoroutineResolvedWithReturn
|
||||
*/
|
||||
public function testFastReturningGenerator()
|
||||
{
|
||||
public function testFastReturningGenerator() {
|
||||
$value = 1;
|
||||
|
||||
$generator = function () use ($value) {
|
||||
|
@ -10,7 +10,7 @@ use Amp\Stream;
|
||||
class FilterTest extends \PHPUnit\Framework\TestCase {
|
||||
public function testNoValuesEmitted() {
|
||||
$invoked = false;
|
||||
Loop::run(function () use (&$invoked){
|
||||
Loop::run(function () use (&$invoked) {
|
||||
$emitter = new Emitter;
|
||||
|
||||
$stream = Stream\filter($emitter->stream(), function ($value) use (&$invoked) {
|
||||
@ -89,7 +89,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase {
|
||||
public function testStreamFails() {
|
||||
$invoked = false;
|
||||
$exception = new \Exception;
|
||||
Loop::run(function () use (&$invoked, &$reason, &$exception){
|
||||
Loop::run(function () use (&$invoked, &$reason, &$exception) {
|
||||
$emitter = new Emitter;
|
||||
|
||||
$stream = Stream\filter($emitter->stream(), function ($value) use (&$invoked) {
|
||||
|
@ -41,7 +41,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
|
||||
Promise\first($promises)->onResolve($callback);
|
||||
|
||||
$this->assertInstanceOf(MultiReasonException::class, $reason);
|
||||
$this->assertEquals([$exception, $exception, $exception], $reason->getReasons());
|
||||
$this->assertSame([$exception, $exception, $exception], $reason->getReasons());
|
||||
}
|
||||
|
||||
public function testMixedPromisesArray() {
|
||||
|
@ -32,4 +32,4 @@ class InvalidYieldErrorTest extends \PHPUnit\Framework\TestCase {
|
||||
$error = new InvalidYieldError($gen, "prefix");
|
||||
$this->assertSame("prefix; integer yielded at key 'foo' on line " . (__LINE__ - 8) . " in " . __FILE__, $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,16 +24,16 @@ if (!defined("PHP_INT_MIN")) {
|
||||
|
||||
abstract class DriverTest extends TestCase {
|
||||
/**
|
||||
* The DriverFactory to run this test on
|
||||
* The DriverFactory to run this test on.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
abstract function getFactory(): callable;
|
||||
abstract public function getFactory(): callable;
|
||||
|
||||
/** @var Driver */
|
||||
public $loop;
|
||||
|
||||
function setUp() {
|
||||
public function setUp() {
|
||||
$this->loop = ($this->getFactory())();
|
||||
|
||||
if (!$this->loop instanceof Driver) {
|
||||
@ -44,21 +44,21 @@ abstract class DriverTest extends TestCase {
|
||||
Loop::set($this->loop);
|
||||
}
|
||||
|
||||
function start($cb) {
|
||||
public function start($cb) {
|
||||
$cb($this->loop);
|
||||
$this->loop->run();
|
||||
}
|
||||
|
||||
function testEmptyLoop() {
|
||||
public function testEmptyLoop() {
|
||||
$this->assertNull($this->loop->run());
|
||||
}
|
||||
|
||||
function testStopWorksEvenIfNotCurrentlyRunning() {
|
||||
public function testStopWorksEvenIfNotCurrentlyRunning() {
|
||||
$this->assertNull($this->loop->stop());
|
||||
}
|
||||
|
||||
// Note: The running nesting is important for being able to continue actually still running loops (i.e. running flag set, if the driver has one) inside register_shutdown_function() for example
|
||||
function testLoopRunsCanBeConsecutiveAndNested() {
|
||||
public function testLoopRunsCanBeConsecutiveAndNested() {
|
||||
$this->expectOutputString("123456");
|
||||
$this->start(function (Driver $loop) {
|
||||
$loop->stop();
|
||||
@ -94,7 +94,7 @@ abstract class DriverTest extends TestCase {
|
||||
}
|
||||
|
||||
/** This MUST NOT have a "test" prefix, otherwise it's executed as test and marked as risky. */
|
||||
function checkForSignalCapability() {
|
||||
public function checkForSignalCapability() {
|
||||
try {
|
||||
$watcher = $this->loop->onSignal(SIGUSR1, function () {
|
||||
});
|
||||
@ -104,7 +104,7 @@ abstract class DriverTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
function testWatcherUnrefRerefRunResult() {
|
||||
public function testWatcherUnrefRerefRunResult() {
|
||||
$invoked = false;
|
||||
$this->start(function (Driver $loop) use (&$invoked) {
|
||||
$watcher = $loop->defer(function () use (&$invoked) {
|
||||
@ -117,7 +117,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertTrue($invoked);
|
||||
}
|
||||
|
||||
function testDeferWatcherUnrefRunResult() {
|
||||
public function testDeferWatcherUnrefRunResult() {
|
||||
$invoked = false;
|
||||
$this->start(function (Driver $loop) use (&$invoked) {
|
||||
$watcher = $loop->defer(function () use (&$invoked) {
|
||||
@ -128,7 +128,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertFalse($invoked);
|
||||
}
|
||||
|
||||
function testOnceWatcherUnrefRunResult() {
|
||||
public function testOnceWatcherUnrefRunResult() {
|
||||
$invoked = false;
|
||||
$this->start(function (Driver $loop) use (&$invoked) {
|
||||
$watcher = $loop->delay(2000, function () use (&$invoked) {
|
||||
@ -140,7 +140,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertFalse($invoked);
|
||||
}
|
||||
|
||||
function testRepeatWatcherUnrefRunResult() {
|
||||
public function testRepeatWatcherUnrefRunResult() {
|
||||
$invoked = false;
|
||||
$this->start(function (Driver $loop) use (&$invoked) {
|
||||
$watcher = $loop->repeat(2000, function () use (&$invoked) {
|
||||
@ -151,7 +151,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertFalse($invoked);
|
||||
}
|
||||
|
||||
function testOnReadableWatcherUnrefRunResult() {
|
||||
public function testOnReadableWatcherUnrefRunResult() {
|
||||
$invoked = false;
|
||||
$this->start(function (Driver $loop) use (&$invoked) {
|
||||
$watcher = $loop->onReadable(STDIN, function () use (&$invoked) {
|
||||
@ -162,7 +162,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertFalse($invoked);
|
||||
}
|
||||
|
||||
function testOnWritableWatcherKeepAliveRunResult() {
|
||||
public function testOnWritableWatcherKeepAliveRunResult() {
|
||||
$invoked = false;
|
||||
$this->start(function (Driver $loop) use (&$invoked) {
|
||||
$watcher = $loop->onWritable(STDOUT, function () use (&$invoked) {
|
||||
@ -173,7 +173,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertFalse($invoked);
|
||||
}
|
||||
|
||||
function testOnSignalWatcherKeepAliveRunResult() {
|
||||
public function testOnSignalWatcherKeepAliveRunResult() {
|
||||
$this->checkForSignalCapability();
|
||||
$invoked = false;
|
||||
$this->start(function (Driver $loop) use (&$invoked) {
|
||||
@ -189,7 +189,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertTrue($invoked);
|
||||
}
|
||||
|
||||
function testUnreferencedDeferWatcherStillExecutes() {
|
||||
public function testUnreferencedDeferWatcherStillExecutes() {
|
||||
$invoked = false;
|
||||
$this->start(function (Driver $loop) use (&$invoked) {
|
||||
$watcher = $loop->defer(function () use (&$invoked) {
|
||||
@ -203,7 +203,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertTrue($invoked);
|
||||
}
|
||||
|
||||
function testLoopDoesNotBlockOnNegativeTimerExpiration() {
|
||||
public function testLoopDoesNotBlockOnNegativeTimerExpiration() {
|
||||
$invoked = false;
|
||||
$this->start(function (Driver $loop) use (&$invoked) {
|
||||
$loop->delay(1, function () use (&$invoked) {
|
||||
@ -215,7 +215,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertTrue($invoked);
|
||||
}
|
||||
|
||||
function testDisabledDeferReenableInSubsequentTick() {
|
||||
public function testDisabledDeferReenableInSubsequentTick() {
|
||||
$this->expectOutputString("123");
|
||||
$this->start(function (Driver $loop) {
|
||||
$watcherId = $loop->defer(function ($watcherId) {
|
||||
@ -230,7 +230,7 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
function provideRegistrationArgs() {
|
||||
public function provideRegistrationArgs() {
|
||||
$args = [
|
||||
["defer", [function () {
|
||||
}]],
|
||||
@ -253,7 +253,7 @@ abstract class DriverTest extends TestCase {
|
||||
* @requires PHP 7
|
||||
* @dataProvider provideRegistrationArgs
|
||||
*/
|
||||
function testWeakTypes($type, $args) {
|
||||
public function testWeakTypes($type, $args) {
|
||||
if ($type == "onSignal") {
|
||||
$this->checkForSignalCapability();
|
||||
}
|
||||
@ -297,7 +297,7 @@ abstract class DriverTest extends TestCase {
|
||||
}
|
||||
|
||||
/** @dataProvider provideRegistrationArgs */
|
||||
function testDisableWithConsecutiveCancel($type, $args) {
|
||||
public function testDisableWithConsecutiveCancel($type, $args) {
|
||||
if ($type === "onSignal") {
|
||||
$this->checkForSignalCapability();
|
||||
}
|
||||
@ -317,7 +317,7 @@ abstract class DriverTest extends TestCase {
|
||||
}
|
||||
|
||||
/** @dataProvider provideRegistrationArgs */
|
||||
function testWatcherReferenceInfo($type, $args) {
|
||||
public function testWatcherReferenceInfo($type, $args) {
|
||||
if ($type === "onSignal") {
|
||||
$this->checkForSignalCapability();
|
||||
}
|
||||
@ -383,7 +383,7 @@ abstract class DriverTest extends TestCase {
|
||||
}
|
||||
|
||||
/** @dataProvider provideRegistrationArgs */
|
||||
function testWatcherRegistrationAndCancellationInfo($type, $args) {
|
||||
public function testWatcherRegistrationAndCancellationInfo($type, $args) {
|
||||
if ($type === "onSignal") {
|
||||
$this->checkForSignalCapability();
|
||||
}
|
||||
@ -447,7 +447,7 @@ abstract class DriverTest extends TestCase {
|
||||
}
|
||||
|
||||
/** @dataProvider provideRegistrationArgs */
|
||||
function testNoMemoryLeak($type, $args) {
|
||||
public function testNoMemoryLeak($type, $args) {
|
||||
if ($this->getTestResultObject()->getCollectCodeCoverageInformation()) {
|
||||
$this->markTestSkipped("Cannot run this test with code coverage active [code coverage consumes memory which makes it impossible to rely on memory_get_usage()]");
|
||||
}
|
||||
@ -571,7 +571,7 @@ abstract class DriverTest extends TestCase {
|
||||
* The first number of each tuple indicates the tick in which the watcher is supposed to execute, the second digit
|
||||
* indicates the order within the tick.
|
||||
*/
|
||||
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->start(function (Driver $loop) use (&$ticks) {
|
||||
$f = function () use ($loop) {
|
||||
@ -662,7 +662,7 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
function testSignalExecutionOrder() {
|
||||
public function testSignalExecutionOrder() {
|
||||
$this->checkForSignalCapability();
|
||||
|
||||
$this->expectOutputString("122222");
|
||||
@ -698,23 +698,23 @@ abstract class DriverTest extends TestCase {
|
||||
}
|
||||
|
||||
/** @expectedException \Amp\Loop\InvalidWatcherError */
|
||||
function testExceptionOnEnableNonexistentWatcher() {
|
||||
public function testExceptionOnEnableNonexistentWatcher() {
|
||||
try {
|
||||
$this->loop->enable("nonexistentWatcher");
|
||||
} catch (InvalidWatcherError $e) {
|
||||
$this->assertEquals("nonexistentWatcher", $e->getWatcherId());
|
||||
$this->assertSame("nonexistentWatcher", $e->getWatcherId());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
function testSuccessOnDisableNonexistentWatcher() {
|
||||
public function testSuccessOnDisableNonexistentWatcher() {
|
||||
$this->loop->disable("nonexistentWatcher");
|
||||
|
||||
// Otherwise risky, throwing fails the test
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
function testSuccessOnCancelNonexistentWatcher() {
|
||||
public function testSuccessOnCancelNonexistentWatcher() {
|
||||
$this->loop->cancel("nonexistentWatcher");
|
||||
|
||||
// Otherwise risky, throwing fails the test
|
||||
@ -722,27 +722,27 @@ abstract class DriverTest extends TestCase {
|
||||
}
|
||||
|
||||
/** @expectedException \Amp\Loop\InvalidWatcherError */
|
||||
function testExceptionOnReferenceNonexistentWatcher() {
|
||||
public function testExceptionOnReferenceNonexistentWatcher() {
|
||||
try {
|
||||
$this->loop->reference("nonexistentWatcher");
|
||||
} catch (InvalidWatcherError $e) {
|
||||
$this->assertEquals("nonexistentWatcher", $e->getWatcherId());
|
||||
$this->assertSame("nonexistentWatcher", $e->getWatcherId());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/** @expectedException \Amp\Loop\InvalidWatcherError */
|
||||
function testExceptionOnUnreferenceNonexistentWatcher() {
|
||||
public function testExceptionOnUnreferenceNonexistentWatcher() {
|
||||
try {
|
||||
$this->loop->unreference("nonexistentWatcher");
|
||||
} catch (InvalidWatcherError $e) {
|
||||
$this->assertEquals("nonexistentWatcher", $e->getWatcherId());
|
||||
$this->assertSame("nonexistentWatcher", $e->getWatcherId());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/** @expectedException \Amp\Loop\InvalidWatcherError */
|
||||
function testWatcherInvalidityOnDefer() {
|
||||
public function testWatcherInvalidityOnDefer() {
|
||||
$this->start(function (Driver $loop) {
|
||||
$loop->defer(function ($watcher) use ($loop) {
|
||||
$loop->enable($watcher);
|
||||
@ -751,7 +751,7 @@ abstract class DriverTest extends TestCase {
|
||||
}
|
||||
|
||||
/** @expectedException \Amp\Loop\InvalidWatcherError */
|
||||
function testWatcherInvalidityOnDelay() {
|
||||
public function testWatcherInvalidityOnDelay() {
|
||||
$this->start(function (Driver $loop) {
|
||||
$loop->delay($msDelay = 0, function ($watcher) use ($loop) {
|
||||
$loop->enable($watcher);
|
||||
@ -759,7 +759,7 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
function testEventsNotExecutedInSameTickAsEnabled() {
|
||||
public function testEventsNotExecutedInSameTickAsEnabled() {
|
||||
$this->start(function (Driver $loop) {
|
||||
$loop->defer(function () use ($loop) {
|
||||
$loop->defer(function () use ($loop, &$diswatchers, &$watchers) {
|
||||
@ -803,7 +803,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
function testEnablingWatcherAllowsSubsequentInvocation() {
|
||||
public function testEnablingWatcherAllowsSubsequentInvocation() {
|
||||
$loop = $this->loop;
|
||||
$increment = 0;
|
||||
$watcherId = $loop->defer(function () use (&$increment) {
|
||||
@ -812,14 +812,14 @@ abstract class DriverTest extends TestCase {
|
||||
$loop->disable($watcherId);
|
||||
$loop->delay($msDelay = 5, [$loop, "stop"]);
|
||||
$loop->run();
|
||||
$this->assertEquals(0, $increment);
|
||||
$this->assertSame(0, $increment);
|
||||
$loop->enable($watcherId);
|
||||
$loop->delay($msDelay = 5, [$loop, "stop"]);
|
||||
$loop->run();
|
||||
$this->assertEquals(1, $increment);
|
||||
$this->assertSame(1, $increment);
|
||||
}
|
||||
|
||||
function testUnresolvedEventsAreReenabledOnRunFollowingPreviousStop() {
|
||||
public function testUnresolvedEventsAreReenabledOnRunFollowingPreviousStop() {
|
||||
$increment = 0;
|
||||
$this->start(function (Driver $loop) use (&$increment) {
|
||||
$loop->defer([$loop, "stop"]);
|
||||
@ -832,13 +832,13 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
});
|
||||
|
||||
$this->assertEquals(0, $increment);
|
||||
$this->assertSame(0, $increment);
|
||||
\usleep(5000);
|
||||
});
|
||||
$this->assertEquals(1, $increment);
|
||||
$this->assertSame(1, $increment);
|
||||
}
|
||||
|
||||
function testTimerWatcherParameterOrder() {
|
||||
public function testTimerWatcherParameterOrder() {
|
||||
$this->start(function (Driver $loop) {
|
||||
$counter = 0;
|
||||
$loop->defer(function ($watcherId) use ($loop, &$counter) {
|
||||
@ -863,7 +863,7 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
function testStreamWatcherParameterOrder() {
|
||||
public function testStreamWatcherParameterOrder() {
|
||||
$this->start(function (Driver $loop) use (&$invoked) {
|
||||
$invoked = 0;
|
||||
$loop->onWritable(STDOUT, function ($watcherId, $stream) use ($loop, &$invoked) {
|
||||
@ -876,7 +876,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertSame(1, $invoked);
|
||||
}
|
||||
|
||||
function testDisablingWatcherPreventsSubsequentInvocation() {
|
||||
public function testDisablingWatcherPreventsSubsequentInvocation() {
|
||||
$this->start(function (Driver $loop) {
|
||||
$increment = 0;
|
||||
$watcherId = $loop->defer(function () use (&$increment) {
|
||||
@ -886,11 +886,11 @@ abstract class DriverTest extends TestCase {
|
||||
$loop->disable($watcherId);
|
||||
$loop->delay($msDelay = 5, [$loop, "stop"]);
|
||||
|
||||
$this->assertEquals(0, $increment);
|
||||
$this->assertSame(0, $increment);
|
||||
});
|
||||
}
|
||||
|
||||
function testImmediateExecution() {
|
||||
public function testImmediateExecution() {
|
||||
$loop = $this->loop;
|
||||
$increment = 0;
|
||||
$this->start(function (Driver $loop) use (&$increment) {
|
||||
@ -899,10 +899,10 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
$loop->defer([$loop, "stop"]);
|
||||
});
|
||||
$this->assertEquals(1, $increment);
|
||||
$this->assertSame(1, $increment);
|
||||
}
|
||||
|
||||
function testImmediatelyCallbacksDoNotRecurseInSameTick() {
|
||||
public function testImmediatelyCallbacksDoNotRecurseInSameTick() {
|
||||
$increment = 0;
|
||||
$this->start(function (Driver $loop) use (&$increment) {
|
||||
$loop->defer(function () use ($loop, &$increment) {
|
||||
@ -913,10 +913,10 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
$loop->defer([$loop, "stop"]);
|
||||
});
|
||||
$this->assertEquals(1, $increment);
|
||||
$this->assertSame(1, $increment);
|
||||
}
|
||||
|
||||
function testRunExecutesEventsUntilExplicitlyStopped() {
|
||||
public function testRunExecutesEventsUntilExplicitlyStopped() {
|
||||
$increment = 0;
|
||||
$this->start(function (Driver $loop) use (&$increment) {
|
||||
$loop->repeat($msInterval = 5, function ($watcherId) use ($loop, &$increment) {
|
||||
@ -926,14 +926,14 @@ abstract class DriverTest extends TestCase {
|
||||
}
|
||||
});
|
||||
});
|
||||
$this->assertEquals(10, $increment);
|
||||
$this->assertSame(10, $increment);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
* @expectedExceptionMessage loop error
|
||||
*/
|
||||
function testLoopAllowsExceptionToBubbleUpDuringStart() {
|
||||
public function testLoopAllowsExceptionToBubbleUpDuringStart() {
|
||||
$this->start(function (Driver $loop) {
|
||||
$loop->defer(function () {
|
||||
throw new \Exception("loop error");
|
||||
@ -945,7 +945,7 @@ abstract class DriverTest extends TestCase {
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage test
|
||||
*/
|
||||
function testLoopAllowsExceptionToBubbleUpFromRepeatingAlarmDuringStart() {
|
||||
public function testLoopAllowsExceptionToBubbleUpFromRepeatingAlarmDuringStart() {
|
||||
$this->start(function (Driver $loop) {
|
||||
$loop->repeat($msInterval = 1, function () {
|
||||
throw new \RuntimeException("test");
|
||||
@ -953,14 +953,14 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
function testErrorHandlerCapturesUncaughtException() {
|
||||
public function testErrorHandlerCapturesUncaughtException() {
|
||||
$msg = "";
|
||||
$this->loop->setErrorHandler($f = function () {
|
||||
});
|
||||
$oldErrorHandler = $this->loop->setErrorHandler(function (\Exception $error) use (&$msg) {
|
||||
$msg = $error->getMessage();
|
||||
});
|
||||
$this->assertEquals($f, $oldErrorHandler);
|
||||
$this->assertSame($f, $oldErrorHandler);
|
||||
$this->start(function (Driver $loop) {
|
||||
$loop->defer(function () {
|
||||
throw new \Exception("loop error");
|
||||
@ -973,7 +973,7 @@ abstract class DriverTest extends TestCase {
|
||||
* @expectedException \Exception
|
||||
* @expectedExceptionMessage errorception
|
||||
*/
|
||||
function testOnErrorFailure() {
|
||||
public function testOnErrorFailure() {
|
||||
$this->loop->setErrorHandler(function () {
|
||||
throw new \Exception("errorception");
|
||||
});
|
||||
@ -988,7 +988,7 @@ abstract class DriverTest extends TestCase {
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage test
|
||||
*/
|
||||
function testLoopException() {
|
||||
public function testLoopException() {
|
||||
$this->start(function (Driver $loop) {
|
||||
$loop->defer(function () use ($loop) {
|
||||
// force next tick, outside of primary startup tick
|
||||
@ -999,7 +999,7 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
function testOnSignalWatcher() {
|
||||
public function testOnSignalWatcher() {
|
||||
$this->checkForSignalCapability();
|
||||
|
||||
$this->expectOutputString("caught SIGUSR1");
|
||||
@ -1018,7 +1018,7 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
function testInitiallyDisabledOnSignalWatcher() {
|
||||
public function testInitiallyDisabledOnSignalWatcher() {
|
||||
$this->checkForSignalCapability();
|
||||
|
||||
$this->expectOutputString("caught SIGUSR1");
|
||||
@ -1043,7 +1043,7 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
function testNestedLoopSignalDispatch() {
|
||||
public function testNestedLoopSignalDispatch() {
|
||||
$this->checkForSignalCapability();
|
||||
|
||||
$this->expectOutputString("inner SIGUSR2\nouter SIGUSR1\n");
|
||||
@ -1079,7 +1079,7 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
function testCancelRemovesWatcher() {
|
||||
public function testCancelRemovesWatcher() {
|
||||
$invoked = false;
|
||||
|
||||
$this->start(function (Driver $loop) use (&$invoked) {
|
||||
@ -1098,7 +1098,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertTrue($invoked);
|
||||
}
|
||||
|
||||
function testOnWritableWatcher() {
|
||||
public function testOnWritableWatcher() {
|
||||
$flag = false;
|
||||
$this->start(function (Driver $loop) use (&$flag) {
|
||||
$loop->onWritable(STDOUT, function () use ($loop, &$flag) {
|
||||
@ -1110,7 +1110,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertTrue($flag);
|
||||
}
|
||||
|
||||
function testInitiallyDisabledWriteWatcher() {
|
||||
public function testInitiallyDisabledWriteWatcher() {
|
||||
$increment = 0;
|
||||
$this->start(function (Driver $loop) {
|
||||
$watcherId = $loop->onWritable(STDOUT, function () use (&$increment) {
|
||||
@ -1122,7 +1122,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertSame(0, $increment);
|
||||
}
|
||||
|
||||
function testInitiallyDisabledWriteWatcherIsTriggeredOnceEnabled() {
|
||||
public function testInitiallyDisabledWriteWatcherIsTriggeredOnceEnabled() {
|
||||
$this->expectOutputString("12");
|
||||
$this->start(function (Driver $loop) {
|
||||
$watcherId = $loop->onWritable(STDOUT, function () use ($loop) {
|
||||
@ -1138,7 +1138,7 @@ abstract class DriverTest extends TestCase {
|
||||
}
|
||||
|
||||
/** @expectedException \RuntimeException */
|
||||
function testStreamWatcherDoesntSwallowExceptions() {
|
||||
public function testStreamWatcherDoesntSwallowExceptions() {
|
||||
$this->start(function (Driver $loop) {
|
||||
$loop->onWritable(STDOUT, function () {
|
||||
throw new \RuntimeException;
|
||||
@ -1147,7 +1147,7 @@ abstract class DriverTest extends TestCase {
|
||||
});
|
||||
}
|
||||
|
||||
function testReactorRunsUntilNoWatchersRemain() {
|
||||
public function testReactorRunsUntilNoWatchersRemain() {
|
||||
$var1 = $var2 = 0;
|
||||
$this->start(function (Driver $loop) use (&$var1, &$var2) {
|
||||
$loop->repeat($msDelay = 1, function ($watcherId) use ($loop, &$var1) {
|
||||
@ -1166,7 +1166,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertSame(4, $var2);
|
||||
}
|
||||
|
||||
function testReactorRunsUntilNoWatchersRemainWhenStartedDeferred() {
|
||||
public function testReactorRunsUntilNoWatchersRemainWhenStartedDeferred() {
|
||||
$var1 = $var2 = 0;
|
||||
$this->start(function (Driver $loop) use (&$var1, &$var2) {
|
||||
$loop->defer(function () use ($loop, &$var1, &$var2) {
|
||||
@ -1187,7 +1187,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertSame(4, $var2);
|
||||
}
|
||||
|
||||
function testOptionalCallbackDataPassedOnInvocation() {
|
||||
public function testOptionalCallbackDataPassedOnInvocation() {
|
||||
$callbackData = new \StdClass;
|
||||
|
||||
$this->start(function (Driver $loop) use ($callbackData) {
|
||||
@ -1213,7 +1213,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertTrue($callbackData->onWritable);
|
||||
}
|
||||
|
||||
function testLoopStopPreventsTimerExecution() {
|
||||
public function testLoopStopPreventsTimerExecution() {
|
||||
$t = microtime(1);
|
||||
$this->start(function (Driver $loop) {
|
||||
$loop->delay($msDelay = 10000, function () {
|
||||
@ -1226,7 +1226,7 @@ abstract class DriverTest extends TestCase {
|
||||
$this->assertTrue($t + 0.1 > microtime(1));
|
||||
}
|
||||
|
||||
function testDeferEnabledInNextTick() {
|
||||
public function testDeferEnabledInNextTick() {
|
||||
$tick = function () {
|
||||
$this->loop->defer(function () {
|
||||
$this->loop->stop();
|
||||
@ -1248,14 +1248,14 @@ abstract class DriverTest extends TestCase {
|
||||
$this->loop->enable($watcher);
|
||||
$tick(); // disable + immediate enable after a tick should have no effect either
|
||||
|
||||
$this->assertEquals(4, $invoked);
|
||||
$this->assertSame(4, $invoked);
|
||||
}
|
||||
|
||||
// getState and setState are final, but test it here again to be sure
|
||||
function testRegistry() {
|
||||
public function testRegistry() {
|
||||
$this->assertNull($this->loop->getState("foo"));
|
||||
$this->loop->setState("foo", NAN);
|
||||
$this->assertTrue(is_nan($this->loop->getState("foo")));
|
||||
$this->assertNan($this->loop->getState("foo"));
|
||||
$this->loop->setState("foo", "1");
|
||||
$this->assertNull($this->loop->getState("bar"));
|
||||
$this->loop->setState("baz", -INF);
|
||||
@ -1267,12 +1267,12 @@ abstract class DriverTest extends TestCase {
|
||||
}
|
||||
|
||||
/** @dataProvider provideRegistryValues */
|
||||
function testRegistryValues($val) {
|
||||
public function testRegistryValues($val) {
|
||||
$this->loop->setState("foo", $val);
|
||||
$this->assertSame($val, $this->loop->getState("foo"));
|
||||
}
|
||||
|
||||
function provideRegistryValues() {
|
||||
public function provideRegistryValues() {
|
||||
return [
|
||||
["string"],
|
||||
[0],
|
||||
@ -1286,7 +1286,7 @@ abstract class DriverTest extends TestCase {
|
||||
];
|
||||
}
|
||||
|
||||
function testRethrowsFromCallbacks() {
|
||||
public function testRethrowsFromCallbacks() {
|
||||
foreach (["onReadable", "onWritable", "defer", "delay", "repeat", "onSignal"] as $watcher) {
|
||||
$promises = [
|
||||
new Failure(new \Exception("rethrow test")),
|
||||
@ -1309,7 +1309,6 @@ abstract class DriverTest extends TestCase {
|
||||
];
|
||||
|
||||
foreach ($promises as $promise) {
|
||||
|
||||
if ($watcher === "onSignal") {
|
||||
$this->checkForSignalCapability();
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class UvDriverTest extends DriverTest {
|
||||
}
|
||||
|
||||
public function testHandle() {
|
||||
$this->assertTrue(\is_resource($this->loop->getHandle()));
|
||||
$this->assertInternalType('resource', $this->loop->getHandle());
|
||||
}
|
||||
|
||||
public function testSupported() {
|
||||
|
@ -46,4 +46,4 @@ class LoopTest extends TestCase {
|
||||
public function testGetInto() {
|
||||
$this->assertSame(Loop::get()->getInfo(), Loop::getInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use Amp\Stream;
|
||||
class MapTest extends \PHPUnit\Framework\TestCase {
|
||||
public function testNoValuesEmitted() {
|
||||
$invoked = false;
|
||||
Loop::run(function () use (&$invoked){
|
||||
Loop::run(function () use (&$invoked) {
|
||||
$emitter = new Emitter;
|
||||
|
||||
$stream = Stream\map($emitter->stream(), function ($value) use (&$invoked) {
|
||||
@ -131,7 +131,7 @@ class MapTest extends \PHPUnit\Framework\TestCase {
|
||||
public function testStreamFails() {
|
||||
$invoked = false;
|
||||
$exception = new \Exception;
|
||||
Loop::run(function () use (&$invoked, &$reason, &$exception){
|
||||
Loop::run(function () use (&$invoked, &$reason, &$exception) {
|
||||
$emitter = new Emitter;
|
||||
|
||||
$stream = Stream\map($emitter->stream(), function ($value) use (&$invoked) {
|
||||
|
@ -30,17 +30,17 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
];
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
public function setUp() {
|
||||
$this->originalErrorHandler = Loop::setErrorHandler(function ($e) {
|
||||
throw $e;
|
||||
});
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
public function tearDown() {
|
||||
Loop::setErrorHandler($this->originalErrorHandler);
|
||||
}
|
||||
|
||||
function provideSuccessValues() {
|
||||
public function provideSuccessValues() {
|
||||
return [
|
||||
["string"],
|
||||
[0],
|
||||
@ -55,18 +55,16 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
];
|
||||
}
|
||||
|
||||
function testPromiseImplementsPromise()
|
||||
{
|
||||
public function testPromiseImplementsPromise() {
|
||||
list($promise) = $this->promise();
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
}
|
||||
|
||||
/** @dataProvider provideSuccessValues */
|
||||
function testPromiseSucceed($value)
|
||||
{
|
||||
public function testPromiseSucceed($value) {
|
||||
list($promise, $succeeder) = $this->promise();
|
||||
$promise->onResolve(function($e, $v) use (&$invoked, $value) {
|
||||
$this->assertSame(null, $e);
|
||||
$promise->onResolve(function ($e, $v) use (&$invoked, $value) {
|
||||
$this->assertNull($e);
|
||||
$this->assertSame($value, $v);
|
||||
$invoked = true;
|
||||
});
|
||||
@ -75,10 +73,10 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
}
|
||||
|
||||
/** @dataProvider provideSuccessValues */
|
||||
function testOnResolveOnSucceededPromise($value) {
|
||||
public function testOnResolveOnSucceededPromise($value) {
|
||||
list($promise, $succeeder) = $this->promise();
|
||||
$succeeder($value);
|
||||
$promise->onResolve(function($e, $v) use (&$invoked, $value) {
|
||||
$promise->onResolve(function ($e, $v) use (&$invoked, $value) {
|
||||
$this->assertSame(null, $e);
|
||||
$this->assertSame($value, $v);
|
||||
$invoked = true;
|
||||
@ -86,16 +84,16 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
$this->assertTrue($invoked);
|
||||
}
|
||||
|
||||
function testSuccessAllOnResolvesExecuted() {
|
||||
public function testSuccessAllOnResolvesExecuted() {
|
||||
list($promise, $succeeder) = $this->promise();
|
||||
$invoked = 0;
|
||||
|
||||
$promise->onResolve(function($e, $v) use (&$invoked) {
|
||||
$promise->onResolve(function ($e, $v) use (&$invoked) {
|
||||
$this->assertSame(null, $e);
|
||||
$this->assertSame(true, $v);
|
||||
$invoked++;
|
||||
});
|
||||
$promise->onResolve(function($e, $v) use (&$invoked) {
|
||||
$promise->onResolve(function ($e, $v) use (&$invoked) {
|
||||
$this->assertSame(null, $e);
|
||||
$this->assertSame(true, $v);
|
||||
$invoked++;
|
||||
@ -103,12 +101,12 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$succeeder(true);
|
||||
|
||||
$promise->onResolve(function($e, $v) use (&$invoked) {
|
||||
$promise->onResolve(function ($e, $v) use (&$invoked) {
|
||||
$this->assertSame(null, $e);
|
||||
$this->assertSame(true, $v);
|
||||
$invoked++;
|
||||
});
|
||||
$promise->onResolve(function($e, $v) use (&$invoked) {
|
||||
$promise->onResolve(function ($e, $v) use (&$invoked) {
|
||||
$this->assertSame(null, $e);
|
||||
$this->assertSame(true, $v);
|
||||
$invoked++;
|
||||
@ -117,7 +115,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
$this->assertSame(4, $invoked);
|
||||
}
|
||||
|
||||
function testPromiseExceptionFailure() {
|
||||
public function testPromiseExceptionFailure() {
|
||||
list($promise, , $failer) = $this->promise();
|
||||
$promise->onResolve(function ($e) use (&$invoked) {
|
||||
$this->assertSame(get_class($e), "RuntimeException");
|
||||
@ -127,7 +125,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
$this->assertTrue($invoked);
|
||||
}
|
||||
|
||||
function testOnResolveOnExceptionFailedPromise() {
|
||||
public function testOnResolveOnExceptionFailedPromise() {
|
||||
list($promise, , $failer) = $this->promise();
|
||||
$failer(new \RuntimeException);
|
||||
$promise->onResolve(function ($e) use (&$invoked) {
|
||||
@ -137,7 +135,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
$this->assertTrue($invoked);
|
||||
}
|
||||
|
||||
function testFailureAllOnResolvesExecuted() {
|
||||
public function testFailureAllOnResolvesExecuted() {
|
||||
list($promise, , $failer) = $this->promise();
|
||||
$invoked = 0;
|
||||
|
||||
@ -164,7 +162,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
$this->assertSame(4, $invoked);
|
||||
}
|
||||
|
||||
function testPromiseErrorFailure() {
|
||||
public function testPromiseErrorFailure() {
|
||||
if (PHP_VERSION_ID < 70000) {
|
||||
$this->markTestSkipped("Error only exists on PHP 7+");
|
||||
}
|
||||
@ -178,7 +176,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
$this->assertTrue($invoked);
|
||||
}
|
||||
|
||||
function testOnResolveOnErrorFailedPromise() {
|
||||
public function testOnResolveOnErrorFailedPromise() {
|
||||
if (PHP_VERSION_ID < 70000) {
|
||||
$this->markTestSkipped("Error only exists on PHP 7+");
|
||||
}
|
||||
@ -193,7 +191,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
}
|
||||
|
||||
/** Implementations MAY fail upon resolution with a Promise, but they definitely MUST NOT return a Promise */
|
||||
function testPromiseResolutionWithPromise() {
|
||||
public function testPromiseResolutionWithPromise() {
|
||||
list($success, $succeeder) = $this->promise();
|
||||
$succeeder(true);
|
||||
|
||||
@ -216,7 +214,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
function testThrowingInCallback() {
|
||||
public function testThrowingInCallback() {
|
||||
Loop::run(function () {
|
||||
$invoked = 0;
|
||||
|
||||
@ -244,11 +242,11 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
});
|
||||
$succeeder(true);
|
||||
|
||||
$this->assertEquals(4, $invoked);
|
||||
$this->assertSame(4, $invoked);
|
||||
});
|
||||
}
|
||||
|
||||
function testThrowingInCallbackContinuesOtherOnResolves() {
|
||||
public function testThrowingInCallbackContinuesOtherOnResolves() {
|
||||
Loop::run(function () {
|
||||
$invoked = 0;
|
||||
|
||||
@ -271,11 +269,11 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
});
|
||||
$succeeder(true);
|
||||
|
||||
$this->assertEquals(3, $invoked);
|
||||
$this->assertSame(3, $invoked);
|
||||
});
|
||||
}
|
||||
|
||||
function testThrowingInCallbackOnFailure() {
|
||||
public function testThrowingInCallbackOnFailure() {
|
||||
Loop::run(function () {
|
||||
$invoked = 0;
|
||||
Loop::setErrorHandler(function () use (&$invoked) {
|
||||
@ -304,30 +302,30 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
});
|
||||
$failer($exception);
|
||||
|
||||
$this->assertEquals(4, $invoked);
|
||||
$this->assertSame(4, $invoked);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7
|
||||
*/
|
||||
function testWeakTypes() {
|
||||
public function testWeakTypes() {
|
||||
$invoked = 0;
|
||||
list($promise, $succeeder) = $this->promise();
|
||||
|
||||
$expectedData = "15.24";
|
||||
|
||||
$promise->onResolve(function($e, int $v) use (&$invoked, $expectedData) {
|
||||
$promise->onResolve(function ($e, int $v) use (&$invoked, $expectedData) {
|
||||
$invoked++;
|
||||
$this->assertSame((int) $expectedData, $v);
|
||||
});
|
||||
$succeeder($expectedData);
|
||||
$promise->onResolve(function($e, int $v) use (&$invoked, $expectedData) {
|
||||
$promise->onResolve(function ($e, int $v) use (&$invoked, $expectedData) {
|
||||
$invoked++;
|
||||
$this->assertSame((int) $expectedData, $v);
|
||||
});
|
||||
|
||||
$this->assertEquals(2, $invoked);
|
||||
$this->assertSame(2, $invoked);
|
||||
}
|
||||
|
||||
public function testResolvedQueueUnrolling() {
|
||||
@ -439,4 +437,4 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$this->assertSame(3, $invoked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
Promise\some($promises)->onResolve($callback);
|
||||
|
||||
$this->assertInstanceOf(MultiReasonException::class, $reason);
|
||||
$this->assertEquals([$exception, $exception, $exception], $reason->getReasons());
|
||||
$this->assertSame([$exception, $exception, $exception], $reason->getReasons());
|
||||
}
|
||||
|
||||
public function testSuccessfulAndFailedPromisesArray() {
|
||||
@ -84,7 +84,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
Promise\some($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals([[], [0 => 1, 1 => 2, 2 => 3]], $result);
|
||||
$this->assertSame([[], [0 => 1, 1 => 2, 2 => 3]], $result);
|
||||
}
|
||||
|
||||
public function testArrayKeysPreserved() {
|
||||
@ -104,7 +104,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
Promise\some($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ class StructTest extends \PHPUnit\Framework\TestCase {
|
||||
*/
|
||||
public function testSetErrorWithSuggestion() {
|
||||
$struct = new StructTestFixture;
|
||||
$struct->callbac = function(){};
|
||||
$struct->callbac = function () {};
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user