From 2eb8eb76621624f5f048dccd44c3abfdeedc0268 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Tue, 20 Jun 2017 19:37:41 +0200 Subject: [PATCH] Clean up execute for tests --- test/BlockingDriverTest.php | 10 +++++++--- test/BlockingHandleTest.php | 10 +++++++--- test/EioDriverTest.php | 16 ++++++++++------ test/EioHandleTest.php | 16 ++++++++++------ test/UvDriverTest.php | 19 +++++++++++-------- test/UvHandleTest.php | 19 +++++++++++-------- 6 files changed, 56 insertions(+), 34 deletions(-) diff --git a/test/BlockingDriverTest.php b/test/BlockingDriverTest.php index 2675f0c..c4f5fba 100644 --- a/test/BlockingDriverTest.php +++ b/test/BlockingDriverTest.php @@ -2,11 +2,15 @@ namespace Amp\File\Test; +use Amp\File; +use Amp\Loop; +use function Amp\asyncCall; + class BlockingDriverTest extends DriverTest { protected function execute(callable $cb) { - \Amp\Loop::run(function () use ($cb) { - \Amp\File\filesystem(new \Amp\File\BlockingDriver); - \Amp\Promise\rethrow(new \Amp\Coroutine($cb())); + Loop::run(function () use ($cb) { + File\filesystem(new File\BlockingDriver); + asyncCall($cb); }); } } diff --git a/test/BlockingHandleTest.php b/test/BlockingHandleTest.php index 62b93f2..097f6b0 100644 --- a/test/BlockingHandleTest.php +++ b/test/BlockingHandleTest.php @@ -2,11 +2,15 @@ namespace Amp\File\Test; +use Amp\File; +use Amp\Loop; +use function Amp\asyncCall; + class BlockingHandleTest extends HandleTest { protected function execute(callable $cb) { - \Amp\Loop::run(function () use ($cb) { - \Amp\File\filesystem(new \Amp\File\BlockingDriver); - \Amp\Promise\rethrow(new \Amp\Coroutine($cb())); + Loop::run(function () use ($cb) { + File\filesystem(new File\BlockingDriver); + asyncCall($cb); }); } } diff --git a/test/EioDriverTest.php b/test/EioDriverTest.php index ef45151..d31c160 100644 --- a/test/EioDriverTest.php +++ b/test/EioDriverTest.php @@ -2,17 +2,21 @@ namespace Amp\File\Test; +use Amp\File; +use Amp\Loop; +use function Amp\asyncCall; + class EioDriverTest extends DriverTest { protected function execute(callable $cb) { - if (\extension_loaded("eio")) { - \Amp\Loop::run(function () use ($cb) { - \Amp\File\filesystem(new \Amp\File\EioDriver); - \Amp\Promise\rethrow(new \Amp\Coroutine($cb())); - }); - } else { + if (!\extension_loaded("eio")) { $this->markTestSkipped( "eio extension not loaded" ); } + + Loop::run(function () use ($cb) { + File\filesystem(new File\EioDriver); + asyncCall($cb); + }); } } diff --git a/test/EioHandleTest.php b/test/EioHandleTest.php index 8937f2c..5c345ae 100644 --- a/test/EioHandleTest.php +++ b/test/EioHandleTest.php @@ -2,17 +2,21 @@ namespace Amp\File\Test; +use Amp\File; +use Amp\Loop; +use function Amp\asyncCall; + class EioHandleTest extends AsyncHandleTest { protected function execute(callable $cb) { - if (\extension_loaded("eio")) { - \Amp\Loop::run(function () use ($cb) { - \Amp\File\filesystem(new \Amp\File\EioDriver); - \Amp\Promise\rethrow(new \Amp\Coroutine($cb())); - }); - } else { + if (!\extension_loaded("eio")) { $this->markTestSkipped( "eio extension not loaded" ); } + + Loop::run(function () use ($cb) { + File\filesystem(new File\EioDriver); + asyncCall($cb); + }); } } diff --git a/test/UvDriverTest.php b/test/UvDriverTest.php index 5b08695..e2e6f33 100644 --- a/test/UvDriverTest.php +++ b/test/UvDriverTest.php @@ -2,21 +2,24 @@ namespace Amp\File\Test; +use Amp\File; use Amp\Loop; +use function Amp\asyncCall; class UvDriverTest extends DriverTest { protected function execute(callable $cb) { - if (\extension_loaded("uv")) { - $loop = new Loop\UvDriver; - Loop::set($loop); - Loop::run(function () use ($cb, $loop) { - \Amp\File\filesystem(new \Amp\File\UvDriver($loop)); - \Amp\Promise\rethrow(new \Amp\Coroutine($cb())); - }); - } else { + if (!\extension_loaded("uv")) { $this->markTestSkipped( "php-uv extension not loaded" ); } + + $loop = new Loop\UvDriver; + + Loop::set($loop); + Loop::run(function () use ($cb, $loop) { + File\filesystem(new File\UvDriver($loop)); + asyncCall($cb); + }); } } diff --git a/test/UvHandleTest.php b/test/UvHandleTest.php index 504a358..bedb3ae 100644 --- a/test/UvHandleTest.php +++ b/test/UvHandleTest.php @@ -2,21 +2,24 @@ namespace Amp\File\Test; +use Amp\File; use Amp\Loop; +use function Amp\asyncCall; class UvHandleTest extends AsyncHandleTest { protected function execute(callable $cb) { - if (\extension_loaded("uv")) { - $loop = new Loop\UvDriver; - Loop::set($loop); - Loop::run(function () use ($cb, $loop) { - \Amp\File\filesystem(new \Amp\File\UvDriver($loop)); - \Amp\Promise\rethrow(new \Amp\Coroutine($cb())); - }); - } else { + if (!\extension_loaded("uv")) { $this->markTestSkipped( "php-uv extension not loaded" ); } + + $loop = new Loop\UvDriver; + + Loop::set($loop); + Loop::run(function () use ($cb, $loop) { + File\filesystem(new File\UvDriver($loop)); + asyncCall($cb); + }); } }