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', '\\Propel\\Tests\\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', 'Propel\\Tests\\Bookstore\\BookstoreEmployee');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $c->join('Propel\\Tests\\Bookstore\\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');
 }
Example #3
0
 /**
  * Test foreign key relationships based on references to unique cols but not PK.
  * @link       http://propel.phpdb.org/trac/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', 'Propel\\Tests\\Bookstore\\BookstoreEmployee');
     $c->join('Propel\\Tests\\Bookstore\\BookstoreEmployee.Supervisor s');
     $c->with('s');
     $c->where('s.Name = ?', 'John');
     $con = Propel::getServiceContainer()->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));
 }