Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace React\Filesystem;

use React\Filesystem\ObjectStream;
use React\EventLoop\LoopInterface;
use React\Promise\PromiseInterface;

Expand Down Expand Up @@ -111,6 +112,14 @@ public function stat($filename);
*/
public function ls($path);

/**
* List contents of the given path.
*
* @param string $path
* @return ObjectStream
*/
public function lsStream($path);

/**
* Touch the given path, either creating a file, or updating mtime on the file.
*
Expand Down
10 changes: 10 additions & 0 deletions src/ChildProcess/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Exception;
use React\EventLoop\LoopInterface;
use React\Filesystem\ObjectStream;
use React\Filesystem\ObjectStreamSink;
use React\Filesystem\AdapterInterface;
use React\Filesystem\CallInvokerInterface;
use React\Filesystem\FilesystemInterface;
Expand Down Expand Up @@ -322,6 +323,15 @@ public function stat($filename)
* @return PromiseInterface
*/
public function ls($path)
{
return ObjectStreamSink::promise($this->lsStream($path));
}

/**
* @param string $path
* @return ObjectStream
*/
public function lsStream($path)
{
$stream = new ObjectStream();

Expand Down
13 changes: 12 additions & 1 deletion src/Eio/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use React\Filesystem\ModeTypeDetector;
use React\Filesystem\Node\NodeInterface;
use React\Filesystem\ObjectStream;
use React\Filesystem\ObjectStreamSink;
use React\Filesystem\OpenFileLimiter;
use React\Filesystem\PermissionFlagResolver;
use React\Filesystem\TypeDetectorInterface;
use React\Promise\Deferred;
use React\Promise\PromiseInterface;

class Adapter implements AdapterInterface
{
Expand Down Expand Up @@ -191,9 +193,18 @@ public function chown($path, $uid, $gid)
}

/**
* {@inheritDoc}
* @param string $path
* @return PromiseInterface
*/
public function ls($path)
{
return ObjectStreamSink::promise($this->lsStream($path));
}

/**
* {@inheritDoc}
*/
public function lsStream($path)
{
$stream = new ObjectStream();

Expand Down
4 changes: 2 additions & 2 deletions src/Node/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ public function __construct($path, FilesystemInterface $filesystem, RecursiveInv
*/
public function ls()
{
return ObjectStreamSink::promise($this->lsStreaming());
return $this->adapter->ls($this->path);
}

/**
* {@inheritDoc}
*/
public function lsStreaming()
{
return $this->adapter->ls($this->path);
return $this->adapter->lsStream($this->path);
}

/**
Expand Down
49 changes: 48 additions & 1 deletion tests/ChildProcess/AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use React\EventLoop\Factory;
use React\Filesystem\ChildProcess\Adapter;
use React\Filesystem\Filesystem;
use React\Filesystem\Node\File;
use React\Filesystem\Node\NodeInterface;
use React\Promise\Deferred;
use React\Promise\FulfilledPromise;
Expand Down Expand Up @@ -278,6 +279,52 @@ public function testSymlink()
}

public function testLs()
{
$loop = \React\EventLoop\Factory::create();
$adapter = new Adapter($loop, [
'pool' => [
'class' => 'WyriHaximus\React\ChildProcess\Pool\Pool\Dummy',
],
]);
$invoker = $this->getMock('React\Filesystem\CallInvokerInterface', [
'__construct',
'invokeCall',
'isEmpty',
]);
$adapter->setInvoker($invoker);
$fs = Filesystem::createFromAdapter($adapter);

$deferred = new Deferred();

$invoker
->expects($this->once())
->method('invokeCall')
->with(
'readdir',
[
'path' => 'foo.bar',
'flags' => 2,
]
)->will($this->returnValue($deferred->promise()))
;

$promise = $adapter->ls('foo.bar');
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);

$deferred->resolve([
[
'type' => 'file',
'name' => 'bar.foo',
],
]);

$nodes = $this->await($promise, $loop);
$nodes->rewind();

$this->assertEquals(new File('foo.bar/bar.foo', $fs), $nodes->current());
}

public function testLsStream()
{
$loop = $this->getMock('React\EventLoop\LoopInterface');
$adapter = new Adapter($loop, [
Expand Down Expand Up @@ -307,7 +354,7 @@ public function testLs()
)->will($this->returnValue($deferred->promise()))
;

$stream = $adapter->ls('foo.bar');
$stream = $adapter->lsStream('foo.bar');
$this->assertInstanceOf('React\Filesystem\ObjectStream', $stream);

$calledOnData = false;
Expand Down
25 changes: 23 additions & 2 deletions tests/Node/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,41 @@ public function testLs()

$filesystem = $this->mockAdapter($loop);

$lsStream = $this->getMock('React\Filesystem\ObjectStream');
$ls = \React\Promise\resolve();

$filesystem
->expects($this->once())
->method('ls')
->with()
->will($this->returnValue($lsStream))
->will($this->returnValue($ls))
;

$directory = new Directory($path, Filesystem::createFromAdapter($filesystem));

$this->assertInstanceOf('React\Promise\PromiseInterface', $directory->ls());
}

public function testLsStream()
{
$path = '/home/foo/bar';
$loop = $this->getMock('React\EventLoop\LoopInterface');

$filesystem = $this->mockAdapter($loop);

$lsStream = $this->getMock('React\Filesystem\ObjectStream');

$filesystem
->expects($this->once())
->method('lsStream')
->with()
->will($this->returnValue($lsStream))
;

$directory = new Directory($path, Filesystem::createFromAdapter($filesystem));

$this->assertInstanceOf('React\Filesystem\ObjectStream', $directory->lsStreaming());
}

public function testCreate()
{
$path = 'foo.bar';
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected function mockAdapter(LoopInterface $loop = null)
'chown',
'stat',
'ls',
'lsStream',
'touch',
'open',
'read',
Expand Down
2 changes: 1 addition & 1 deletion tests/UnknownNodeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace React\Tests\Filesystem;

use React\Filesystem\Node\NodeInterface;
use React\Filesystem\Node\ObjectStream;
use React\Filesystem\ObjectStream;

class UnknownNodeType implements NodeInterface
{
Expand Down