Exemple #1
0
 public function testRemove()
 {
     $dispatcher = new Dispatcher();
     $request = m::mock('jyggen\\Curl\\RequestInterface');
     $request->shouldReceive('addMultiHandle')->andReturn(0);
     $request->shouldReceive('removeMultiHandle')->andReturn(0);
     $dispatcher->add($request);
     $dispatcher->remove(0);
     $this->assertEquals(array(), $dispatcher->get());
 }
Exemple #2
0
 /**
  * Handle all static helpers.
  * @param  mixed $name
  * @param  array $arguments
  * @return mixed
  */
 public static function __callStatic($name, $arguments)
 {
     $allowedVerbs = array('delete', 'get', 'post', 'put');
     if (in_array($name, $allowedVerbs)) {
         // We require at least one URL.
         if (!isset($arguments[0])) {
             $message = sprintf('Missing argument 1 for %s::%s()', get_called_class(), $name);
             throw new InvalidArgumentException($message);
         }
         $urls = $arguments[0];
         $data = isset($arguments[1]) ? $arguments[1] : null;
         if (!is_array($urls)) {
             $urls = array($urls => $data);
         } elseif (!(bool) count(array_filter(array_keys($urls), 'is_string'))) {
             foreach ($urls as $key => $url) {
                 $urls[$url] = null;
                 unset($urls[$key]);
             }
         }
         $dispatcher = new Dispatcher();
         $requests = array();
         $dataStore = array();
         foreach ($urls as $url => $data) {
             $requests[] = new Request($url);
             $dataStore[] = $data;
         }
         new static($name, $dispatcher, $requests, $dataStore);
         $requests = $dispatcher->get();
         $responses = array();
         foreach ($requests as $request) {
             $responses[] = $request->getResponse();
         }
         return $responses;
     } else {
         throw new BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_called_class(), $name));
     }
 }