1
0
mirror of https://github.com/danog/file.git synced 2024-11-30 04:19:39 +01:00
file/test/UvHandleTest.php

46 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2015-08-13 01:02:41 +02:00
namespace Amp\File\Test;
use Amp\Loop;
2015-08-13 01:02:41 +02:00
use Amp\File as file;
class UvHandleTest extends HandleTest {
2016-07-21 01:33:03 +02:00
protected function lRun(callable $cb) {
2015-08-13 01:02:41 +02:00
if (\extension_loaded("uv")) {
$loop = new Loop\UvDriver;
Loop::set($loop);
Loop::run(function() use ($cb, $loop) {
2016-07-21 01:33:03 +02:00
\Amp\File\filesystem(new \Amp\File\UvDriver($loop));
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
});
2015-08-13 01:02:41 +02:00
} else {
$this->markTestSkipped(
"php-uv extension not loaded"
);
}
}
public function testQueuedWritesOverrideEachOtherIfNotWaitedUpon() {
2016-07-21 01:33:03 +02:00
$this->lRun(function () {
2015-08-13 01:02:41 +02:00
$path = Fixture::path() . "/write";
$handle = (yield file\open($path, "c+"));
$this->assertSame(0, $handle->tell());
$write1 = $handle->write("foo");
$write2 = $handle->write("bar");
yield \Amp\Promise\all([$write1, $write2]);
2015-08-13 01:02:41 +02:00
$handle->seek(0);
$contents = (yield $handle->read(8192));
$this->assertSame(3, $handle->tell());
$this->assertTrue($handle->eof());
$this->assertSame("bar", $contents);
yield $handle->close();
yield file\unlink($path);
});
}
}