/**
  * Test json serialization
  */
 public function testJsonSerialize()
 {
     $entity = new RamUsageStatEntity();
     $this->assertTrue(is_array($entity->jsonSerialize()));
     $this->assertNotEmpty($entity->jsonSerialize());
     $json = json_encode($entity);
     $this->assertEmpty(json_last_error());
     $this->assertTrue(is_string($json));
     $this->assertNotEmpty($json);
     $this->assertContains('freeSize', $json);
 }
Beispiel #2
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;
 }