Alcaeus\MongoDbAdapter\Tests\Mongo\MongoGridFSTest::testStoreUpload PHP Method

testStoreUpload() public method

public testStoreUpload ( )
    public function testStoreUpload()
    {
        $this->skipTestIf(extension_loaded('mongo'));
        $collection = $this->getGridFS();
        $_FILES['foo'] = ['name' => 'test.php', 'error' => UPLOAD_ERR_OK, 'tmp_name' => __FILE__];
        $id = $collection->storeUpload('foo', ['chunkSize' => 100, 'foo' => 'bar']);
        $newCollection = $this->getCheckDatabase()->selectCollection('fs.files');
        $newChunksCollection = $this->getCheckDatabase()->selectCollection('fs.chunks');
        $this->assertSame(1, $newCollection->count());
        $md5 = md5_file(__FILE__);
        $size = filesize(__FILE__);
        $record = $newCollection->findOne();
        $this->assertNotNull($record);
        $this->assertAttributeInstanceOf('MongoDB\\BSON\\ObjectID', '_id', $record);
        $this->assertSame((string) $id, (string) $record->_id);
        $this->assertObjectHasAttribute('foo', $record);
        $this->assertAttributeSame('bar', 'foo', $record);
        $this->assertObjectHasAttribute('length', $record);
        $this->assertAttributeSame($size, 'length', $record);
        $this->assertObjectHasAttribute('chunkSize', $record);
        $this->assertAttributeSame(100, 'chunkSize', $record);
        $this->assertObjectHasAttribute('md5', $record);
        $this->assertAttributeSame($md5, 'md5', $record);
        $this->assertObjectHasAttribute('filename', $record);
        $this->assertAttributeSame('test.php', 'filename', $record);
        $numberOfChunks = (int) ceil($size / 100);
        $this->assertSame($numberOfChunks, $newChunksCollection->count());
    }