public function testWait() { $tmpfile = tmpfile(); $reqp = $this->prophesize('Hirak\\Prestissimo\\CopyRequest'); $reqp->getCurlOptions()->willReturn(array(CURLOPT_URL => 'file://uso800.txt', CURLOPT_FILE => $tmpfile)); $reqp->getMaskedURL()->willReturn('file://uso800.txt'); $reqp->makeSuccess()->willReturn(null); $requests = array($reqp->reveal()); $multi = new CurlMulti(); $multi->setRequests($requests); do { $multi->setupEventLoop(); $multi->wait(); $result = $multi->getFinishedResults(); $this->assertEquals(0, $result['successCnt']); $this->assertEquals(1, $result['failureCnt']); } while ($multi->remain()); rewind($tmpfile); $content = stream_get_contents($tmpfile); $this->assertEmpty($content); }
/** * Retry all failed requests of the given array of Curl instances. * * @param array $curlInstances An array of Curl instances of which failed ones should be retried * * @return int The number of failed requests which were retried. */ public function retryFailed($curlInstances) { $failed = 0; $curlMultiInstance = new CurlMulti(); /** * @var $curlInstance Curl */ foreach ($curlInstances as $curlInstance) { if ($curlInstance->isSuccessful()) { continue; } $curlInstance->setRetryCount($curlInstance->getRetryCount() + 1); $curlMultiInstance->addInstance($curlInstance); $failed++; } $curlMultiInstance->exec(); return $failed; }
public function testAll() { $c = $this->getMock('PHPCurl\\CurlWrapper\\Curl', array('getHandle')); $c->expects($this->any())->method('getHandle')->will($this->returnValue('bar')); $cm = new CurlMulti(); $this->assertEquals('foo', $cm->getHandle()); $this->assertEquals('setopt_foo_opt_val', $cm->setOpt('opt', 'val')); $this->assertEquals('add_handle_foo_bar', $cm->add($c)); $this->assertEquals('remove_handle_foo_bar', $cm->remove($c)); $this->assertEquals('getcontent_bar', $cm->getContent($c)); $this->assertEquals('select_foo_1', $cm->select()); $this->assertEquals('select_foo_2.3', $cm->select(2.3)); $this->assertEquals('info_read_foo', $cm->infoRead($msgs)); $this->assertEquals(42, $msgs); $this->assertEquals('exec_foo', $cm->exec($running)); $this->assertEquals(24, $running); $this->assertEquals('strerror_boo', CurlMulti::strerror('boo')); unset($cm); $this->assertEquals('close_foo', array_pop(self::$log)); }