예제 #1
0
 /**
  * Test Document preparation and conversion.
  */
 public function testPrepareDocument()
 {
     $some_data = DataProvider::getStandardData();
     $document = DocumentFactory::init($this->config)->prepareDocument($some_data);
     $this->assertEquals('Vultan\\Document\\Document', get_class($document));
     $this->assertEquals('Mercedes-Benz', $document->get('marque'));
 }
예제 #2
0
 public function testProperties()
 {
     $document = Document::create($this->config);
     // Test default property creation.
     $document->setDefaultProperties();
     $values = $document->getProperties();
     // Default properties are currently just updated and created timestamps.
     $this->assertArrayHasKey('time_created', $values);
     $this->assertArrayHasKey('time_updated', $values);
     // Test adding more properties.
     $some_values = DataProvider::getStandardData();
     $document->setProperties($some_values);
     $values = $document->getProperties();
     // Check our existing defaults are still there.
     $this->assertArrayHasKey('time_created', $values);
     $this->assertArrayHasKey('time_updated', $values);
     // The document should now have default test data set.
     $this->assertArrayHasKey('marque', $values);
     // As well as a collection.
     $this->assertEquals('cars', $document->getCollection());
     // And ID should only exist if we've added one (or a save operation has).
     $test_id = new \MongoId();
     $document->setIdentifier($test_id);
     $values = $document->getProperties();
     // Check the ID is set, and that is internally consistent.
     $this->assertArrayHasKey('_id', $values);
     $this->assertEquals($values['_id'], $document->getId());
 }