Пример #1
0
 public function testClear()
 {
     $set1 = new Set([1, 6, 4, 3]);
     $this->assertEquals($set1->size(), 4);
     $set1->clear();
     $this->assertTrue($set1->isEmpty());
     $this->assertEquals($set1->size(), 0);
     $set1->add('foo');
     $this->assertEquals($set1->count(), 1);
 }
Пример #2
0
 /**
  * Removes all the elements from the collection.
  */
 public function clear()
 {
     if ($this->guard !== null) {
         $this->guard->checkMemberGuard(new GuardPermission(__FUNCTION__, 'call'));
     }
     $this->set->clear();
 }
Пример #3
0
} catch (Exception $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n\n";
}
// readonly collection
echo "Construct as readonly\n";
$set2 = new Set($arr);
$set2->freeze();
Debug::dump($set2->isFrozen());
try {
    echo "Adding Jack\n";
    Debug::dump($set2->append($jack));
} catch (Exception $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n\n";
}
try {
    echo "Removing Jack\n";
    $set2->remove($jack);
} catch (Exception $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n\n";
}
try {
    echo "Clearing\n";
    $set2->clear();
} catch (Exception $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n\n";
}
foreach ($set2 as $key => &$val) {
    $val = FALSE;
}
echo "Contains Jack?\n";
Debug::dump($set2->contains($jack));