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

testStoringData() public method

public testStoringData ( )
    public function testStoringData()
    {
        $collection = $this->getGridFS();
        $id = $collection->storeBytes('abcd', ['foo' => 'bar', 'chunkSize' => 2]);
        $newCollection = $this->getCheckDatabase()->selectCollection('fs.files');
        $newChunksCollection = $this->getCheckDatabase()->selectCollection('fs.chunks');
        $this->assertSame(1, $newCollection->count());
        $this->assertSame(2, $newChunksCollection->count());
        $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(4, 'length', $record);
        $this->assertObjectHasAttribute('chunkSize', $record);
        $this->assertAttributeSame(2, 'chunkSize', $record);
        $this->assertObjectHasAttribute('md5', $record);
        $this->assertAttributeSame('e2fc714c4727ee9395f324cd2e7f331f', 'md5', $record);
        $chunksCursor = $newChunksCollection->find([], ['sort' => ['n' => 1]]);
        $chunks = iterator_to_array($chunksCursor);
        $firstChunk = $chunks[0];
        $this->assertNotNull($firstChunk);
        $this->assertAttributeInstanceOf('MongoDB\\BSON\\ObjectID', 'files_id', $firstChunk);
        $this->assertSame((string) $id, (string) $firstChunk->files_id);
        $this->assertAttributeSame(0, 'n', $firstChunk);
        $this->assertAttributeInstanceOf('MongoDB\\BSON\\Binary', 'data', $firstChunk);
        $this->assertSame('ab', (string) $firstChunk->data->getData());
        $secondChunck = $chunks[1];
        $this->assertNotNull($secondChunck);
        $this->assertAttributeInstanceOf('MongoDB\\BSON\\ObjectID', 'files_id', $secondChunck);
        $this->assertSame((string) $id, (string) $secondChunck->files_id);
        $this->assertAttributeSame(1, 'n', $secondChunck);
        $this->assertAttributeInstanceOf('MongoDB\\BSON\\Binary', 'data', $secondChunck);
        $this->assertSame('cd', (string) $secondChunck->data->getData());
    }