Exemple #1
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();
 }