コード例 #1
0
 public function testConnectionChoosesOnlyOneWorkingConnection()
 {
     $mock1 = new FullMockConnection();
     $mock1->setReturnValue("isAlive", false);
     $mock1->expectOnce("start");
     $mock1->expectNever("read");
     $mock1->expectNever("write");
     $mock2 = new FullMockConnection();
     $mock2->setReturnValue("isAlive", true);
     $mock2->expectOnce("start");
     $mock2->expectOnce("read");
     $mock2->expectCallCount("write", 3);
     $mock2->expectAt(0, "write", array("foo", "*"));
     $mock2->expectAt(1, "write", array("bar", "*"));
     $mock2->expectAt(2, "write", array("zip", "*"));
     $mock3 = new FullMockConnection();
     $mock3->setReturnValue("isAlive", true);
     $mock3->expectNever("start");
     $mock3->expectNever("read");
     $mock3->expectNever("write");
     $multi = new Swift_Connection_Multi();
     $multi->addConnection($mock1, "mock1");
     $multi->addConnection($mock2, "mock2");
     $multi->addConnection($mock3, "mock3");
     $multi->start();
     $multi->read();
     $multi->write("foo");
     $multi->write("bar");
     $multi->write("zip");
 }
コード例 #2
0
 public function testDeadConnectionsAreNeverReTried()
 {
     $mock1 = new FullMockConnection();
     $mock1->setReturnValue("isAlive", false);
     $mock1->expectCallCount("isAlive", 2);
     //Once for first check, twice for check after calling start()
     $mock2 = new FullMockConnection();
     $mock2->setReturnValue("isAlive", false);
     $mock2->expectCallCount("isAlive", 2);
     $mock3 = new FullMockConnection();
     $mock3->setReturnValue("isAlive", true);
     $mock3->setReturnValueAt(0, "isAlive", false);
     $mock3->setReturnValueAt(1, "isAlive", true);
     $mock3->expectCallCount("isAlive", 8);
     $multi = new Swift_Connection_Rotator();
     $multi->addConnection($mock1);
     $multi->addConnection($mock2);
     $multi->addConnection($mock3);
     $multi->start();
     for ($i = 0; $i < 3; $i++) {
         $multi->nextConnection();
     }
 }