/** * */ public function executeMostViewed() { $this->objects = sfCounterPeer::getMostCounted(); }
$object->delete(); $t->ok(sfCounterPeer::doCount(new Criteria()) == 1, 'When an object is deleted, its counter is also deleted.'); $object3 = _create_object(); $object3->save(); $object3->incrementCounter(); $object3->incrementCounter(); $object3->incrementCounter(); $object3->incrementCounter(); $object3->incrementCounter(); $object3->incrementCounter(); $object3->incrementCounter(); $object3->incrementCounter(); $object3->incrementCounter(); $object3->incrementCounter(); $object3->incrementCounter(); $most_counted = sfCounterPeer::getMostCounted(); $t->ok($most_counted[0]->getCounter() > $most_counted[1]->getCounter(), 'sfCounterPeer::getMostCounted() returns objects from the most counted to the less one.'); $object3->incrementCounter(); $most_counted[0]->incrementCounter(); $most_counted[0]->incrementCounter(); $t->ok(sfCounterPeer::doCount(new Criteria()) == 2, 'sfCounterPeer::getMostCounted() does not duplicate the counters, even while preloading them into the objects.'); // several instances of the same countable object have separate counters // lifecycles, once the counter has been selected from the DB. $t->ok($object3->getCounter() == 12 && $most_counted[0]->getCounter() == 13, 'several instances of the same object have separate counter\'s lifes.'); // test object creation function _create_object() { $classname = TEST_CLASS; if (!class_exists($classname)) { throw new Exception(sprintf('Unknow class "%s"', $classname)); }