/** * This is run after each unit test. It empties the database. */ protected function tearDown() { BookstoreDataPopulator::depopulate(); $this->assertEquals(0, count(BookPeer::doSelect(new Criteria())), "Expect book table to be empty."); $this->assertEquals(0, count(AuthorPeer::doSelect(new Criteria())), "Expect author table to be empty."); $this->assertEquals(0, count(PublisherPeer::doSelect(new Criteria())), "Expect publisher table to be empty."); $this->assertEquals(0, count(ReviewPeer::doSelect(new Criteria())), "Expect review table to be empty."); $this->assertEquals(0, count(MediaPeer::doSelect(new Criteria())), "Expect media table to be empty."); $this->assertEquals(0, count(BookstoreEmployeePeer::doSelect(new Criteria())), "Expect bookstore_employee table to be empty."); $this->assertEquals(0, count(BookstoreEmployeeAccountPeer::doSelect(new Criteria())), "Expect bookstore_employee_account table to be empty."); $this->assertEquals(0, count(BookstoreSalePeer::doSelect(new Criteria())), "Expect bookstore_sale table to be empty."); BookPeer::clearInstancePool(); $this->assertEquals(0, count(BookPeer::$instances), "Expected 0 Book instances after clearInstancePool()"); AuthorPeer::clearInstancePool(); $this->assertEquals(0, count(AuthorPeer::$instances), "Expected 0 Author instances after clearInstancePool()"); PublisherPeer::clearInstancePool(); $this->assertEquals(0, count(PublisherPeer::$instances), "Expected 0 Publisher instances after clearInstancePool()"); ReviewPeer::clearInstancePool(); $this->assertEquals(0, count(ReviewPeer::$instances), "Expected 0 Review instances after clearInstancePool()"); MediaPeer::clearInstancePool(); $this->assertEquals(0, count(MediaPeer::$instances), "Expected 0 Media instances after clearInstancePool()"); BookstoreEmployeePeer::clearInstancePool(); $this->assertEquals(0, count(BookstoreEmployeePeer::$instances), "Expected 0 BookstoreEmployee instances after clearInstancePool()"); BookstoreEmployeeAccountPeer::clearInstancePool(); $this->assertEquals(0, count(BookstoreEmployeeAccountPeer::$instances), "Expected 0 BookstoreEmployeeAccount instances after clearInstancePool()"); BookstoreSalePeer::clearInstancePool(); $this->assertEquals(0, count(BookstoreSalePeer::$instances), "Expected 0 BookstoreSale instances after clearInstancePool()"); parent::tearDown(); }
public function testFormat() { $con = Propel::getConnection(BookPeer::DATABASE_NAME); BookstoreEmployeePeer::clearInstancePool(); $stmt = $con->query('SELECT * FROM bookstore_employee'); $formatter = new PropelObjectFormatter(); $formatter->init(new ModelCriteria('bookstore', 'BookstoreEmployee')); $emps = $formatter->format($stmt); $expectedClass = array('b1' => 'BookstoreEmployee', 'b2' => 'BookstoreManager', 'b3' => 'BookstoreCashier'); foreach ($emps as $emp) { $this->assertEquals($expectedClass[$emp->getName()], get_class($emp), 'format() creates objects of the correct class when using inheritance'); } }
public function testFindOneWithRelationName() { BookstoreDataPopulator::populate(); BookstoreEmployeePeer::clearInstancePool(); $c = new ModelCriteria('bookstore', 'BookstoreEmployee'); $c->setFormatter(ModelCriteria::FORMAT_ARRAY); $c->join('BookstoreEmployee.Supervisor s'); $c->with('s'); $c->where('s.Name = ?', 'John'); $emp = $c->findOne(); $this->assertEquals($emp['Name'], 'Pieter', 'Main object is correctly hydrated'); $sup = $emp['Supervisor']; $this->assertEquals($sup['Name'], 'John', 'Related object is correctly hydrated'); }
/** * Test foreign key relationships based on references to unique cols but not PK. * @link http://trac.propelorm.org/ticket/691 */ public function testUniqueFkRel() { BookstoreEmployeeAccountPeer::doDeleteAll(); $employee = new BookstoreEmployee(); $employee->setName("Johnny Walker"); $acct = new BookstoreEmployeeAccount(); $acct->setBookstoreEmployee($employee); $acct->setLogin("test-login"); $acct->save(); $acctId = $acct->getEmployeeId(); $al = new AcctAuditLog(); $al->setBookstoreEmployeeAccount($acct); $al->save(); $alId = $al->getId(); BookstoreEmployeePeer::clearInstancePool(); BookstoreEmployeeAccountPeer::clearInstancePool(); AcctAuditLogPeer::clearInstancePool(); $al2 = AcctAuditLogPeer::retrieveByPK($alId); /* @var $al2 AcctAuditLog */ $mapacct = $al2->getBookstoreEmployeeAccount(); $lookupacct = BookstoreEmployeeAccountPeer::retrieveByPK($acctId); $logs = $lookupacct->getAcctAuditLogs(); $this->assertTrue(count($logs) == 1, "Expected 1 audit log result."); $this->assertEquals($logs[0]->getId(), $al->getId(), "Expected returned audit log to match created audit log."); }
public function testFindOneWithRelationName() { BookstoreDataPopulator::populate(); BookstoreEmployeePeer::clearInstancePool(); $c = new ModelCriteria('bookstore', 'BookstoreEmployee'); $c->join('BookstoreEmployee.Supervisor s'); $c->with('s'); $c->where('s.Name = ?', 'John'); $con = Propel::getConnection(BookPeer::DATABASE_NAME); $emp = $c->findOne($con); $count = $con->getQueryCount(); $this->assertEquals($emp->getName(), 'Pieter', 'Main object is correctly hydrated'); $sup = $emp->getSupervisor(); $this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query'); $this->assertEquals($sup->getName(), 'John', 'Related object is correctly hydrated'); }
/** * Test inheritance features. */ public function testInheritance() { $manager = new BookstoreManager(); $manager->setName("Manager 1"); $manager->setJobTitle("Warehouse Manager"); $manager->save(); $managerId = $manager->getId(); $employee = new BookstoreEmployee(); $employee->setName("Employee 1"); $employee->setJobTitle("Janitor"); $employee->setSupervisorId($managerId); $employee->save(); $empId = $employee->getId(); $cashier = new BookstoreCashier(); $cashier->setName("Cashier 1"); $cashier->setJobTitle("Cashier"); $cashier->save(); $cashierId = $cashier->getId(); // 1) test the pooled instances' $c = new Criteria(); $c->add(BookstoreEmployeePeer::ID, array($managerId, $empId, $cashierId), Criteria::IN); $c->addAscendingOrderByColumn(BookstoreEmployeePeer::ID); $objects = BookstoreEmployeePeer::doSelect($c); $this->assertEquals(3, count($objects), "Expected 3 objects to be returned."); list($o1, $o2, $o3) = $objects; $this->assertSame($o1, $manager); $this->assertSame($o2, $employee); $this->assertSame($o3, $cashier); // 2) test a forced reload from database BookstoreEmployeePeer::clearInstancePool(); list($o1, $o2, $o3) = BookstoreEmployeePeer::doSelect($c); $this->assertTrue($o1 instanceof BookstoreManager, "Expected BookstoreManager object, got " . get_class($o1)); $this->assertTrue($o2 instanceof BookstoreEmployee, "Expected BookstoreEmployee object, got " . get_class($o2)); $this->assertTrue($o3 instanceof BookstoreCashier, "Expected BookstoreCashier object, got " . get_class($o3)); }