Inheritance: extends My_ShantyMongo_Abstract
Exemplo n.º 1
0
 /**
  * @depends testEnsureIndex
  */
 public function testDeleteIndexes()
 {
     My_ShantyMongo_User::ensureIndex(array('name.first' => 1), array('safe' => true));
     My_ShantyMongo_User::deleteIndexes();
     $indexInfo = array(array('name' => '_id_', 'ns' => 'shanty-mongo-testing.user', 'key' => array('_id' => 1), 'v' => 1));
     $this->assertEquals($indexInfo, My_ShantyMongo_User::getIndexInfo());
 }
Exemplo n.º 2
0
 public function testPrePostInsertUpdateSaveHook()
 {
     $user = new My_ShantyMongo_User();
     $user->name->first = 'Stranger';
     $user->name->last = 'Jill';
     $user->email = '*****@*****.**';
     $user->sex = 'M';
     $user->save();
     $user->email = '*****@*****.**';
     $user->save();
     $this->assertEquals(1, $user->_hookCounter['preInsert']);
     $this->assertEquals(1, $user->_hookCounter['postInsert']);
     $this->assertEquals(1, $user->_hookCounter['preUpdate']);
     $this->assertEquals(1, $user->_hookCounter['postUpdate']);
     $this->assertEquals(2, $user->_hookCounter['preSave']);
     $this->assertEquals(2, $user->_hookCounter['postSave']);
 }
Exemplo n.º 3
0
 public function testGetPropertyNewDocument()
 {
     $address = $this->_bob->addresses->new();
     $address->street = '45 Burrow St';
     $address->suburb = 'The Shire';
     $address->state = 'Middle Earth';
     $address->postcode = '21342';
     $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT, $address);
     $this->assertEquals('Shanty_Mongo_Document', get_class($address));
     $this->assertTrue($address->isNewDocument());
     $this->assertFalse($address->hasId());
     $this->assertTrue($address->getConfigAttribute('parentIsDocumentSet'));
     $this->assertEquals('default', $address->getConfigAttribute('connectionGroup'));
     $this->assertEquals(TESTS_SHANTY_MONGO_DB, $address->getConfigAttribute('db'));
     $this->assertEquals('user', $address->getConfigAttribute('collection'));
     $this->assertEquals('addresses', $address->getPathToDocument());
     $criteria = $address->getCriteria();
     $this->assertTrue(isset($criteria['_id']));
     $this->assertEquals('4c04516a1f5f5e21361e3ab0', $criteria['_id']->__toString());
     $address->save();
     $bob = My_ShantyMongo_User::find('4c04516a1f5f5e21361e3ab0');
     $this->assertEquals(3, count($bob->addresses));
     $this->assertEquals('45 Burrow St', $bob->addresses[2]->street);
 }
Exemplo n.º 4
0
 public function setUp()
 {
     parent::setUp();
     $this->_document = My_ShantyMongo_User::find('4c04516a1f5f5e21361e3ab0');
     $this->_iterator = $this->_document->getIterator();
 }
Exemplo n.º 5
0
 /**
  * This is to test a really obscure issue where DBRefs get save with null fields.
  **/
 public function testCleanDbRef()
 {
     $user = new My_ShantyMongo_User();
     $user->name = new My_ShantyMongo_Name(array('first' => 'Tom', 'last' => 'Holder'));
     $user->email = '*****@*****.**';
     $user->sex = 'M';
     $user->save();
     $var = $user->name->first;
     $article = new My_ShantyMongo_Article();
     $article->title = 'DBRefs should be clean';
     $article->author = $user;
     $article->save();
     $article = My_ShantyMongo_Article::find($article->getId());
     $exportedArticle = $article->export();
     //This key shouldn't be left behind on field which should be a DBRef.
     $this->assertArrayNotHasKey('name', $exportedArticle['author']);
 }