public function closeCursor() { $this->dataFetcher->close(); if ($this->enableInstancePoolingOnFinish) { Propel::enableInstancePooling(); } }
public function testInstancePoolingReenabled() { Propel::enableInstancePooling(); $books = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book')->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find($this->con); foreach ($books as $book) { } $this->assertTrue(Propel::isInstancePoolingEnabled()); Propel::disableInstancePooling(); $books = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book')->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find($this->con); foreach ($books as $book) { } $this->assertFalse(Propel::isInstancePoolingEnabled()); Propel::enableInstancePooling(); }
public function setUp() { parent::setUp(); $a = new Author(); $a->setFirstName("Douglas"); $a->setLastName("Adams"); $b1 = new Book(); $b1->setTitle("The Hitchhikers Guide To The Galaxy"); $a->addBook($b1); $b2 = new Book(); $b2->setTitle("The Restaurant At The End Of The Universe"); $a->addBook($b2); $a->save(); $this->author = $a; $this->books = array($b1, $b2); Propel::enableInstancePooling(); // Clear author instance pool so the object would be fetched from the database AuthorTableMap::clearInstancePool(); }
/** * Populate the database using all the Entity classes previously added. * * @param PropelPDO $con A Propel connection object * * @return array A list of the inserted PKs */ public function execute($con = null) { if (null === $con) { $con = $this->getConnection(); } $isInstancePoolingEnabled = Propel::isInstancePoolingEnabled(); Propel::disableInstancePooling(); $insertedEntities = array(); $con->beginTransaction(); foreach ($this->quantities as $class => $number) { for ($i = 0; $i < $number; $i++) { $insertedEntities[$class][] = $this->entities[$class]->execute($con, $insertedEntities); } } $con->commit(); if ($isInstancePoolingEnabled) { Propel::enableInstancePooling(); } return $insertedEntities; }
public function testFindPkCompositeKey() { BookstoreDataPopulator::depopulate(); $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\BookListRel'); $bookListRel = $c->findPk(array(1, 2)); $this->assertNull($bookListRel, 'findPk() returns null when the composite primary key is not found'); Propel::enableInstancePooling(); BookstoreDataPopulator::populate(); // save all books to make sure related objects are also saved - BookstoreDataPopulator keeps some unsaved $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book'); $books = $c->find(); foreach ($books as $book) { $book->save(); } // retrieve the test data $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\BookListRel'); $bookListRelTest = $c->findOne(); $pk = $bookListRelTest->getPrimaryKey(); $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\BookListRel'); $bookListRel = $c->findPk($pk); $this->assertEquals($bookListRelTest, $bookListRel, 'findPk() can find objects with composite primary keys'); }
/** * Bug found in Thelia 2.0.2 */ public function testUpdateDefaultAddress() { /** * Disable propel cache in order to get a new instance of the * active record in $updatedAddress */ Propel::disableInstancePooling(); /** * Get a customer and it's default address */ $customer = CustomerQuery::create()->findOne(); $defaultAddress = $customer->getDefaultAddress(); $addressId = $defaultAddress->getId(); /** * Try to update the address, and set the isDefault argument, * that should keep this address as the default one. */ $addressEvent = new AddressCreateOrUpdateEvent("", 1, "Thelia modif", "Thelia modif", "cour des étoiles", "rue des miracles", "", "63000", "clermont-ferrand", 64, "0102030405", "", "", 1); $addressEvent->setAddress($defaultAddress); $addressEvent->setDispatcher($this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface")); /** * Do the update */ $actionAddress = new Address(); $actionAddress->update($addressEvent); $updatedAddress = AddressQuery::create()->findPk($addressId); /** * This address should still be the default address */ $this->assertEquals(1, $updatedAddress->getIsDefault()); /** * Renable it after */ Propel::enableInstancePooling(); }
public function testFormatALotOfResults() { $nbBooks = 50; $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME); Propel::disableInstancePooling(); $book = new Book(); for ($i = 0; $i < $nbBooks; $i++) { $book->clear(); $book->setTitle('BookTest' . $i); $book->setISBN('FA404-' . $i); $book->save($con); } $stmt = $con->query('SELECT * FROM book'); $formatter = new OnDemandFormatter(); $formatter->init(new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book')); $books = $formatter->format($stmt); $this->assertTrue($books instanceof OnDemandCollection, 'OnDemandFormatter::format() returns a PropelOnDemandCollection'); $this->assertEquals($nbBooks, count($books), 'OnDemandFormatter::format() returns a collection that counts as many rows as the results in the query'); $i = 0; foreach ($books as $book) { $this->assertTrue($book instanceof Book, 'OnDemandFormatter::format() returns a collection of Model objects'); $this->assertEquals('BookTest' . $i, $book->getTitle(), 'OnDemandFormatter::format() returns the model objects matching the query'); $i++; } Propel::enableInstancePooling(); }
protected function tearDown() { $this->books = null; parent::tearDown(); Propel::enableInstancePooling(); }
public function testFindPkSimpleWithAbstractSingleTableInheritanceReturnCorrectClass() { Propel::disableInstancePooling(); $manager = new DistributionManager(); $manager->setName('manager1'); $manager->save(); $distributionStore = new DistributionStore(); $distributionStore->setName('my store 1'); $distributionStore->setDistributionManager($manager); $distributionStore->save(); $distributionVirtualStore = new DistributionVirtualStore(); $distributionVirtualStore->setName('my VirtualStore 1'); $distributionVirtualStore->setDistributionManager($manager); $distributionVirtualStore->save(); $this->assertInstanceOf('Propel\\Tests\\Bookstore\\DistributionStore', DistributionQuery::create()->findPk($distributionStore->getId()), 'findPk() return right object : DistributionStore'); $this->assertInstanceOf('Propel\\Tests\\Bookstore\\DistributionVirtualStore', DistributionQuery::create()->findPk($distributionVirtualStore->getId()), 'findPk() return right object : DistributionVirtualStore'); Propel::enableInstancePooling(); }
public function testParamConvertWithOptionWith() { $this->loadFixtures(); $paramConverter = new PropelParamConverter(); $request = new Request(array(), array(), array('id' => 1, 'book' => null)); $configuration = new ParamConverter(array('class' => 'Propel\\Bundle\\PropelBundle\\Tests\\Request\\ParamConverter\\MyBook', 'name' => 'book', 'options' => array('with' => 'MyAuthor'))); $nb = $this->con->getQueryCount(); $paramConverter->apply($request, $configuration); $book = $request->attributes->get('book'); $this->assertInstanceOf('Propel\\Bundle\\PropelBundle\\Tests\\Request\\ParamConverter\\MyBook', $book, 'param "book" should be an instance of "Propel\\Bundle\\PropelBundle\\Tests\\Request\\ParamConverter\\MyBook"'); $this->assertEquals($nb + 1, $this->con->getQueryCount(), 'only one query to get the book'); $this->assertInstanceOf('Propel\\Bundle\\PropelBundle\\Tests\\Request\\ParamConverter\\MyAuthor', $book->getMyAuthor(), 'param "book" should be an instance of "Propel\\Bundle\\PropelBundle\\Tests\\Request\\ParamConverter\\MyAuthor"'); $this->assertEquals($nb + 1, $this->con->getQueryCount(), 'no new query to get the author'); Propel::enableInstancePooling(); }
public function testHydrateOverwritePreviousValues() { $schema = <<<EOF <database name="generated_object_complex_type_test_with_constructor" namespace="MyNameSpace"> <table name="complex_column_type_entity_with_constructor"> <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" /> <column name="tags" type="ARRAY" /> </table> </database> EOF; QuickBuilder::buildSchema($schema); Propel::disableInstancePooling(); // need to be disabled to test the hydrate() method $obj = new ComplexColumnTypeEntityWithConstructor(); $this->assertEquals(array('foo', 'bar'), $obj->getTags()); $obj->setTags(array('baz')); $this->assertEquals(array('baz'), $obj->getTags()); $obj->save(); $obj = ComplexColumnTypeEntityWithConstructorQuery::create()->findOne(); $this->assertEquals(array('baz'), $obj->getTags()); Propel::enableInstancePooling(); }
public function enablePooling() { \Propel\Runtime\Propel::enableInstancePooling(); }
protected function tearDown() { parent::tearDown(); Propel::enableInstancePooling(); }
public function testDoSelectJoinOneToOne() { $con = Propel::getServiceContainer()->getReadConnection(BookstoreEmployeeAccountPeer::DATABASE_NAME); $count = $con->getQueryCount(); Propel::disableInstancePooling(); $c = new Criteria(); $accs = BookstoreEmployeeAccountPeer::doSelectJoinBookstoreEmployee($c, $con); Propel::enableInstancePooling(); $this->assertEquals(1, $con->getQueryCount() - $count, 'doSelectJoin() makes only one query in a one-to-one relationship'); }
/** * @afterClass */ public static function enableInstancePooling() { Propel::enableInstancePooling(); //Enable it for the other tests }
public function testFindOneWithDistantClassRenamedRelation() { BookstoreDataPopulator::populate(); BookTableMap::clearInstancePool(); AuthorTableMap::clearInstancePool(); ReviewTableMap::clearInstancePool(); Propel::enableInstancePooling(); $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\BookSummary'); $c->joinWith('Propel\\Tests\\Bookstore\\BookSummary.SummarizedBook'); $c->joinWith('SummarizedBook.Author'); $c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND); $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME); $summary = $c->findOne($con); $count = $con->getQueryCount(); $this->assertEquals('Harry Potter does some amazing magic!', $summary->getSummary(), 'Main object is correctly hydrated'); $book = $summary->getSummarizedBook(); $this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query'); $this->assertEquals('Harry Potter and the Order of the Phoenix', $book->getTitle(), 'Related object is correctly hydrated'); $author = $book->getAuthor(); $this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query'); $this->assertEquals('J.K.', $author->getFirstName(), 'Related object is correctly hydrated'); }
/** * Advances the curesor in the statement * Closes the cursor if the end of the statement is reached */ public function next() { $this->currentRow = $this->stmt->fetch(PDO::FETCH_NUM); $this->currentKey++; $this->isValid = (bool) $this->currentRow; if (!$this->isValid) { $this->closeCursor(); if ($this->enableInstancePoolingOnFinish) { Propel::enableInstancePooling(); } } }
public function testFindOneWithDistantClassRenamedRelation() { BookstoreDataPopulator::populate(); BookPeer::clearInstancePool(); AuthorPeer::clearInstancePool(); ReviewPeer::clearInstancePool(); Propel::enableInstancePooling(); $c = new ModelCriteria('bookstore', 'BookSummary'); $c->joinWith('BookSummary.SummarizedBook'); $c->joinWith('SummarizedBook.Author'); $c->setFormatter(ModelCriteria::FORMAT_ARRAY); $con = Propel::getConnection(BookPeer::DATABASE_NAME); $summary = $c->findOne($con); $count = $con->getQueryCount(); $this->assertEquals('Harry Potter does some amazing magic!', $summary['Summary'], 'Main object is correctly hydrated'); $book = $summary['SummarizedBook']; $this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query'); $this->assertEquals('Harry Potter and the Order of the Phoenix', $book['Title'], 'Related object is correctly hydrated'); $author = $book['Author']; $this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query'); $this->assertEquals('J.K.', $author['FirstName'], 'Related object is correctly hydrated'); }