public function elect_returns_null_when_no_member_elected()
 {
     $f = Failover::using([1, 2, 3, 4, 5])->bySerial();
     $this->assertEquals(null, $f->elect(function ($member) {
         return false;
     }));
 }
Exemple #2
0
 /**
  * Constructor
  *
  * @param   var $url either a URL object or a string
  * @throws  lang.IllegalArgumentException if string given is unparseable
  */
 public function __construct($url)
 {
     if ($url instanceof Failover) {
         $this->failover = $url;
     } else {
         $this->failover = Failover::using([$url])->byRandom();
     }
     // Walk through all failover members, to check they all have valid URLs; by returning
     // false, indicate to failover to the next available member.
     // For BC reasons, if one connection has a log=<category> parameter, read it
     // and set it into this objects $cat member.
     $this->failover->elect(function ($url) {
         $url = self::urlFrom($url);
         if (!$this->cat && $url->hasParam('log')) {
             $this->setTrace(Logger::getInstance()->getCategory($url->getParam('log')));
         }
         return false;
     });
 }