public function run()
 {
     try {
         $this->options->parse();
     } catch (\Exception $e) {
         $this->_handleException($e, false);
         $this->_showLine($this->options->getUsage());
         $this->_exit();
     }
     $configFile = $this->options->getConfigFile();
     if (!\file_exists($configFile) || !\is_readable($configFile)) {
         $this->_showError(sprintf("File '%s' cannot be found or not readable", $configFile));
     }
     $config = (require $configFile);
     if (!is_array($config)) {
         $this->_showError(sprintf("Invalid config file '%s'", $configFile));
     }
     $this->_showInfo(sprintf("Loaded config file '%s' ...", $configFile));
     $perunClientFactory = new PerunClient\ClientFactory();
     $perunClient = $perunClientFactory->createClient($config);
     $managerName = $this->options->getManagerName();
     $functionName = $this->options->getFunctionName();
     $arguments = $this->options->getArguments();
     $this->_showInfo(sprintf("Calling %s->%s (%s)", $managerName, $functionName, http_build_query($arguments, null, ', ')));
     $startTime = time();
     $response = $perunClient->sendRequest($managerName, $functionName, $arguments);
     $endTime = time();
     $this->_showInfo(sprintf("Time: %d second(s)", $endTime - $startTime));
     if ($response->isError()) {
         $this->_showError(sprintf("Perun error [%s]: [%s/%s] %s", $response->getErrorId(), $response->getErrorName(), $response->getErrorType(), $response->getErrorMessage()));
     }
     $data = $this->_processResultData($response->getPayload()->getParams(), $this->options->getFilter());
     if ($this->options->getOption('entity')) {
         $entityFactory = new GenericFactory();
         $entity = $entityFactory->create($data);
         print_r($entity);
     } else {
         print_r($data);
     }
     $this->_showInfo('Result OK');
     $this->_exit(0);
 }
 public function testCreateEntityCollection()
 {
     $data = array(array('id' => 123, 'beanName' => 'Group'), array('id' => 456, 'beanName' => 'Group'));
     $entityMappings = array('Group' => 'InoPerunApi\\Entity\\Group');
     $collectionMappings = array('Group' => 'InoPerunApi\\Entity\\Collection\\GroupCollection');
     $this->factory->setBeanToEntityClassMappings($entityMappings);
     $this->factory->setBeanToCollectionClassMappings($collectionMappings);
     $collection = $this->factory->createEntityCollection($data);
     $this->assertInstanceOf('InoPerunApi\\Entity\\Collection\\GroupCollection', $collection);
     $this->assertSame(count($data), $collection->count());
     foreach ($collection as $entity) {
         $this->assertInstanceOf('InoPerunApi\\Entity\\Group', $entity);
     }
 }