public function testGetTorrentSum() { $database = $this->getDatabaseMockReturnsResultSet([['uploaded_last' => 123]]); $this->client->setDatabase($database); $this->assertEquals(123, $this->client->getTorrentSum($this->expectedTorrentList[0], 'uploaded_last', 'localhost', 7)); $database = $this->getDatabaseMockReturnsResultSet([]); $this->client->setDatabase($database); $this->assertEquals(0, $this->client->getTorrentSum($this->expectedTorrentList[0], 'uploaded_last', 'localhost', 7)); }
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(); }
/** * @param $host * @param $port * @param $user * @param $password * @param $databaseName * @return InfluxDbClient * @throws InfluxDB\Database\Exception */ public function createInfluxDbClient($host, $port, $user, $password, $databaseName) { $influxDb = new InfluxDB\Client($host, $port, $user, $password); $connect = ['host' => $host, 'port' => $port, 'user' => $user, 'password' => $password]; $this->logger->debug('Connect InfluxDB using: {user}:{password}@{host}:{port}', $connect); if (!$databaseName) { throw new \RuntimeException('InfluxDb database not defined'); } $influxDbClient = new InfluxDbClient($influxDb, $databaseName); $influxDbClient->setLogger($this->logger); return $influxDbClient; }
public function testDryRun() { $this->influxDbClient->expects($this->never())->method('writePoints'); $this->executeCommand(['--dry-run' => true]); }