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();
     }
 }
 protected function handleFile(File $file, Response $response)
 {
     if (isset($this->filesContents[$file->getPath()])) {
         return $this->filesContents[$file->getPath()];
     }
     $file->getContents()->then(function ($contents) use($file) {
         $this->filesContents[$file->getPath()] = $contents;
         return $file->close()->then(function () use($contents) {
             return $contents;
         });
     })->then(function ($fileContents) use($response) {
         $response->writeHead(200);
         $response->end($fileContents);
     });
 }
Exemple #3
0
 public function testClose()
 {
     $path = 'foo.bar';
     $fd = '0123456789abcdef';
     $filesystem = $this->getMock('React\\Filesystem\\Eio\\Adapter', ['close', 'open'], [$this->getMock('React\\EventLoop\\StreamSelectLoop')]);
     $stream = $this->getMock('React\\Filesystem\\Stream\\GenericStreamInterface', ['getFiledescriptor'], ['foo:bar']);
     $stream->expects($this->once())->method('getFiledescriptor')->with()->will($this->returnValue($fd));
     $openPromise = $this->getMock('React\\Promise\\PromiseInterface', ['then']);
     $openPromise->expects($this->once())->method('then')->with($this->isType('callable'))->will($this->returnCallback(function ($resolveCb) use($stream) {
         return new FulfilledPromise($resolveCb($stream));
     }));
     $filesystem->expects($this->once())->method('open')->with($path, 'r')->will($this->returnValue($openPromise));
     $closePromise = $this->getMock('React\\Promise\\PromiseInterface', ['then']);
     $closePromise->expects($this->once())->method('then')->with($this->isType('callable'))->will($this->returnCallback(function ($resolveCb) use($stream) {
         return \React\Promise\resolve($resolveCb($stream));
     }));
     $filesystem->expects($this->once())->method('close')->with($fd)->will($this->returnValue($closePromise));
     $file = new File($path, Filesystem::createFromAdapter($filesystem));
     $file->open('r');
     $file->close();
 }