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