mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-12 03:16:34 +00:00
Merge pull request #229 from zachborboa/master
Add test for adding Multicurl handles after calling start()
This commit is contained in:
@@ -488,6 +488,10 @@ class MultiCurl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$active) {
|
||||
$active = count($this->curls);
|
||||
}
|
||||
} while ($active > 0);
|
||||
|
||||
$this->isStarted = false;
|
||||
@@ -578,6 +582,5 @@ class MultiCurl
|
||||
}
|
||||
$curl->setJsonDecoder($this->jsonDecoder);
|
||||
$curl->call($curl->beforeSendFunction);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1938,4 +1938,36 @@ class MultiCurlTest extends PHPUnit_Framework_TestCase
|
||||
PHPUnit_Framework_Assert::assertEquals('key=value', $instance->response);
|
||||
});
|
||||
}
|
||||
|
||||
public function testAddRequestAfterStart() {
|
||||
$multi_curl = new MultiCurl();
|
||||
|
||||
$urls = array();
|
||||
$copy_of_urls = array();
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$url = Test::TEST_URL . '?' . md5(mt_rand());
|
||||
$urls[] = $url;
|
||||
$copy_of_urls[] = $url;
|
||||
}
|
||||
|
||||
$urls_called = array();
|
||||
$multi_curl->complete(function ($instance) use (&$multi_curl, &$urls, &$urls_called) {
|
||||
$urls_called[] = $instance->url;
|
||||
$next_url = array_pop($urls);
|
||||
if (!($next_url === null)) {
|
||||
$multi_curl->addGet($next_url);
|
||||
}
|
||||
});
|
||||
|
||||
$multi_curl->addGet(array_pop($urls));
|
||||
$multi_curl->start();
|
||||
|
||||
$this->assertNotEmpty($copy_of_urls);
|
||||
$this->assertNotEmpty($urls_called);
|
||||
$this->assertEquals(count($copy_of_urls), count($urls_called));
|
||||
|
||||
foreach ($copy_of_urls as $url) {
|
||||
$this->assertTrue(in_array($url, $urls_called, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user