Esempio n. 1
0
    /**
    * Test that PropelCollection->add() prevents duplicates of objects strictly identical
    *
    */
   public function testAdd()
    {
        Propel::disableInstancePooling();
        $eleve1 = EleveQuery::create()->findOneByLogin('Florence Michu');
        $eleve1->setNom('test_different');
        $eleve_col = new PropelCollection();
        $eleve_col->add($eleve1);
        $eleve1idem = EleveQuery::create()->findOneByLogin('Florence Michu');
        $this->assertFalse($eleve_col->contains($eleve1idem));
        $eleve_col->add($eleve1idem);
        $this->assertEquals(2, count($eleve_col));
        Propel::enableInstancePooling();


        $eleve1 = EleveQuery::create()->findOneByLogin('Florence Michu');
        $eleve_col = new PropelCollection();
        $eleve_col->add($eleve1);
        $eleve_col->add($eleve1);
        $this->assertEquals(1, count($eleve_col));
    }
 /**
  * {@inheritdoc}
  */
 public function contains($element)
 {
     if ($element instanceof BaseObject) {
         if (null !== ($elt = $this->getIdenticalObject($element))) {
             $element = $elt;
         }
     }
     return parent::contains($element);
 }
Esempio n. 3
0
 /**
  * Returns an array of objects present in the collection that
  * are not presents in the given collection.
  *
  * @param PropelCollection $collection	A Propel collection.
  * @return PropelCollection				An array of Propel objects from the collection that are not presents in the given collection.
  */
 public function diff(PropelCollection $collection)
 {
     $diff = clone $this;
     $diff->clear();
     foreach ($this as $object) {
         if (!$collection->contains($object)) {
             $diff[] = $object;
         }
     }
     return $diff;
 }
 public function testContains()
 {
     $col = new PropelCollection();
     $this->assertFalse($col->contains('foo_1'), 'contains() returns false on an empty collection');
     $data = array('bar1', 'bar2', 'bar3');
     $col = new PropelCollection($data);
     $this->assertTrue($col->contains('bar1'), 'contains() returns true when the key exists');
     $this->assertFalse($col->contains('bar4'), 'contains() returns false when the key does not exist');
 }