Example #1
0
 /**
  * test only for cover Application::getConfig and Command::initialize
  */
 public function testWithoutAnyMock()
 {
     $app = new Application();
     $command = $app->find('torrent-list');
     $commandTester = new CommandTester($command);
     $result = $commandTester->execute(['command' => 'torrent-list', '--config' => 'a/b/c/nonexists']);
     $this->assertEquals(1, $result);
 }
 public function testGetVersion()
 {
     $app = new Application();
     $app->setAutoExit(false);
     $input = new ArrayInput(array('--version'));
     $stream = fopen('php://memory', 'w', false);
     $output = new StreamOutput($stream);
     $app->run($input, $output);
     rewind($stream);
     $string = trim(fgets($stream));
     $string = preg_replace(array('/\\x1b(\\[|\\(|\\))[;?0-9]*[0-9A-Za-z]/', '/\\x1b(\\[|\\(|\\))[;?0-9]*[0-9A-Za-z]/', '/[\\x03|\\x1a]/'), array('', '', ''), $string);
     $this->assertEquals('Transmission CLI (repo)', $string);
     $app->setVersion('1.2.3');
     rewind($stream);
     $app->run($input, $output);
     rewind($stream);
     $string = trim(fgets($stream));
     $string = preg_replace(array('/\\x1b(\\[|\\(|\\))[;?0-9]*[0-9A-Za-z]/', '/\\x1b(\\[|\\(|\\))[;?0-9]*[0-9A-Za-z]/', '/[\\x03|\\x1a]/'), array('', '', ''), $string);
     $this->assertEquals('Transmission CLI version 1.2.3 build @git-commit@', $string);
 }
 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();
 }