mirror of
https://github.com/danog/file.git
synced 2024-11-30 04:19:39 +01:00
9e7c1c1488
Signficantly refactored EioHandle and UvHandle.
82 lines
2.1 KiB
PHP
82 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Amp\File\Test;
|
|
|
|
use Amp\File;
|
|
use Amp\PHPUnit\TestCase;
|
|
|
|
abstract class AsyncHandleTest extends HandleTest {
|
|
/**
|
|
* @expectedException \Amp\File\PendingOperationError
|
|
*/
|
|
public function testSimultaneousReads() {
|
|
$this->execute(function () {
|
|
/** @var \Amp\File\Handle $handle */
|
|
$handle = yield File\open(__FILE__, "r");
|
|
|
|
$promise1 = $handle->read();
|
|
$promise2 = $handle->read();
|
|
|
|
$expected = \substr(yield File\get(__FILE__), 0, 20);
|
|
$this->assertSame($expected, yield $promise1);
|
|
|
|
yield $promise2;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Amp\File\PendingOperationError
|
|
*/
|
|
public function testSeekWhileReading() {
|
|
$this->execute(function () {
|
|
/** @var \Amp\File\Handle $handle */
|
|
$handle = yield File\open(__FILE__, "r");
|
|
|
|
$promise1 = $handle->read(10);
|
|
$promise2 = $handle->seek(0);
|
|
|
|
$expected = \substr(yield File\get(__FILE__), 0, 10);
|
|
$this->assertSame($expected, yield $promise1);
|
|
|
|
yield $promise2;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Amp\File\PendingOperationError
|
|
*/
|
|
public function testReadWhileWriting() {
|
|
$this->execute(function () {
|
|
/** @var \Amp\File\Handle $handle */
|
|
$handle = yield File\open(__FILE__, "r");
|
|
|
|
$data = "test";
|
|
|
|
$promise1 = $handle->write($data);
|
|
$promise2 = $handle->read(10);
|
|
|
|
$this->assertSame(\strlen($data), yield $promise1);
|
|
|
|
yield $promise2;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Amp\File\PendingOperationError
|
|
*/
|
|
public function testWriteWhileReading() {
|
|
$this->execute(function () {
|
|
/** @var \Amp\File\Handle $handle */
|
|
$handle = yield File\open(__FILE__, "r");
|
|
|
|
$promise1 = $handle->read(10);
|
|
$promise2 = $handle->write("test");
|
|
|
|
$expected = \substr(yield File\get(__FILE__), 0, 10);
|
|
$this->assertSame($expected, yield $promise1);
|
|
|
|
yield $promise2;
|
|
});
|
|
}
|
|
}
|