예제 #1
0
 public function testSetFilesystemAndInvoker()
 {
     $loop = $this->getMock('React\\EventLoop\\StreamSelectLoop');
     $adapter = $this->getMock('React\\Filesystem\\Eio\\Adapter', [], [$loop]);
     $invoker = new InstantInvoker($adapter);
     $adapter->expects($this->at(0))->method('setFilesystem')->with($this->isInstanceOf('React\\Filesystem\\Filesystem'));
     $adapter->expects($this->at(1))->method('setInvoker')->with($invoker);
     Filesystem::createFromAdapter($adapter)->setInvoker($invoker);
 }
 public function testCreateNameNParentFromFilename()
 {
     $node = new File('/foo/bar/baz/rabbit/kitten/index.php', Filesystem::createFromAdapter($this->getMock('React\\Filesystem\\Eio\\Adapter', [], [$this->getMock('React\\EventLoop\\StreamSelectLoop')])));
     foreach ([['index.php', '/foo/bar/baz/rabbit/kitten/index.php'], ['kitten', '/foo/bar/baz/rabbit/kitten/'], ['rabbit', '/foo/bar/baz/rabbit/'], ['baz', '/foo/bar/baz/'], ['bar', '/foo/bar/'], ['foo', '/foo/'], ['', '/']] as $names) {
         $this->assertSame($names[0], $node->getName());
         $this->assertSame($names[1], $node->getPath());
         $node = $node->getParent();
     }
 }
 public function testDetectUnknown()
 {
     $callbackFired = false;
     $adapter = $this->getMock('React\\Filesystem\\Eio\\Adapter', ['stat'], [$this->getMock('React\\EventLoop\\StreamSelectLoop')]);
     $adapter->expects($this->any())->method('stat')->with('foo.bar')->will($this->returnValue(new FulfilledPromise(['mode' => 0x3000])));
     $filesystem = Filesystem::createFromAdapter($adapter);
     (new ModeTypeDetector($filesystem))->detect(['path' => 'foo.bar'])->otherwise(function ($result) use(&$callbackFired) {
         $this->assertSame(null, $result);
         $callbackFired = true;
     });
     $this->assertTrue($callbackFired);
 }
 public function testExecute()
 {
     $filesystem = $this->getMock('React\\Filesystem\\Eio\\Adapter', [], [$this->getMock('React\\EventLoop\\LoopInterface')]);
     $node = $this->getMock('React\\Filesystem\\Node\\Directory', ['ls', 'chmod'], ['foo.bar', Filesystem::createFromAdapter($filesystem)]);
     $promise = $this->getMock('React\\Promise\\PromiseInterface');
     $node->expects($this->once())->method('ls')->with()->will($this->returnValue($promise));
     $fileDent = $this->getMock('React\\Filesystem\\Node\\File', ['chmod'], ['foo', Filesystem::createFromAdapter($filesystem)]);
     $node->expects($this->once())->method('chmod')->with(123)->will($this->returnValue(new FulfilledPromise()));
     $directoryDent = $this->getMock('React\\Filesystem\\Node\\Directory', ['chmodRecursive'], ['foo', Filesystem::createFromAdapter($filesystem)]);
     $directoryDent->expects($this->once())->method('chmodRecursive')->with(123)->will($this->returnValue(new FulfilledPromise()));
     $finalPromise = $this->getMock('React\\Promise\\PromiseInterface');
     $node->expects($this->once())->method('chmod')->with(123)->will($this->returnValue($finalPromise));
     $dents = [$fileDent, $directoryDent];
     $promise->expects($this->once())->method('then')->with($this->isType('callable'))->will($this->returnCallback(function ($resolveCb) use($dents) {
         return $resolveCb($dents);
     }));
     $this->assertInstanceOf('React\\Promise\\PromiseInterface', (new RecursiveInvoker($node))->execute('chmod', [123]));
 }
