From 7a739e819ee65238c28fbd266ffdbca9e9322952 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Tue, 11 Feb 2020 08:18:38 +0100 Subject: [PATCH] Drop ext-eio --- README.md | 1 - composer.json | 5 +- phpunit.xml.dist | 2 +- src/Eio/Adapter.php | 539 --------------------- src/Eio/ConstTypeDetector.php | 48 -- src/Eio/OpenFlagResolver.php | 38 -- src/Eio/RuntimeException.php | 20 - src/Eio/UnexpectedValueException.php | 20 - src/Filesystem.php | 4 - tests/Adapters/AbstractAdaptersTest.php | 14 - tests/Eio/AdapterTest.php | 609 ------------------------ tests/Eio/ConstTypeDetectorTest.php | 72 --- tests/Eio/OpenFlagResolverTest.php | 30 -- tests/bootstrap.php | 20 - travis-init.sh | 7 - 15 files changed, 2 insertions(+), 1427 deletions(-) delete mode 100644 src/Eio/Adapter.php delete mode 100644 src/Eio/ConstTypeDetector.php delete mode 100644 src/Eio/OpenFlagResolver.php delete mode 100644 src/Eio/RuntimeException.php delete mode 100644 src/Eio/UnexpectedValueException.php delete mode 100644 tests/Eio/AdapterTest.php delete mode 100644 tests/Eio/ConstTypeDetectorTest.php delete mode 100644 tests/Eio/OpenFlagResolverTest.php delete mode 100644 tests/bootstrap.php diff --git a/README.md b/README.md index 239e0ba7..f6782dad 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,6 @@ Adapters ------------ * ChildProcessAdapter - Adapter using child processes to perform IO actions (default adapter if no extensions are installed) -* EioAdapter - Adapter using `ext-eio` Examples -------- diff --git a/composer.json b/composer.json index e7b67882..f2c1004a 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "react/filesystem", "description": "Asynchronous filesystem abstraction.", - "keywords": ["filesystem", "asynchronous", "eio"], + "keywords": ["filesystem", "asynchronous"], "license": "MIT", "authors": [ { @@ -22,9 +22,6 @@ "clue/block-react": "^1.1", "phpunit/phpunit": "^6.0 || ^5.0 || ^4.8" }, - "suggest": { - "ext-eio": "^1.2" - }, "autoload": { "psr-4": { "React\\Filesystem\\": "src/" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6a44c035..ba3da417 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,7 @@ processIsolation="false" stopOnFailure="false" syntaxCheck="false" - bootstrap="tests/bootstrap.php" + bootstrap="vendor/autoload.php" > diff --git a/src/Eio/Adapter.php b/src/Eio/Adapter.php deleted file mode 100644 index 3cd64789..00000000 --- a/src/Eio/Adapter.php +++ /dev/null @@ -1,539 +0,0 @@ - EIO_READDIR_STAT_ORDER, - ]; - - /** - * @param LoopInterface $loop - * @param array $options - */ - public function __construct(LoopInterface $loop, array $options = []) - { - eio_init(); - $this->loop = $loop; - $this->fd = eio_get_event_stream(); - $this->openFlagResolver = new OpenFlagResolver(); - $this->permissionFlagResolver = new PermissionFlagResolver(); - - $this->applyConfiguration($options); - } - - /** - * @param array $options - */ - protected function applyConfiguration(array $options) - { - $this->openFileLimiter = new OpenFileLimiter(\React\Filesystem\getOpenFileLimit($options)); - $this->options = array_merge_recursive($this->options, $options); - } - - /** - * @return bool - */ - public static function isSupported() - { - return extension_loaded('eio'); - } - - /** - * {@inheritDoc} - */ - public function getLoop() - { - return $this->loop; - } - - /** - * {@inheritDoc} - */ - public function setFilesystem(FilesystemInterface $filesystem) - { - $this->filesystem = $filesystem; - - $this->typeDetectors = [ - new ConstTypeDetector($this->filesystem), - new ModeTypeDetector($this->filesystem), - ]; - } - - /** - * {@inheritDoc} - */ - public function getFilesystem() - { - return $this->filesystem; - } - - /** - * {@inheritDoc} - */ - public function stat($filename) - { - return $this->callFilesystem('eio_lstat', [$filename])->then(function ($stat) { - $stat['atime'] = new DateTime('@' .$stat['atime']); - $stat['mtime'] = new DateTime('@' .$stat['mtime']); - $stat['ctime'] = new DateTime('@' .$stat['ctime']); - return \React\Promise\resolve($stat); - }); - } - - /** - * {@inheritDoc} - */ - public function unlink($filename) - { - return $this->callFilesystem('eio_unlink', [$filename]); - } - - /** - * {@inheritDoc} - */ - public function rename($fromFilename, $toFilename) - { - return $this->callFilesystem('eio_rename', [$fromFilename, $toFilename]); - } - - /** - * {@inheritDoc} - */ - public function chmod($path, $mode) - { - return $this->callFilesystem('eio_chmod', [$path, $mode]); - } - - /** - * {@inheritDoc} - */ - public function chown($path, $uid, $gid) - { - return $this->callFilesystem('eio_chown', [$path, $uid, $gid]); - } - - /** - * @param string $path - * @return PromiseInterface - */ - public function ls($path) - { - return ObjectStreamSink::promise($this->lsStream($path)); - } - - /** - * {@inheritDoc} - */ - public function lsStream($path) - { - $stream = new ObjectStream(); - - $this->callFilesystem('eio_readdir', [$path, $this->options['lsFlags']], false)->then(function ($result) use ($path, $stream) { - $this->processLsContents($path, $result, $stream); - }, function ($error) use ($stream) { - $stream->emit('error', [$error]); - $stream->close(); - }); - - return $stream; - } - - /** - * @param $basePath - * @param $result - * @param ObjectStream $stream - */ - protected function processLsContents($basePath, $result, ObjectStream $stream) - { - if (!isset($result['dents'])) { - $stream->close(); - return; - } - - $promises = []; - - foreach ($result['dents'] as $entry) { - $path = $basePath . DIRECTORY_SEPARATOR . $entry['name']; - $node = [ - 'path' => $path, - 'type' => $entry['type'], - ]; - $promises[] = \React\Filesystem\detectType($this->typeDetectors, $node)->then(function (NodeInterface $node) use ($stream) { - $stream->write($node); - - return \React\Promise\resolve(true); - }, function ($error) { - return \React\Promise\resolve(true); - }); - } - - \React\Promise\all($promises)->then(function () use ($stream) { - $stream->close(); - }, function ($error) use ($stream) { - $stream->close(); - }); - } - - /** - * {@inheritDoc} - */ - public function mkdir($path, $mode = self::CREATION_MODE) - { - return $this->callFilesystem('eio_mkdir', [ - $path, - $this->permissionFlagResolver->resolve($mode), - ]); - } - - /** - * {@inheritDoc} - */ - public function rmdir($path) - { - return $this->callFilesystem('eio_rmdir', [$path]); - } - - /** - * {@inheritDoc} - */ - public function open($path, $flags, $mode = self::CREATION_MODE) - { - $eioFlags = $this->openFlagResolver->resolve($flags); - $mode = $this->permissionFlagResolver->resolve($mode); - return $this->openFileLimiter->open()->then(function () use ($path, $eioFlags, $mode) { - return $this->callFilesystem('eio_open', [ - $path, - $eioFlags, - $mode, - ]); - })->otherwise(function ($error) { - $this->openFileLimiter->close(); - return \React\Promise\reject($error); - }); - } - - /** - * {@inheritDoc} - */ - public function close($fd) - { - return $this->callFilesystem('eio_close', [$fd])->always(function () { - $this->openFileLimiter->close(); - }); - } - - /** - * Reads the entire file. - * - * This is an optimization for adapters which can optimize - * the open -> (seek ->) read -> close sequence into one call. - * - * @param string $path - * @param int $offset - * @param int|null $length - * @return PromiseInterface - */ - public function getContents($path, $offset = 0, $length = null) - { - if ($length === null) { - return $this->stat($path)->then(function ($stat) use ($path, $offset) { - return $this->getContents($path, $offset, $stat['size']); - }); - } - - return $this->open($path, 'r')->then(function ($fd) use ($offset, $length) { - return $this->read($fd, $length, $offset)->always(function () use ($fd) { - return $this->close($fd); - }); - }); - } - - /** - * Writes the given content to the specified file. - * If the file exists, the file is truncated. - * If the file does not exist, the file will be created. - * - * This is an optimization for adapters which can optimize - * the open -> write -> close sequence into one call. - * - * @param string $path - * @param string $content - * @return PromiseInterface - * @see AdapterInterface::appendContents() - */ - public function putContents($path, $content) - { - return $this->open($path, 'cw')->then(function ($fd) use ($content) { - return $this->write($fd, $content, strlen($content), 0)->always(function () use ($fd) { - return $this->close($fd); - }); - }); - } - - /** - * Appends the given content to the specified file. - * If the file does not exist, the file will be created. - * - * This is an optimization for adapters which can optimize - * the open -> write -> close sequence into one call. - * - * @param string $path - * @param string $content - * @return PromiseInterface - * @see AdapterInterface::putContents() - */ - public function appendContents($path, $content) - { - return $this->open($path, 'cwa')->then(function ($fd) use ($content) { - return $this->write($fd, $content, strlen($content), 0)->always(function () use ($fd) { - return $this->close($fd); - }); - }); - } - - /** - * {@inheritDoc} - */ - public function touch($path, $mode = self::CREATION_MODE, $time = null) - { - return $this->stat($path)->then(function () use ($path, $time) { - if ($time === null) { - $time = microtime(true); - } - return $this->callFilesystem('eio_utime', [ - $path, - $time, - $time, - ]); - }, function () use ($path, $mode) { - return $this->openFileLimiter->open()->then(function () use ($path, $mode) { - return $this->callFilesystem('eio_open', [ - $path, - EIO_O_CREAT, - $this->permissionFlagResolver->resolve($mode), - ]); - })->then(function ($fd) use ($path) { - return $this->close($fd); - }); - }); - } - - /** - * {@inheritDoc} - */ - public function read($fileDescriptor, $length, $offset) - { - return $this->callFilesystem('eio_read', [ - $fileDescriptor, - $length, - $offset, - ]); - } - - /** - * {@inheritDoc} - */ - public function write($fileDescriptor, $data, $length, $offset) - { - return $this->callFilesystem('eio_write', [ - $fileDescriptor, - $data, - $length, - $offset, - ]); - } - - /** - * {@inheritDoc} - */ - public function readlink($path) - { - return $this->callFilesystem('eio_readlink', [ - $path, - ]); - } - - /** - * {@inheritDoc} - */ - public function symlink($fromPath, $toPath) - { - return $this->callFilesystem('eio_symlink', [ - $fromPath, - $toPath, - ]); - } - - /** - * @inheritDoc - */ - public function detectType($path) - { - return \React\Filesystem\detectType($this->typeDetectors, [ - 'path' => $path, - ]); - } - - /** - * @param string $function - * @param array $args - * @param int $errorResultCode - * @return \React\Promise\Promise - */ - public function callFilesystem($function, $args, $errorResultCode = -1) - { - return new Promise(function ($resolve, $reject) use ($function, $args, $errorResultCode) { - if ($this->loopRunning) { - try { - $resolve($this->executeDelayedCall($function, $args, $errorResultCode)); - } catch (\Exception $exception) { - $reject($exception); - } catch (\Throwable $exception) { - $reject($exception); - } - - return; - } - - - // Run this in a future tick to make sure all EIO calls are run within the loop - $this->loop->futureTick(function () use ($function, $args, $errorResultCode, $resolve, $reject) { - try { - $resolve($this->executeDelayedCall($function, $args, $errorResultCode)); - } catch (\Exception $exception) { - $reject($exception); - } catch (\Throwable $exception) { - $reject($exception); - } - }); - - }); - } - - protected function executeDelayedCall($function, $args, $errorResultCode) - { - $this->register(); - return new Promise(function ($resolve, $reject) use ($function, $args, $errorResultCode) { - $args[] = EIO_PRI_DEFAULT; - $args[] = function ($data, $result, $req) use ($resolve, $reject, $errorResultCode, $function, $args) { - if ($result == $errorResultCode) { - $exception = new UnexpectedValueException(@eio_get_last_error($req)); - $exception->setArgs($args); - $reject($exception); - return; - } - - $resolve($result); - }; - - if (!call_user_func_array($function, $args)) { - $name = $function; - if (!is_string($function)) { - $name = get_class($function); - } - $exception = new RuntimeException('Unknown error calling "' . $name . '"'); - $exception->setArgs($args); - $reject($exception); - }; - }); - } - - protected function register() - { - if ($this->active) { - return; - } - - $this->active = true; - $this->loop->addReadStream($this->fd, [$this, 'handleEvent']); - } - - protected function unregister() - { - if (!$this->active) { - return; - } - - $this->active = false; - $this->loop->removeReadStream($this->fd, [$this, 'handleEvent']); - } - - public function handleEvent() - { - if ($this->workPendingCount() == 0) { - return; - } - - while (eio_npending()) { - eio_poll(); - } - - if ($this->workPendingCount() == 0) { - $this->unregister(); - } - } - - public function workPendingCount() - { - return eio_nreqs() + eio_npending() + eio_nready(); - } -} diff --git a/src/Eio/ConstTypeDetector.php b/src/Eio/ConstTypeDetector.php deleted file mode 100644 index 74a5bb80..00000000 --- a/src/Eio/ConstTypeDetector.php +++ /dev/null @@ -1,48 +0,0 @@ - 'dir', - EIO_DT_REG => 'file', - EIO_DT_LNK => 'constructLink', - ]; - - /** - * @var FilesystemInterface - */ - protected $filesystem; - - /** - * @param FilesystemInterface $filesystem - */ - public function __construct(FilesystemInterface $filesystem) - { - $this->filesystem = $filesystem; - } - - /** - * @param array $node - * @return \React\Promise\PromiseInterface - */ - public function detect(array $node) - { - if (!isset($node['type']) || !isset($this->mapping[$node['type']])) { - return \React\Promise\reject(new Exception('Unknown node type')); - } - - return \React\Promise\resolve([ - $this->filesystem, - $this->mapping[$node['type']], - ]); - } -} diff --git a/src/Eio/OpenFlagResolver.php b/src/Eio/OpenFlagResolver.php deleted file mode 100644 index d09b1da3..00000000 --- a/src/Eio/OpenFlagResolver.php +++ /dev/null @@ -1,38 +0,0 @@ - EIO_O_RDWR, - 'a' => EIO_O_APPEND, - 'c' => EIO_O_CREAT, - 'e' => EIO_O_EXCL, - 'n' => EIO_O_NONBLOCK, - 'r' => EIO_O_RDONLY, - 't' => EIO_O_TRUNC, - 'w' => EIO_O_WRONLY, - ]; - - /** - * {@inheritDoc} - */ - public function defaultFlags() - { - return static::DEFAULT_FLAG; - } - - /** - * {@inheritDoc} - */ - public function flagMapping() - { - return $this->flagMapping; - } -} diff --git a/src/Eio/RuntimeException.php b/src/Eio/RuntimeException.php deleted file mode 100644 index 7ff5a4cc..00000000 --- a/src/Eio/RuntimeException.php +++ /dev/null @@ -1,20 +0,0 @@ -args = $args; - } - - public function getArgs() - { - return $this->args; - } -} diff --git a/src/Eio/UnexpectedValueException.php b/src/Eio/UnexpectedValueException.php deleted file mode 100644 index cfd56d0e..00000000 --- a/src/Eio/UnexpectedValueException.php +++ /dev/null @@ -1,20 +0,0 @@ -args = $args; - } - - public function getArgs() - { - return $this->args; - } -} diff --git a/src/Filesystem.php b/src/Filesystem.php index d2bd474e..b27db651 100644 --- a/src/Filesystem.php +++ b/src/Filesystem.php @@ -57,10 +57,6 @@ public static function getSupportedAdapters() { $adapters = []; - if (Eio\Adapter::isSupported()) { - $adapters[] = 'Eio'; - } - if (ChildProcess\Adapter::isSupported()) { $adapters[] = 'ChildProcess'; } diff --git a/tests/Adapters/AbstractAdaptersTest.php b/tests/Adapters/AbstractAdaptersTest.php index d9127ea3..2846994c 100644 --- a/tests/Adapters/AbstractAdaptersTest.php +++ b/tests/Adapters/AbstractAdaptersTest.php @@ -4,7 +4,6 @@ use React\EventLoop; use React\Filesystem\ChildProcess; -use React\Filesystem\Eio; use React\Filesystem\Filesystem; use React\Filesystem\Pthreads; use React\Tests\Filesystem\TestCase; @@ -58,10 +57,6 @@ protected function adapterFactory(&$adapters, $loopSlug, callable $loopFactory) $adapters[$loopSlug . '-factory'] = $this->getFacoryProvider($loopFactory); $adapters[$loopSlug . '-child-process'] = $this->getChildProcessProvider($loopFactory); - if (extension_loaded('eio')) { - $adapters[$loopSlug . '-eio'] = $this->getEioProvider($loopFactory); - } - if (extension_loaded('pthreads')) { $adapters[$loopSlug . '-pthreads'] = $this->getPthreadsProvider($loopFactory); } @@ -76,15 +71,6 @@ protected function getChildProcessProvider(callable $loopFactory) ]; } - protected function getEioProvider(callable $loopFactory) - { - $loop = $loopFactory(); - return [ - $loop, - new Eio\Adapter($loop), - ]; - } - protected function getFacoryProvider(callable $loopFactory) { $loop = $loopFactory(); diff --git a/tests/Eio/AdapterTest.php b/tests/Eio/AdapterTest.php deleted file mode 100644 index 1e525588..00000000 --- a/tests/Eio/AdapterTest.php +++ /dev/null @@ -1,609 +0,0 @@ -assertTrue(function_exists('eio_init')); - } - - public function testInterface() - { - $this->assertInstanceOf( - 'React\Filesystem\AdapterInterface', - new Adapter($this->getMock('React\EventLoop\LoopInterface')) - ); - } - - public function testGetLoop() - { - $loop = $this->getMock('React\EventLoop\LoopInterface'); - $filesystem = new Adapter($loop); - $this->assertSame($loop, $filesystem->getLoop()); - } - - public function testGetSetFilesystem() - { - $loop = $this->getMock('React\EventLoop\LoopInterface'); - $filesystem = new Adapter($loop, [ - 'pool' => [ - 'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy', - ], - ]); - - $this->assertNull($filesystem->getFilesystem()); - $fs = \React\Filesystem\Filesystem::createFromAdapter($this->mockAdapter()); - $filesystem->setFilesystem($fs); - - $this->assertSame($fs, $filesystem->getFilesystem()); - } - - public function testCallFilesystemCallsProvider() - { - $pathName = 'foo.bar'; - return [ - [ - 'unlink', - 'eio_unlink', - [ - $pathName, - ], - [ - $pathName, - ], - ], - [ - 'rename', - 'eio_rename', - [ - $pathName, - str_rot13($pathName), - ], - [ - $pathName, - str_rot13($pathName), - ], - ], - [ - 'chmod', - 'eio_chmod', - [ - $pathName, - 123, - ], - [ - $pathName, - 123, - ], - ], - [ - 'chown', - 'eio_chown', - [ - $pathName, - 1, - 2, - ], - [ - $pathName, - 1, - 2, - ], - ], - [ - 'mkdir', - 'eio_mkdir', - [ - $pathName, - ], - [ - $pathName, - (new PermissionFlagResolver())->resolve(Adapter::CREATION_MODE), - ], - ], - [ - 'mkdir', - 'eio_mkdir', - [ - $pathName, - 'rwxrwxrwx', - ], - [ - $pathName, - (new PermissionFlagResolver())->resolve('rwxrwxrwx'), - ], - ], - [ - 'rmdir', - 'eio_rmdir', - [ - $pathName, - ], - [ - $pathName, - ], - ], - [ - 'close', - 'eio_close', - [ - $pathName, - ], - [ - $pathName, - ], - ], - [ - 'read', - 'eio_read', - [ - $pathName, - 123, - 456, - ], - [ - $pathName, - 123, - 456, - ], - ], - [ - 'write', - 'eio_write', - [ - $pathName, - 'abc', - 3, - 456, - ], - [ - $pathName, - 'abc', - 3, - 456, - ], - ], - ]; - } - - /** - * @dataProvider testCallFilesystemCallsProvider - */ - public function testCallFilesystemCalls($externalMethod, $internalMethod, $externalCallArgs, $internalCallArgs, $errorResultCode = -1) - { - $promise = new FulfilledPromise(); - - $loop = Factory::create(); - - $filesystem = $this->getMock('React\Filesystem\Eio\Adapter', [ - 'callFilesystem', - ], [ - $loop, - ]); - - $filesystem - ->expects($this->once()) - ->method('callFilesystem') - ->with($internalMethod, $internalCallArgs, $errorResultCode) - ->will($this->returnValue($promise)) - ; - - $this->assertInstanceOf('React\Promise\ExtendedPromiseInterface', call_user_func_array([$filesystem, $externalMethod], $externalCallArgs)); - - $loop->run(); - } - - public function testHandleEvent() - { - $filesystem = $this->getMock('React\Filesystem\Eio\Adapter', [ - 'workPendingCount', - 'unregister', - ], [ - $this->getMock('React\EventLoop\LoopInterface'), - ]); - - $filesystem - ->expects($this->once()) - ->method('unregister') - ->with() - ; - - $filesystem - ->expects($this->at(0)) - ->method('workPendingCount') - ->with() - ->will($this->returnValue(1)) - ; - - $filesystem - ->expects($this->at(1)) - ->method('workPendingCount') - ->with() - ->will($this->returnValue(0)) - ; - - $filesystem->handleEvent(); - } - - public function testHandleEventNothingToDo() - { - $filesystem = $this->getMock('React\Filesystem\Eio\Adapter', [ - 'workPendingCount', - 'unregister', - ], [ - $this->getMock('React\EventLoop\LoopInterface'), - ]); - - $filesystem - ->expects($this->at(0)) - ->method('workPendingCount') - ->with() - ->will($this->returnValue(0)) - ; - - $filesystem - ->expects($this->never()) - ->method('unregister') - ->with() - ; - - $filesystem->handleEvent(); - } - - public function testExecuteDelayedCall() - { - $loop = $this->getMock('React\EventLoop\LoopInterface', [ - 'addReadStream', - 'addWriteStream', - 'removeReadStream', - 'removeWriteStream', - 'removeStream', - 'addTimer', - 'addPeriodicTimer', - 'cancelTimer', - 'isTimerActive', - 'nextTick', - 'futureTick', - 'tick', - 'run', - 'stop', - 'addSignal', - 'removeSignal', - ]); - - $filesystem = new Adapter($loop); - - $loop - ->expects($this->exactly(2)) - ->method('futureTick') - ->with($this->isType('callable')) - ->will($this->returnCallback(function ($resolveCb) { - $resolveCb(); - })) - ; - - $loop - ->expects($this->once()) - ->method('addReadStream') - ->with($this->isType('resource'), [ - $filesystem, - 'handleEvent', - ]) - ; - - $calledFunction = false; - $calledCallback = false; - $filesystem->callFilesystem(function ($priority, $callback) use (&$calledFunction) { - $this->assertSame(EIO_PRI_DEFAULT, $priority); - $callback('', 0, 0); - $calledFunction = true; - return true; - }, [])->then(function () use (&$calledCallback) { - $calledCallback = true; - }); - $filesystem->callFilesystem(function () { - return true; - }, []); - - $this->assertTrue($calledFunction); - $this->assertTrue($calledCallback); - } - - public function testExecuteDelayedCallFailed() - { - $loop = $this->getMock('React\EventLoop\LoopInterface', [ - 'addReadStream', - 'addWriteStream', - 'removeReadStream', - 'removeWriteStream', - 'removeStream', - 'addTimer', - 'addPeriodicTimer', - 'cancelTimer', - 'isTimerActive', - 'nextTick', - 'futureTick', - 'tick', - 'run', - 'stop', - 'addSignal', - 'removeSignal', - ]); - - $filesystem = new Adapter($loop); - - $loop - ->expects($this->once()) - ->method('futureTick') - ->with($this->isType('callable')) - ->will($this->returnCallback(function ($resolveCb) { - $resolveCb(); - })) - ; - - $loop - ->expects($this->once()) - ->method('addReadStream') - ->with($this->isType('resource'), [ - $filesystem, - 'handleEvent', - ]) - ; - - $calledFunction = false; - $calledCallback = false; - $filesystem->callFilesystem(function ($priority, $callback) use (&$calledFunction) { - $this->assertSame(EIO_PRI_DEFAULT, $priority); - $callback('', -1, 0); - $calledFunction = true; - return true; - }, [])->then(null, function ($e) use (&$calledCallback) { - $this->assertInstanceOf('UnexpectedValueException', $e); - $calledCallback = true; - }); - - $this->assertTrue($calledFunction); - $this->assertTrue($calledCallback); - } - - public function testExecuteDelayedCallFailedResult() - { - $loop = $this->getMock('React\EventLoop\LoopInterface', [ - 'addReadStream', - 'addWriteStream', - 'removeReadStream', - 'removeWriteStream', - 'removeStream', - 'addTimer', - 'addPeriodicTimer', - 'cancelTimer', - 'isTimerActive', - 'nextTick', - 'futureTick', - 'tick', - 'run', - 'stop', - 'addSignal', - 'removeSignal', - ]); - - $filesystem = new Adapter($loop); - - $loop - ->expects($this->once()) - ->method('futureTick') - ->with($this->isType('callable')) - ->will($this->returnCallback(function ($resolveCb) { - $resolveCb(); - })) - ; - - $loop - ->expects($this->once()) - ->method('addReadStream') - ->with($this->isType('resource'), [ - $filesystem, - 'handleEvent', - ]) - ; - - $calledFunction = false; - $calledCallback = false; - $filesystem->callFilesystem(function ($priority, $callback) use (&$calledFunction) { - $this->assertSame(EIO_PRI_DEFAULT, $priority); - $callback('', -1, 0); - $calledFunction = true; - return false; - }, [])->then(null, function ($e) use (&$calledCallback) { - $this->assertInstanceOf('UnexpectedValueException', $e); - $calledCallback = true; - }); - - $this->assertTrue($calledFunction); - $this->assertTrue($calledCallback); - } - - public function testUnregister() - { - $loop = $this->getMock('React\EventLoop\LoopInterface', [ - 'addReadStream', - 'addWriteStream', - 'removeReadStream', - 'removeWriteStream', - 'removeStream', - 'addTimer', - 'addPeriodicTimer', - 'cancelTimer', - 'isTimerActive', - 'nextTick', - 'futureTick', - 'tick', - 'run', - 'stop', - 'addSignal', - 'removeSignal', - ]); - - $filesystem = $this->getMock('React\Filesystem\Eio\Adapter', [ - 'workPendingCount', - ], [ - $loop, - ]); - - $filesystem - ->expects($this->at(0)) - ->method('workPendingCount') - ->with() - ->will($this->returnValue(1)) - ; - - $filesystem - ->expects($this->at(1)) - ->method('workPendingCount') - ->with() - ->will($this->returnValue(0)) - ; - - $loop - ->expects($this->once()) - ->method('futureTick') - ->with($this->isType('callable')) - ->will($this->returnCallback(function ($resolveCb) { - $resolveCb(); - })) - ; - - $loop - ->expects($this->once()) - ->method('removeReadStream') - ->with($this->isType('resource'), [ - $filesystem, - 'handleEvent', - ]) - ->will($this->returnValue(1)) - ; - - $filesystem->callFilesystem(function () { - return true; - }, []); - - $filesystem->handleEvent(); - } - - public function testUnregisterInactive() - { - $loop = $this->getMock('React\EventLoop\LoopInterface', [ - 'addReadStream', - 'addWriteStream', - 'removeReadStream', - 'removeWriteStream', - 'removeStream', - 'addTimer', - 'addPeriodicTimer', - 'cancelTimer', - 'isTimerActive', - 'nextTick', - 'futureTick', - 'tick', - 'run', - 'stop', - 'addSignal', - 'removeSignal', - ]); - - $filesystem = $this->getMock('React\Filesystem\Eio\Adapter', [ - 'workPendingCount', - ], [ - $loop, - ]); - - $filesystem - ->expects($this->at(0)) - ->method('workPendingCount') - ->with() - ->will($this->returnValue(1)) - ; - - $filesystem - ->expects($this->at(1)) - ->method('workPendingCount') - ->with() - ->will($this->returnValue(0)) - ; - - $loop - ->expects($this->never()) - ->method('removeReadStream') - ->with($this->isType('resource'), [ - $filesystem, - 'handleData', - ]) - ->will($this->returnValue(1)) - ; - - $filesystem->handleEvent(); - } - - public function testWorkPendingCount() - { - $this->assertInternalType('int', (new Adapter($this->getMock('React\EventLoop\LoopInterface')))->workPendingCount()); - } - - public function testGetContents() - { - $loop = \React\EventLoop\Factory::create(); - $adapter = new Adapter($loop); - - $contents = $this->await($adapter->getContents(__FILE__), $loop); - $this->assertSame(file_get_contents(__FILE__), $contents); - } - - public function testGetContentsMinMax() - { - $loop = \React\EventLoop\Factory::create(); - $adapter = new Adapter($loop); - - $contents = $this->await($adapter->getContents(__FILE__, 5, 10), $loop); - $this->assertSame(file_get_contents(__FILE__, false, null, 5, 10), $contents); - } - - public function testPutContents() - { - $loop = \React\EventLoop\Factory::create(); - $adapter = new Adapter($loop); - - $tempFile = $this->tmpDir . uniqid('', true); - $contents = sha1_file(__FILE__); - - $this->await($adapter->putContents($tempFile, $contents), $loop); - $this->assertSame($contents, file_get_contents($tempFile)); - } - - public function testAppendContents() - { - $loop = \React\EventLoop\Factory::create(); - $adapter = new Adapter($loop); - - $tempFile = $this->tmpDir . uniqid('', true); - $contents = sha1_file(__FILE__); - - file_put_contents($tempFile, $contents); - $time = sha1(time()); - $contents .= $time; - - $this->await($adapter->appendContents($tempFile, $time), $loop); - $this->assertSame($contents, file_get_contents($tempFile)); - } -} diff --git a/tests/Eio/ConstTypeDetectorTest.php b/tests/Eio/ConstTypeDetectorTest.php deleted file mode 100644 index f5cab9c2..00000000 --- a/tests/Eio/ConstTypeDetectorTest.php +++ /dev/null @@ -1,72 +0,0 @@ -getMock('React\EventLoop\LoopInterface'), [ - 'pool' => [ - 'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy', - ], - ]); - (new ConstTypeDetector($filesystem))->detect([ - 'type' => $const, - ])->then(function ($result) use ($filesystem, $method, &$callbackFired) { - $this->assertSame([ - $filesystem, - $method, - ], $result); - $callbackFired = true; - }); - - $this->assertTrue($callbackFired); - } - - public function testDetectUnknown() - { - $callbackFired = false; - - $filesystem = Filesystem::create($this->getMock('React\EventLoop\LoopInterface'), [ - 'pool' => [ - 'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy', - ], - ]); - (new ConstTypeDetector($filesystem))->detect([ - 'type' => 123, - ])->otherwise(function ($result) use (&$callbackFired) { - $this->assertInstanceOf('Exception', $result); - $callbackFired = true; - }); - - $this->assertTrue($callbackFired); - } -} diff --git a/tests/Eio/OpenFlagResolverTest.php b/tests/Eio/OpenFlagResolverTest.php deleted file mode 100644 index 94ce5587..00000000 --- a/tests/Eio/OpenFlagResolverTest.php +++ /dev/null @@ -1,30 +0,0 @@ -resolver = new OpenFlagResolver(); - } - - public function tearDown() - { - unset($this->resolver); - parent::tearDown(); - } - - - public function testDefaultFlags() - { - $this->assertSame(OpenFlagResolver::DEFAULT_FLAG, $this->resolver->defaultFlags()); - } -} diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 0c784510..00000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,20 +0,0 @@ -