public function setUp()
 {
     $this->setCommandName('weburg-series-add');
     parent::setUp();
     $this->configFile = tempnam(sys_get_temp_dir(), 'config');
     $config = new Config($this->configFile);
     $config->saveConfigFile();
     $this->app->setConfig($config);
 }
 public function testDefaultConfigWriteOnAppStart()
 {
     $configFile = Config::getHomeDir() . '/.transmission-cli.yml';
     if (file_exists($configFile)) {
         unlink($configFile);
     }
     $this->executeCommand();
     $this->assertFileExists($configFile);
 }
 public function setUp()
 {
     $this->setCommandName('weburg-download');
     parent::setUp();
     $this->dest = sys_get_temp_dir() . '/transmission-cli-torrents';
     if (!file_exists($this->dest)) {
         mkdir($this->dest);
     }
     $config = new Config();
     $config->set('download-torrents-dir', $this->dest);
     $config->set('weburg-series-list', [1, 2, 3]);
     $this->app->setConfig($config);
     $httpClient = $this->getMock('GuzzleHttp\\ClientInterface');
     $client = $this->getMock('Popstas\\Transmission\\Console\\WeburgClient', [], [$httpClient]);
     $client->method('getMoviesIds')->will($this->returnValue([1, 2, 3]));
     $client->method('getMovieTorrentUrlsById')->will($this->returnValue(['http://torrent-url']));
     $client->method('getSeriesTorrents')->willReturn(['torrent-url']);
     $client->method('getMovieInfoById')->willReturn(['title' => 'movie', 'comments' => 123, 'rating_imdb' => null]);
     $this->app->setWeburgClient($client);
 }
Exemple #4
0
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     // logger
     $logger = $this->getApplication()->getLogger();
     if (!isset($logger)) {
         $verbosityLevelMap = [LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL, LogLevel::INFO => OutputInterface::VERBOSITY_VERBOSE, LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG];
         $logger = new ConsoleLogger($output, $verbosityLevelMap);
         $this->getApplication()->setLogger($logger);
     }
     // config
     $config = $this->getApplication()->getConfig();
     if (!isset($config)) {
         $config = new Config($input->getOption('config'));
         try {
             $config->loadConfigFile();
         } catch (\RuntimeException $e) {
             $logger->critical($e->getMessage());
             $this->setCode(function () {
                 return 1;
             });
             return;
         }
         $this->getApplication()->setConfig($config);
     }
     // compatibility: first client available at old config names
     // this overrides config values to options from command line arguments
     $firstTransmission = $config->get('transmission')[0];
     $vars = ['host', 'port', 'user', 'password'];
     foreach ($vars as $var) {
         $configName = 'transmission-' . $var;
         $config->set($configName, $this->getInputOption($input, $configName, $firstTransmission[$var]));
     }
     // client
     $client = $this->getApplication()->getClient();
     if (!isset($client)) {
         $client = $this->createTransmissionClient($config->get('transmission-host'), $config->get('transmission-port'), $config->get('transmission-user'), $config->get('transmission-password'));
         $this->getApplication()->setClient($client);
     }
     $logger->info('[{date}] command: {args}', ['date' => date('Y-m-d H:i:s'), 'args' => implode(' ', array_slice($_SERVER['argv'], 1))]);
     parent::initialize($input, $output);
 }
 public function setUp()
 {
     $this->app = new Application();
     // logger
     $this->logger = $this->getMock('\\Psr\\Log\\LoggerInterface');
     $this->app->setLogger($this->logger);
     // config
     $homeDir = sys_get_temp_dir();
     $this->configFile = tempnam($homeDir, 'transmission-cli.yml');
     if (file_exists($this->configFile)) {
         unlink($this->configFile);
     }
     putenv('HOME=' . $homeDir);
     $config = new Config();
     $config->saveConfigFile();
     // TransmissionClient
     $httpClient = $this->getMock('GuzzleHttp\\ClientInterface');
     $api = $this->getMock('Martial\\Transmission\\API\\RpcClient', [], [$httpClient, '', '']);
     $client = $this->getMock('Popstas\\Transmission\\Console\\TransmissionClient', [], [$api]);
     $client->method('getTorrentData')->will($this->returnValue($this->expectedTorrentList));
     $this->app->setClient($client);
     // InfluxDbClient
     $influxDb = $this->getMockBuilder('InfluxDB\\Client')->setMethods([])->setConstructorArgs([''])->disableOriginalConstructor()->getMock();
     $influxDbClient = new InfluxDbClient($influxDb, 'dbname');
     $database = $this->getMock('InfluxDB\\Database', [], ['dbname', $influxDb]);
     $queryBuilder = $this->getMock('InfluxDB\\Query\\Builder', ['getResultSet'], [$database]);
     $resultSet = $this->getMockBuilder('InfluxDB\\ResultSet')->setMethods([])->setConstructorArgs([''])->disableOriginalConstructor()->getMock();
     $resultSet->method('getPoints')->willReturn([]);
     $queryBuilder->method('getResultSet')->will($this->returnValue($resultSet));
     $database->method('getQueryBuilder')->willReturn($queryBuilder);
     $influxDbClient->setDatabase($database);
     $this->app->setInfluxDbClient($influxDbClient);
     $this->command = $this->app->find($this->commandName);
     $this->commandTester = new CommandTester($this->command);
     parent::setUp();
 }
 public function testCreateTransmissionClientSuccess()
 {
     $this->setCommandName('weburg-download');
     parent::setUp();
     $this->app->setClient(null);
     $config = new Config();
     $config->set('transmission-host', 'devnull');
     $config->set('transmission-port', 1234);
     $config->set('transmission-user', 'user');
     $config->set('transmission-password', 'pass');
     $config->set('dest', '');
     $this->app->setConfig($config);
     $result = $this->executeCommand();
     $this->assertEquals(1, $result);
     $this->assertRegExp('/Destination directory not defined/', $this->getDisplay());
 }
 public function setUp()
 {
     $this->setCommandName('stats-get');
     parent::setUp();
     $config = new Config();
     $config->set('influxdb-host', 'devnull');
     $config->set('influxdb-port', 1234);
     $config->set('influxdb-user', 'user');
     $config->set('influxdb-password', 'pass');
     $this->app->setConfig($config);
     $this->influxDb = $this->getMockBuilder('InfluxDB\\Client')->setMethods([])->setConstructorArgs([''])->disableOriginalConstructor()->getMock();
     $this->influxDbClient = $this->getMock('Popstas\\Transmission\\Console\\InfluxDbClient', [], [$this->influxDb, 'test']);
     $this->database = $this->getMock('InfluxDB\\Database', [], ['dbname', $this->influxDb]);
     $this->database->method('exists')->will($this->returnValue(true));
     $this->influxDb->method('selectDB')->will($this->returnValue($this->database));
     $this->app->setInfluxDbClient($this->influxDbClient);
 }
 public function testGetHomeDir()
 {
     $home = getenv('HOME');
     putenv('HOME=/home/user');
     $this->assertEquals('/home/user', Config::getHomeDir());
     putenv('HOME=');
     $_SERVER['HOMEDRIVE'] = 'c:';
     $_SERVER['HOMEPATH'] = '\\server\\directory\\';
     $this->assertEquals('c:\\server\\directory', Config::getHomeDir());
     putenv('HOME=' . $home);
 }