/**
  * @param FactoryArguments $arguments
  * @param $method
  * @param array $parameters
  * @return mixed
  * @throws \LukaszMordawski\CampaignMonitorBundle\Exception\Exception
  * @throws \LogicException
  *
  * This method invokes proper API method and stores result in cache.
  */
 public function invoke(FactoryArguments $arguments, $method, $parameters = [])
 {
     if (!$arguments->clientId) {
         $arguments->clientId = $this->clientId;
     }
     $method = Inflector::tableize($method);
     $cacheKey = $this->getCacheKey($arguments, $method, $parameters);
     if ($this->cache->contains($cacheKey)) {
         return unserialize($this->cache->fetch($cacheKey));
     }
     $csClient = $this->factory->factory($arguments);
     if (method_exists($csClient, $method)) {
         if (is_array($parameters)) {
             $data = call_user_func_array([$csClient, $method], $parameters);
         } else {
             $data = call_user_func([$csClient, $method], $parameters);
         }
     } else {
         throw new \LogicException(sprintf('Method %s does not exist for class %s', $method, get_class($csClient)));
     }
     if ($data->http_status_code != 200 && $data->http_status_code != 201) {
         throw new Exception($data->response->Message, $data->response->Code);
     }
     $this->cache->save($cacheKey, serialize($data->response), $this->cacheLifetime);
     return $data->response;
 }
 /**
  * @param $endpoint
  * @param $expectedClassName
  * @dataProvider factoryWithSecondParameterProvider
  */
 public function testFactory_WithSecondParameter($endpoint, $secondArg, $expectedClassName, $propertyToCheck)
 {
     $factory = new Factory('2321312');
     $args = new FactoryArguments();
     $args->endpoint = $endpoint;
     $args->{$secondArg} = '123456';
     $service = $factory->factory($args);
     $this->assertInstanceOf($expectedClassName, $service);
     $reflection = new \ReflectionClass($expectedClassName);
     $prop = $reflection->getProperty($propertyToCheck);
     $prop->setAccessible(true);
     $value = $prop->getValue($service);
     $this->assertRegExp('#/123456/?$#', $value);
 }