Ejemplo n.º 1
0
 /**
  * Testing creating & saving new object & instance pool.
  */
 public function testObjectInstances_New()
 {
     $emp = new BookstoreEmployee();
     $emp->setName(md5(microtime()));
     $emp->save();
     $id = $emp->getId();
     $retrieved = BookstoreEmployeePeer::retrieveByPK($id);
     $this->assertSame($emp, $retrieved, "Expected same object (from instance pool)");
 }
Ejemplo n.º 2
0
 public function testObjectInstances()
 {
     $sample = BookPeer::doSelectOne(new Criteria());
     $samplePk = $sample->getPrimaryKey();
     // 1) make sure consecutive calls to retrieveByPK() return the same object.
     $b1 = BookPeer::retrieveByPK($samplePk);
     $b2 = BookPeer::retrieveByPK($samplePk);
     $sampleval = md5(microtime());
     $this->assertTrue($b1 === $b2, "Expected object instances to match for calls with same retrieveByPK() method signature.");
     // 2) make sure that calls to doSelect also return references to the same objects.
     $allbooks = BookPeer::doSelect(new Criteria());
     foreach ($allbooks as $testb) {
         if ($testb->getPrimaryKey() == $b1->getPrimaryKey()) {
             $this->assertTrue($testb === $b1, "Expected same object instance from doSelect() as from retrieveByPK()");
         }
     }
     // 3) test fetching related objects
     $book = BookPeer::retrieveByPK($samplePk);
     $bookauthor = $book->getAuthor();
     $author = AuthorPeer::retrieveByPK($bookauthor->getId());
     $this->assertTrue($bookauthor === $author, "Expected same object instance when calling fk object accessor as retrieveByPK()");
     // 4) test a doSelectJoin()
     $morebooks = BookPeer::doSelectJoinAuthor(new Criteria());
     for ($i = 0, $j = 0; $j < count($morebooks); $i++, $j++) {
         $testb1 = $allbooks[$i];
         $testb2 = $allbooks[$j];
         $this->assertTrue($testb1 === $testb2, "Expected the same objects from consecutive doSelect() calls.");
         // we could probably also test this by just verifying that $book & $testb are the same
         if ($testb1->getPrimaryKey() === $book) {
             $this->assertTrue($book->getAuthor() === $testb1->getAuthor(), "Expected same author object in calls to pkey-matching books.");
         }
     }
     // 5) test creating a new object, saving it, and then retrieving that object (should all be same instance)
     $b = new BookstoreEmployee();
     $b->setName("Testing");
     $b->setJobTitle("Testing");
     $b->save();
     $empId = $b->getId();
     $this->assertSame($b, BookstoreEmployeePeer::retrieveByPK($empId), "Expected newly saved object to be same instance as pooled.");
 }