Commit 5310c62b authored by Katherine Walker's avatar Katherine Walker

PHPLIB-306: Set GridFS uploadDate at completion time

parent d3a3c4e8
......@@ -101,7 +101,6 @@ class WritableStream
'_id' => $options['_id'],
'chunkSize' => $this->chunkSize,
'filename' => (string) $filename,
'uploadDate' => new UTCDateTime,
] + array_intersect_key($options, ['aliases' => 1, 'contentType' => 1, 'metadata' => 1]);
}
......@@ -223,6 +222,7 @@ class WritableStream
$this->file['length'] = $this->length;
$this->file['md5'] = $md5;
$this->file['uploadDate'] = new UTCDateTime;
try {
$this->collectionWrapper->insertFile($this->file);
......
......@@ -3,6 +3,7 @@
namespace MongoDB\Tests\GridFS;
use MongoDB\BSON\Binary;
use MongoDB\BSON\ObjectId;
use MongoDB\BSON\UTCDateTime;
/**
......@@ -147,9 +148,8 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase
$this->assertSame(-1, fseek($stream, 1, \SEEK_END));
}
public function testWritableStreamStat()
public function testWritableStreamStatBeforeSaving()
{
$currentTimestamp = time();
$stream = $this->bucket->openUploadStream('filename', ['chunkSizeBytes' => 1024]);
$stat = fstat($stream);
......@@ -157,10 +157,10 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase
$this->assertSame(0100222, $stat['mode']);
$this->assertSame(0, $stat[7]);
$this->assertSame(0, $stat['size']);
$this->assertGreaterThanOrEqual($currentTimestamp, $stat[9]);
$this->assertGreaterThanOrEqual($currentTimestamp, $stat['mtime']);
$this->assertGreaterThanOrEqual($currentTimestamp, $stat[10]);
$this->assertGreaterThanOrEqual($currentTimestamp, $stat['ctime']);
$this->assertGreaterThanOrEqual(0, $stat[9]);
$this->assertGreaterThanOrEqual(0, $stat['mtime']);
$this->assertGreaterThanOrEqual(0, $stat[10]);
$this->assertGreaterThanOrEqual(0, $stat['ctime']);
$this->assertSame(1024, $stat[11]);
$this->assertSame(1024, $stat['blksize']);
......@@ -169,6 +169,29 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase
$stat = fstat($stream);
$this->assertSame(6, $stat[7]);
$this->assertSame(6, $stat['size']);
}
public function testWritableStreamStatAfterSaving()
{
$id = new ObjectId;
$stream = $this->bucket->openUploadStream('filename', ['chunkSizeBytes' => 1024, '_id' => $id]);
$this->assertSame(6, fwrite($stream, 'foobar'));
$this->assertTrue(fclose($stream));
$currentTimestamp = time();
$stream = $this->bucket->openDownloadStream($id);
$stat = fstat($stream);
$this->assertSame(0100444, $stat[2]);
$this->assertSame(0100444, $stat['mode']);
$this->assertSame(6, $stat[7]);
$this->assertSame(6, $stat['size']);
$this->assertGreaterThanOrEqual($currentTimestamp, $stat[9]);
$this->assertGreaterThanOrEqual($currentTimestamp, $stat['mtime']);
$this->assertGreaterThanOrEqual($currentTimestamp, $stat[10]);
$this->assertGreaterThanOrEqual($currentTimestamp, $stat['ctime']);
$this->assertSame(1024, $stat[11]);
$this->assertSame(1024, $stat['blksize']);
}
public function testWritableStreamWrite()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment