Skip to content

Commit

Permalink
fix tests, replace retreiveByPk* with findPk*
Browse files Browse the repository at this point in the history
  • Loading branch information
jaugustin committed Jan 27, 2013
1 parent 6497478 commit 00442b4
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 62 deletions.
12 changes: 6 additions & 6 deletions tests/Propel/Tests/BookstoreTest.php
Expand Up @@ -207,7 +207,7 @@ public function testScenario()

// Updating just-created book title
// First finding book by PK (=$qs_id) ....
$qs_lookup = BookPeer::retrieveByPk($qs_id);
$qs_lookup = BookQuery::create()->findPk($qs_id);
$this->assertNotNull($qs_lookup, 'just-created book can be found by pk');

$new_title = "Quicksilver (".crc32(uniqid(rand())).")";
Expand All @@ -216,7 +216,7 @@ public function testScenario()
$qs_lookup->save();

// Making sure object was correctly updated: ";
$qs_lookup2 = BookPeer::retrieveByPk($qs_id);
$qs_lookup2 = BookQuery::create()->findPk($qs_id);
$this->assertEquals($new_title, $qs_lookup2->getTitle());

// Test some basic DATE / TIME stuff
Expand All @@ -231,7 +231,7 @@ public function testScenario()
$r->setReviewDate($control);
$r->save();

$r2 = ReviewPeer::retrieveByPk($r_id);
$r2 = ReviewQuery::create()->findPk($r_id);

$this->assertEquals(new DateTime('2004-02-29 00:00:00'), $r2->getReviewDate(null), 'ability to fetch DateTime');
$this->assertEquals($control, $r2->getReviewDate('U'), 'ability to fetch native unix timestamp');
Expand All @@ -251,7 +251,7 @@ public function testScenario()
$m1->save();
$m1_id = $m1->getId();

$m1_lookup = MediaPeer::retrieveByPk($m1_id);
$m1_lookup = MediaQuery::create()->findPk($m1_id);

$this->assertNotNull($m1_lookup, 'Can find just-created media item');
$this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($m1_lookup->getCoverImage())), 'BLOB was correctly updated');
Expand All @@ -261,7 +261,7 @@ public function testScenario()
$m1_lookup->setCoverImage(file_get_contents($blob2_path));
$m1_lookup->save();

$m2_lookup = MediaPeer::retrieveByPk($m1_id);
$m2_lookup = MediaQuery::create()->findPk($m1_id);
$this->assertNotNull($m2_lookup, 'Can find just-created media item');

$this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2_lookup->getCoverImage())), 'BLOB was correctly overwritten');
Expand Down Expand Up @@ -343,7 +343,7 @@ public function testScenario()

// Removing books that were just created
// First finding book by PK (=$phoenix_id) ....
$hp = BookPeer::retrieveByPk($phoenix_id);
$hp = BookQuery::create()->findPk($phoenix_id);
$this->assertNotNull($hp, 'Could find just-created book');

// Attempting to delete [multi-table] by found pk
Expand Down
Expand Up @@ -16,6 +16,7 @@
use Propel\Tests\Bookstore\BookPeer;
use Propel\Tests\Bookstore\Media;
use Propel\Tests\Bookstore\MediaPeer;
use Propel\Tests\Bookstore\MediaQuery;

use Propel\Runtime\ActiveQuery\Criteria;

Expand Down Expand Up @@ -272,7 +273,7 @@ public function testLobSetting_WriteMode()
MediaPeer::clearInstancePool();

// make sure we have the latest from the db:
$m2 = MediaPeer::retrieveByPK($m1->getId());
$m2 = MediaQuery::create()->findPk($m1->getId());

// now attempt to assign a temporary stream, opened in 'w' mode, to the db

Expand Down
40 changes: 23 additions & 17 deletions tests/Propel/Tests/Generator/Builder/Om/GeneratedObjectTest.php
Expand Up @@ -17,6 +17,7 @@
use Propel\Runtime\Map\TableMap;
use Propel\Tests\Bookstore\AcctAuditLog;
use Propel\Tests\Bookstore\AcctAuditLogPeer;
use Propel\Tests\Bookstore\AcctAuditLogQuery;
use Propel\Tests\Bookstore\Author;
use Propel\Tests\Bookstore\AuthorQuery;
use Propel\Tests\Bookstore\Map\AuthorTableMap;
Expand All @@ -26,27 +27,32 @@
use Propel\Tests\Bookstore\Map\BookTableMap;
use Propel\Tests\Bookstore\BookReader;
use Propel\Tests\Bookstore\BookOpinion;
use Propel\Tests\Bookstore\BookOpinionQuery;
use Propel\Tests\Bookstore\BookOpinionPeer;
use Propel\Tests\Bookstore\Bookstore;
use Propel\Tests\Bookstore\BookstorePeer;
use Propel\Tests\Bookstore\BookstoreContest;
use Propel\Tests\Bookstore\BookstoreEmployee;
use Propel\Tests\Bookstore\BookstoreEmployeePeer;
use Propel\Tests\Bookstore\BookstoreEmployeeQuery;
use Propel\Tests\Bookstore\Map\BookstoreEmployeeTableMap;
use Propel\Tests\Bookstore\BookstoreEmployeeAccount;
use Propel\Tests\Bookstore\BookstoreEmployeeAccountPeer;
use Propel\Tests\Bookstore\BookstoreEmployeeAccountQuery;
use Propel\Tests\Bookstore\Map\BookstoreEmployeeAccountTableMap;
use Propel\Tests\Bookstore\BookstoreContestEntry;
use Propel\Tests\Bookstore\BookstoreSale;
use Propel\Tests\Bookstore\Contest;
use Propel\Tests\Bookstore\ContestView;
use Propel\Tests\Bookstore\Customer;
use Propel\Tests\Bookstore\CustomerPeer;
use Propel\Tests\Bookstore\CustomerQuery;
use Propel\Tests\Bookstore\Publisher;
use Propel\Tests\Bookstore\PublisherPeer;
use Propel\Tests\Bookstore\PublisherQuery;
use Propel\Tests\Bookstore\Review;
use Propel\Tests\Bookstore\ReviewPeer;
use Propel\Tests\Bookstore\Map\ReviewTableMap;
use Propel\Tests\Bookstore\BookstoreEmployee;
use Propel\Tests\Bookstore\BookstoreEmployeePeer;
use Propel\Tests\Bookstore\Map\BookstoreEmployeeTableMap;
use Propel\Tests\Bookstore\BookstoreEmployeeAccount;
use Propel\Tests\Bookstore\BookstoreEmployeeAccountPeer;
use Propel\Tests\Bookstore\Map\BookstoreEmployeeAccountTableMap;
use Propel\Tests\Bookstore\BookstoreContestEntry;
use Propel\Tests\Bookstore\BookstoreSale;
use Propel\Tests\Helpers\Bookstore\BookstoreTestBase;
use Propel\Tests\Helpers\Bookstore\Behavior\TestAuthor;
use Propel\Tests\Helpers\Bookstore\Behavior\TestAuthorDeleteFalse;
Expand Down Expand Up @@ -108,7 +114,7 @@ public function testDefaultValueSetTwice()

PublisherPeer::clearInstancePool();

$pub2 = PublisherPeer::retrieveByPK($pubId);
$pub2 = PublisherQuery::create()->findPk($pubId);
$pub2->setName('Penguin');
$this->assertFalse($pub2->isModified(), "Expect Publisher to be not modified after setting default value second time.");
}
Expand Down Expand Up @@ -167,7 +173,7 @@ public function testDefaultExpressions()

$acct->save();

$acct = BookstoreEmployeeAccountPeer::retrieveByPK($acct->getEmployeeId());
$acct = BookstoreEmployeeAccountQuery::create()->findPk($acct->getEmployeeId());

$this->assertNotNull($acct->getAuthenticator(), "Expected a valid (non-NULL) authenticator column after save.");
$this->assertEquals('Password', $acct->getAuthenticator(), "Expected authenticator='Password' after save.");
Expand Down Expand Up @@ -326,7 +332,7 @@ public function testObjectInstances_New()
$emp->save();
$id = $emp->getId();

$retrieved = BookstoreEmployeePeer::retrieveByPK($id);
$retrieved = BookstoreEmployeeQuery::create()->findPk($id);
$this->assertSame($emp, $retrieved, "Expected same object (from instance pool)");
}

Expand Down Expand Up @@ -361,7 +367,7 @@ public function testObjectInstances_Fkeys()
. " publisher_id = " . $pub2->getId()
. " WHERE id = " . $book->getId());

$book2 = BookPeer::retrieveByPK($book->getId());
$book2 = BookQuery::create()->findPk($book->getId());
$this->assertSame($book, $book2, "Expected same book object instance");

$this->assertEquals($pub1->getId(), $book->getPublisherId(), "Expected book to have OLD publisher id before reload()");
Expand Down Expand Up @@ -408,7 +414,7 @@ public function testObjectInstancePoolTypecasting()
$opinion->save();


$opinion2 = BookOpinionPeer::retrieveByPK($bookId, $readerId);
$opinion2 = BookOpinionQuery::create()->findPk(array($bookId, $readerId));

$this->assertSame($opinion, $opinion2, "Expected same object to be retrieved from differently type-casted primary key values.");

Expand Down Expand Up @@ -658,7 +664,7 @@ public function testCountRefFk()
BookPeer::clearInstancePool();
ReviewPeer::clearInstancePool();

$book = BookPeer::retrieveByPK($book->getId());
$book = BookQuery::create()->findPk($book->getId());
$this->assertEquals($num, $book->countReviews(), "Expected countReviews() to return $num (after save)");
$this->assertEquals($num, count($book->getReviews()), "Expected getReviews() to return $num (after save)");

Expand Down Expand Up @@ -820,7 +826,7 @@ public function testAllowPkInsertOnIdMethodNativeTable()

$this->assertEquals(100000, $cu->getPrimaryKey());

$cu2 = CustomerPeer::retrieveByPk(100000);
$cu2 = CustomerQuery::create()->findPk(100000);

$this->assertSame($cu, $cu2);
}
Expand Down Expand Up @@ -862,10 +868,10 @@ public function testUniqueFkRel()
BookstoreEmployeeAccountPeer::clearInstancePool();
AcctAuditLogPeer::clearInstancePool();

$al2 = AcctAuditLogPeer::retrieveByPK($alId);
$al2 = AcctAuditLogQuery::create()->findPk($alId);
/* @var $al2 AcctAuditLog */
$mapacct = $al2->getBookstoreEmployeeAccount();
$lookupacct = BookstoreEmployeeAccountPeer::retrieveByPK($acctId);
$lookupacct = BookstoreEmployeeAccountQuery::create()->findPk($acctId);

$logs = $lookupacct->getAcctAuditLogs();

Expand Down
Expand Up @@ -17,6 +17,7 @@
use Propel\Tests\Bookstore\AuthorPeer;
use Propel\Tests\Bookstore\Book;
use Propel\Tests\Bookstore\BookPeer;
use Propel\Tests\Bookstore\BookQuery;
use Propel\Tests\Bookstore\Bookstore;
use Propel\Tests\Bookstore\BookstorePeer;
use Propel\Tests\Bookstore\BookstoreSale;
Expand All @@ -29,10 +30,12 @@
use Propel\Tests\Bookstore\Map\BookstoreEmployeeTableMap;
use Propel\Tests\Bookstore\Map\MediaTableMap;
use Propel\Tests\Bookstore\MediaPeer;
use Propel\Tests\Bookstore\MediaQuery;
use Propel\Tests\Bookstore\Publisher;
use Propel\Tests\Bookstore\PublisherPeer;
use Propel\Tests\Bookstore\Review;
use Propel\Tests\Bookstore\ReviewPeer;
use Propel\Tests\Bookstore\ReviewQuery;
use Propel\Tests\Helpers\Bookstore\BookstoreEmptyTestBase;
use Propel\Tests\Helpers\Bookstore\BookstoreDataPopulator;

Expand Down Expand Up @@ -121,7 +124,7 @@ public function testDelete()
} catch (PropelException $e) {}

// 4) make sure that it doesn't exist in db
$book = BookPeer::retrieveByPK($bookId);
$book = BookQuery::create()->findPk($bookId);
$this->assertNull($book, "Expect NULL from retrieveByPK on deleted Book.");

}
Expand Down Expand Up @@ -168,7 +171,7 @@ public function testTypeSensitive()
BookPeer::clearInstancePool();

// reload and verify that the types are the same
$r2 = ReviewPeer::retrieveByPK($id);
$r2 = ReviewQuery::create()->findPk($id);

$this->assertInternalType('integer', $r2->getId(), "Expected getId() to return an integer.");
$this->assertInternalType('string', $r2->getReviewedBy(), "Expected getReviewedBy() to return a string.");
Expand Down
Expand Up @@ -17,26 +17,32 @@
use Propel\Tests\Bookstore\Map\AuthorTableMap;
use Propel\Tests\Bookstore\Book;
use Propel\Tests\Bookstore\BookPeer;
use Propel\Tests\Bookstore\BookQuery;
use Propel\Tests\Bookstore\Map\BookTableMap;
use Propel\Tests\Bookstore\BookOpinion;
use Propel\Tests\Bookstore\BookReader;
use Propel\Tests\Bookstore\BookReaderPeer;
use Propel\Tests\Bookstore\BookReaderQuery;
use Propel\Tests\Bookstore\Map\BookReaderTableMap;
use Propel\Tests\Bookstore\Bookstore;
use Propel\Tests\Bookstore\BookstoreContest;
use Propel\Tests\Bookstore\BookstoreContestPeer;
use Propel\Tests\Bookstore\Map\BookstoreContestTableMap;
use Propel\Tests\Bookstore\BookstoreContestEntry;
use Propel\Tests\Bookstore\BookstoreContestEntryPeer;
use Propel\Tests\Bookstore\BookstoreContestEntryQuery;
use Propel\Tests\Bookstore\Customer;
use Propel\Tests\Bookstore\Contest;
use Propel\Tests\Bookstore\BookstoreContestEntryPeer;
use Propel\Tests\Bookstore\MediaPeer;
use Propel\Tests\Bookstore\MediaQuery;
use Propel\Tests\Bookstore\Publisher;
use Propel\Tests\Bookstore\PublisherPeer;
use Propel\Tests\Bookstore\Map\PublisherTableMap;
use Propel\Tests\Bookstore\ReviewPeer;
use Propel\Tests\Bookstore\ReviewQuery;
use Propel\Tests\Bookstore\ReaderFavorite;
use Propel\Tests\Bookstore\ReaderFavoritePeer;
use Propel\Tests\Bookstore\ReaderFavoriteQuery;

use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
Expand Down Expand Up @@ -134,7 +140,7 @@ public function testDoDelete_Cascade_Simple()

// 3) Assert that the media row is now also gone

$obj = MediaPeer::retrieveByPK($mediaId);
$obj = MediaQuery::create()->findPk($mediaId);
$this->assertNull($obj, "Expect NULL when retrieving on no matching Media.");

}
Expand Down Expand Up @@ -198,10 +204,10 @@ public function testDoDelete_Cascade_CompositePK()

$this->assertEquals($origBceCount + 1, $newCount, "Expected new number of rows in BCE to be orig + 1");

$bcetest = BookstoreContestEntryPeer::retrieveByPK($store1->getId(), $c1->getId(), $cust1->getId());
$bcetest = BookstoreContestEntryQuery::create()->findPk(array($store1->getId(), $c1->getId(), $cust1->getId()));
$this->assertNull($bcetest, "Expected BCE for store1 to be cascade deleted.");

$bcetest2 = BookstoreContestEntryPeer::retrieveByPK($store1->getId(), $c2->getId(), $cust1->getId());
$bcetest2 = BookstoreContestEntryQuery::create()->findPk(array($store1->getId(), $c2->getId(), $cust1->getId()));
$this->assertNotNull($bcetest2, "Expected BCE for store2 to NOT be cascade deleted.");

}
Expand All @@ -225,7 +231,7 @@ public function testDoDelete_SetNull()

// 3) Assert that the book.author_id column is now NULL

$book = BookPeer::retrieveByPK($bookId);
$book = BookQuery::create()->findPk($bookId);
$this->assertNull($book->getAuthorId(), "Expect the book.author_id to be NULL after the author was removed.");

}
Expand All @@ -243,7 +249,7 @@ public function testDoDelete_ByPK()
BookPeer::doDelete($bookId);

// 3) now make sure it's gone
$obj = BookPeer::retrieveByPK($bookId);
$obj = BookQuery::create()->findPk($bookId);
$this->assertNull($obj, "Expect NULL when retrieving on no matching Book.");

}
Expand Down Expand Up @@ -281,7 +287,7 @@ public function testDoDelete_ByObj()
BookPeer::doDelete($book);

// 3) now make sure it's gone
$obj = BookPeer::retrieveByPK($bookId);
$obj = BookQuery::create()->findPk($bookId);
$this->assertNull($obj, "Expect NULL when retrieving on no matching Book.");

}
Expand All @@ -303,8 +309,8 @@ public function testDoDeleteAllInstancePool()
$review = ReviewPeer::doSelectOne(new Criteria);
$book = $review->getBook();
BookPeer::doDeleteAll();
$this->assertNull(BookPeer::retrieveByPk($book->getId()), 'doDeleteAll invalidates instance pool');
$this->assertNull(ReviewPeer::retrieveByPk($review->getId()), 'doDeleteAll invalidates instance pool of related tables with ON DELETE CASCADE');
$this->assertNull(BookQuery::create()->findPk($book->getId()), 'doDeleteAll invalidates instance pool');
$this->assertNull(ReviewQuery::create()->findPk($review->getId()), 'doDeleteAll invalidates instance pool of related tables with ON DELETE CASCADE');
}

/**
Expand Down Expand Up @@ -374,22 +380,22 @@ public function testDoDeleteCompositePK()
$this->assertEquals(4, ReaderFavoritePeer::doCount(new Criteria()));

//Note: these composite PK's are pairs of (BookId, ReaderId)
$this->assertNotNull(ReaderFavoritePeer::retrieveByPK(2,1));
$this->assertNotNull(ReaderFavoritePeer::retrieveByPK(1,2));
$this->assertNotNull(ReaderFavoritePeer::retrieveByPk(3,1));
$this->assertNotNull(ReaderFavoritePeer::retrieveByPk(3,2));
$this->assertNull(ReaderFavoritePeer::retrieveByPK(1,1));
$this->assertNull(ReaderFavoritePeer::retrieveByPK(2,2));
$this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(2,1)));
$this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(1,2)));
$this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(3,1)));
$this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(3,2)));
$this->assertNull(ReaderFavoriteQuery::create()->findPk(array(1,1)));
$this->assertNull(ReaderFavoriteQuery::create()->findPk(array(2,2)));

//test deletion of a single composite PK
ReaderFavoritePeer::doDelete(array(3,1));
$this->assertEquals(3, ReaderFavoritePeer::doCount(new Criteria()));
$this->assertNotNull(ReaderFavoritePeer::retrieveByPK(2,1));
$this->assertNotNull(ReaderFavoritePeer::retrieveByPK(1,2));
$this->assertNotNull(ReaderFavoritePeer::retrieveByPk(3,2));
$this->assertNull(ReaderFavoritePeer::retrieveByPK(1,1));
$this->assertNull(ReaderFavoritePeer::retrieveByPK(2,2));
$this->assertNull(ReaderFavoritePeer::retrieveByPk(3,1));
$this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(2,1)));
$this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(1,2)));
$this->assertNotNull(ReaderFavoriteQuery::create()->findPk(array(3,2)));
$this->assertNull(ReaderFavoriteQuery::create()->findPk(array(1,1)));
$this->assertNull(ReaderFavoriteQuery::create()->findPk(array(2,2)));
$this->assertNull(ReaderFavoriteQuery::create()->findPk(array(3,1)));

//test deleting the last three
ReaderFavoritePeer::doDelete(array(array(2,1), array(1,2), array(3,2)));
Expand Down Expand Up @@ -540,7 +546,7 @@ public function testRemoveInstanceFromPool_Null()
private function createBookWithId($id)
{
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$b = BookPeer::retrieveByPK($id);
$b = BookQuery::create()->findPk($id);
if (!$b) {
$b = new Book();
$b->setTitle("Book$id")->setISBN("BookISBN$id")->save();
Expand All @@ -559,7 +565,7 @@ private function createBookWithId($id)
private function createReaderWithId($id)
{
$con = Propel::getServiceContainer()->getConnection(BookReaderTableMap::DATABASE_NAME);
$r = BookReaderPeer::retrieveByPK($id);
$r = BookReaderQuery::create()->findPk($id);
if (!$r) {
$r = new BookReader();
$r->setName('Reader'.$id)->save();
Expand Down

0 comments on commit 00442b4

Please sign in to comment.