Example #1
0
 public function testCommitAfterFetch()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     AuthorTableMap::doDeleteAll($con);
     $a = new Author();
     $a->setFirstName('Test');
     $a->setLastName('User');
     $a->save($con);
     $con->beginTransaction();
     $stmt = $con->prepare('SELECT author.FIRST_NAME, author.LAST_NAME FROM author');
     $stmt->execute();
     $authorArr = array(0 => 'Test', 1 => 'User');
     $i = 0;
     $row = $stmt->fetch(PDO::FETCH_NUM);
     $stmt->closeCursor();
     $con->commit();
     $this->assertEquals($authorArr, $row, 'PDO driver supports calling $stmt->fetch before the transaction has been closed');
 }
 /**
  * @see http://www.propelorm.org/ticket/959
  */
 public function testFindOneWithSameRelatedObject()
 {
     BookTableMap::doDeleteAll();
     AuthorTableMap::doDeleteAll();
     $auth = new Author();
     $auth->setFirstName('John');
     $auth->setLastName('Doe');
     $auth->save();
     $book1 = new Book();
     $book1->setTitle('Hello');
     $book1->setISBN('FA404');
     $book1->setAuthor($auth);
     $book1->save();
     $book2 = new Book();
     $book2->setTitle('World');
     $book2->setISBN('FA404');
     $book2->setAuthor($auth);
     $book2->save();
     BookTableMap::clearInstancePool();
     AuthorTableMap::clearInstancePool();
     $c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $c->join('Propel\\Tests\\Bookstore\\Book.Author');
     $c->with('Author');
     $books = $c->find();
     $this->assertEquals(2, count($books));
     $firstBook = $books[0];
     $this->assertTrue(isset($firstBook['Author']));
     $secondBook = $books[1];
     $this->assertTrue(isset($secondBook['Author']));
 }
 /**
  * Test the doDeleteAll() method when onDelete="SETNULL".
  */
 public function testDoDeleteAll_SetNull()
 {
     $c = new Criteria();
     $c->add(BookTableMap::AUTHOR_ID, null, Criteria::NOT_EQUAL);
     // 1) make sure there are some books with valid authors
     $this->assertGreaterThan(0, count(BookQuery::create()->filterByAuthorId(null, Criteria::NOT_EQUAL)->find()) > 0, "Expect some book.author_id columns that are not NULL.");
     // 2) delete all the authors
     AuthorTableMap::doDeleteAll();
     // 3) now verify that the book.author_id columns are all null
     $this->assertCount(0, BookQuery::create()->filterByAuthorId(null, Criteria::NOT_EQUAL)->find(), "Expect all book.author_id columns to be NULL.");
 }