/**
  * @dataProvider goodDataProvider
  *
  * @param array $testData
  */
 public function testProperties(array $testData)
 {
     $entity = new DiskUsageStatEntity();
     $mountPoints = [];
     foreach ($testData as $mountPointData) {
         $mountPoint = new DiskUsageMountEntity();
         $mountPoint->setMountPoint($mountPointData[0])->setUsagePercent($mountPointData[1])->setTotalSize($mountPointData[2])->setUsedSize($mountPointData[3])->setFreeSize($mountPointData[4]);
         $mountPoints[] = $mountPoint;
     }
     $this->assertTrue(is_array($entity->getMountPoints()));
     $this->assertEmpty($entity->getMountPoints());
     $this->assertSame($entity, $entity->setMountPoints($mountPoints));
     $this->assertSame($mountPoints, $entity->getMountPoints());
     foreach ($entity->getMountPoints() as $mountPoint) {
         $this->assertSame($mountPoint, $entity->getMountPointByLocation($mountPoint->getMountPoint()));
     }
     $this->assertFalse($entity->getMountPointByLocation('/tmp'));
     $this->assertEquals(6, $entity->getUsagePercent());
     $this->assertEquals($testData[0][2] + $testData[1][2] + $testData[2][2], $entity->getTotalSize());
     $this->assertEquals($testData[0][3] + $testData[1][3] + $testData[2][3], $entity->getUsedSize());
     $this->assertEquals($testData[0][4] + $testData[1][4] + $testData[2][4], $entity->getFreeSize());
     $this->assertTrue(is_array($entity->jsonSerialize()));
     $this->assertNotEmpty($entity->jsonSerialize());
     $serverJson = json_encode($entity);
     $this->assertEmpty(json_last_error());
     $this->assertTrue(is_string($serverJson));
     $this->assertNotEmpty($serverJson);
     $this->assertContains('mountPoints', $serverJson);
 }
 /**
  * Test all methods
  * @dataProvider goodDataProvider
  *
  * @param array $testData
  */
 public function testProperties(array $testData)
 {
     /** @var AbstractServerStatsEntity $entity */
     $entity = $this->getMockForAbstractClass(AbstractServerStatsEntity::class);
     $this->assertTrue(is_array($entity->__toArray()));
     $mountEntity = new DiskUsageMountEntity();
     $mountEntity->setMountPoint($testData[1]);
     $diskStat = new DiskUsageStatEntity();
     $diskStat->addMountPoint($mountEntity);
     $ramStat = new RamUsageStatEntity();
     $this->assertSame($entity, $entity->setCPULoadAverage($testData[0]));
     $this->assertSame($entity, $entity->setDiskUsage($diskStat));
     $this->assertSame($entity, $entity->setRamUsage($ramStat));
     $this->assertEquals($testData[0], $entity->getCPULoadAverage());
     $this->assertEquals($diskStat, $entity->getDiskUsage());
     $this->assertEquals($ramStat, $entity->getRamUsage());
     $this->assertTrue(is_array($entity->__toArray()));
     $this->assertNotEmpty($entity->__toArray());
     $this->assertCount(3, $entity->__toArray());
 }
Example #3
0
 /**
  * @param int $id
  *
  * @return VirtualServerStatsEntity
  */
 private function getVirtualServerStatsById($id)
 {
     $response = $this->makeRequest(sprintf('virtual-servers/get_stats?id=%d&_dc=%s', $id, time()), 'json');
     $diskUsageStat = new DiskUsageStatEntity();
     $stats = new VirtualServerStatsEntity();
     $stats->setDiskUsage($diskUsageStat);
     foreach ($response->data as $property) {
         switch ($property->parameter) {
             case 'CPU load average':
                 if ($property->value !== '-') {
                     $stats->setCPULoadAverage([(double) $property->value->percent]);
                 }
                 break;
             case 'Disk usage':
                 if ($property->value !== '-') {
                     $stat = MemoryParser::parse($property->value->text);
                     $diskMount = new DiskUsageMountEntity();
                     $diskMount->setMountPoint('/')->setUsagePercent($stat['percent'])->setTotalSize($stat['total'])->setFreeSize($stat['free'])->setUsedSize($stat['used']);
                     $diskUsageStat->addMountPoint($diskMount);
                 }
                 break;
             case 'Memory usage':
                 if ($property->value !== '-') {
                     $stat = MemoryParser::parse($property->value->text);
                     $ramUsage = new RamUsageStatEntity();
                     $ramUsage->setUsagePercent($stat['percent'])->setTotalSize($stat['total'])->setFreeSize($stat['free'])->setUsedSize($stat['used']);
                     $stats->setRamUsage($ramUsage);
                 }
                 break;
             default:
                 throw new InvalidArgumentException(sprintf('Unknown property "%s"'), $property->parameter);
         }
     }
     return $stats;
 }