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(); }