Ejemplo n.º 1
0
 public function testGetProperty()
 {
     // $bob->email
     $this->assertEquals('*****@*****.**', $this->_bob->getProperty('email'));
     // $bob->name->first
     $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT, $this->_bob->getProperty('name'));
     $this->assertEquals('My_ShantyMongo_Name', get_class($this->_bob->getProperty('name')));
     $this->assertEquals('Bob', $this->_bob->getProperty('name')->getProperty('first'));
     $this->assertTrue($this->_bob->getProperty('name')->isConnected());
     $this->assertEquals('default', $this->_bob->getProperty('name')->getConfigAttribute('connectionGroup'));
     $this->assertEquals(TESTS_SHANTY_MONGO_DB, $this->_bob->getProperty('name')->getConfigAttribute('db'));
     $this->assertEquals('user', $this->_bob->getProperty('name')->getConfigAttribute('collection'));
     $this->assertEquals('name', $this->_bob->getProperty('name')->getPathToDocument());
     $this->assertFalse($this->_bob->getProperty('name')->getConfigAttribute('hasId'));
     $this->assertFalse($this->_bob->getProperty('name')->isNewDocument());
     // $bob->partner->name->first
     $cherry = $this->_bob->getProperty('partner');
     $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT, $cherry);
     $this->assertEquals('My_ShantyMongo_User', get_class($cherry));
     $this->assertEquals('Cherry', $cherry->getProperty('name')->getProperty('first'));
     $this->assertTrue($cherry->isRootDocument());
     $this->assertEquals('default', $cherry->getProperty('name')->getConfigAttribute('connectionGroup'));
     $this->assertEquals(TESTS_SHANTY_MONGO_DB, $cherry->getProperty('name')->getConfigAttribute('db'));
     $this->assertEquals('user', $cherry->getProperty('name')->getConfigAttribute('collection'));
     // $bob->addresses[1]->street
     $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT, $this->_bob->getProperty('addresses'));
     $this->assertEquals('Shanty_Mongo_DocumentSet', get_class($this->_bob->getProperty('addresses')));
     $this->assertEquals('addresses', $this->_bob->getProperty('addresses')->getPathToDocument());
     $this->assertEquals(2, count($this->_bob->getProperty('addresses')));
     $this->assertEquals('742 Evergreen Terrace', $this->_bob->getProperty('addresses')->getProperty(1)->getProperty('street'));
     $this->assertEquals('default', $this->_bob->getProperty('addresses')->getConfigAttribute('connectionGroup'));
     $this->assertEquals(TESTS_SHANTY_MONGO_DB, $this->_bob->getProperty('addresses')->getConfigAttribute('db'));
     $this->assertEquals('user', $this->_bob->getProperty('addresses')->getConfigAttribute('collection'));
     // Test get on new documents
     $sarah = new My_ShantyMongo_User();
     // $sarah->email
     $this->assertNull($sarah->getProperty('email'));
     // $sarah->name
     $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT, $sarah->getProperty('name'));
     $this->assertEquals('My_ShantyMongo_Name', get_class($sarah->getProperty('name')));
     // $sarah->addresses
     $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT, $sarah->getProperty('addresses'));
     $this->assertEquals('Shanty_Mongo_DocumentSet', get_class($sarah->getProperty('addresses')));
     $this->assertEquals(0, count($sarah->getProperty('addresses')));
     // Test Array's
     $this->assertTrue(is_array($this->_articleRegular->tags));
     $this->assertEquals(array('awesome', 'howto', 'mongodb'), $this->_articleRegular->tags);
     // Test broken references
     $this->assertNull($this->_articleBroken->author);
 }