예제 #5
0
 /**
  * @expectedException UnexpectedValueException
  */
 public function testCopyStreamingUnknownNode()
 {
     $filesystem = $this->getMock('React\\Filesystem\\Eio\\Adapter', [], [$this->getMock('React\\EventLoop\\StreamSelectLoop')]);
     (new File('foo.bar', Filesystem::createFromAdapter($filesystem)))->copyStreaming(new UnknownNodeType());
 }
예제 #6
0
 public function testCopyStreamingABC()
 {
     $adapter = $this->getMock('React\\Filesystem\\Eio\\Adapter', ['stat', 'mkdir'], [$this->getMock('React\\EventLoop\\StreamSelectLoop')]);
     $filesystem = Filesystem::createFromAdapter($adapter);
     $adapter->expects($this->at(0))->method('stat')->with('bar.foo/foo.bar/')->will($this->returnValue(new RejectedPromise()));
     $adapter->expects($this->at(1))->method('stat')->with('bar.foo/')->will($this->returnValue(new FulfilledPromise()));
     $adapter->expects($this->at(3))->method('stat')->with('bar.foo/foo.bar/')->will($this->returnValue(new FulfilledPromise()));
     $adapter->expects($this->any())->method('mkdir')->with($this->isType('string'))->will($this->returnValue(new FulfilledPromise()));
     $directoryFrom = $this->getMock('React\\Filesystem\\Node\\Directory', ['lsStreaming'], ['foo.bar', $filesystem]);
     $stream = new ObjectStream();
     $directoryTo = new Directory('bar.foo', $filesystem);
     $directoryFrom->expects($this->once())->method('lsStreaming')->with()->will($this->returnValue($stream));
     $returnedStream = $directoryFrom->copyStreaming($directoryTo);
     $this->assertInstanceOf('React\\Filesystem\\ObjectStream', $returnedStream);
     $file = $this->getMock('React\\Filesystem\\Node\\File', ['copyStreaming'], ['foo.bar', $filesystem]);
     $fileStream = new ObjectStream();
     $file->expects($this->once())->method('copyStreaming')->with($directoryTo)->will($this->returnValue($fileStream));
     $stream->emit('data', [$file]);
     $directory = $this->getMock('React\\Filesystem\\Node\\Directory', ['copyStreaming'], ['foo.bar', $filesystem]);
     $directoryStream = new ObjectStream();
     $directory->expects($this->once())->method('copyStreaming')->with($this->isInstanceOf('React\\Filesystem\\Node\\Directory'))->will($this->returnValue($directoryStream));
     $stream->emit('data', [$directory]);
     $directoryStream->end($directory);
     $stream->end();
 }
예제 #7
0
 /**
  * @dataProvider providerToString
  */
 public function test__toString($in, $out)
 {
     $nodeClass = $this->getNodeClass();
     $this->assertSame($out, (string) new $nodeClass($in, Filesystem::createFromAdapter($this->getMock('React\\Filesystem\\Eio\\Adapter', [], [$this->getMock('React\\EventLoop\\StreamSelectLoop')]))));
 }
<?php

/**
 * The package league/flysystem-webdav is required for this example
 */
use League\Flysystem\Filesystem as Flysystem;
use League\Flysystem\WebDAV\WebDAVAdapter;
use React\EventLoop\Factory;
use React\Filesystem\Filesystem;
use Sabre\DAV\Client;
use WyriHaximus\React\Filesystem\Flysystem\FlysystemAdapter;
require dirname(__DIR__) . '/vendor/autoload.php';
$loop = Factory::create();
$loop->futureTick(function () use($loop) {
    $adapter = new WebDAVAdapter(new Client(['baseUri' => 'https://YOURSTACK.stackstorage.com/remote.php/webdav', 'userName' => 'USERNAME', 'password' => 'PASSWORD']));
    $adapter->setPathPrefix('/remote.php/webdav');
    $flysystem = new Flysystem($adapter);
    $filesystem = Filesystem::createFromAdapter(new FlysystemAdapter($loop, [], $flysystem));
    $filesystem->dir('')->ls()->then(function ($nodes) {
        foreach ($nodes as $node) {
            echo $node->getPath(), PHP_EOL;
        }
    }, function ($e) {
        var_export($e);
    });
});
$loop->run();