/** * @test */ public function shouldBeTrueWhenZeroBytes() { $this->assertTrue(Bytes::allocateUnits(0)->hasZeroBytes()); $this->assertTrue(KiloBytes::allocateUnits(0)->hasZeroBytes()); $this->assertTrue(MegaBytes::allocateUnits(0)->hasZeroBytes()); $this->assertTrue(GigaBytes::allocateUnits(0)->hasZeroBytes()); $this->assertTrue(TeraBytes::allocateUnits(0)->hasZeroBytes()); }
/** * @param string $userName * @return integer */ public function byUsername($userName) { $view = new FilesView('/' . $userName . '/files'); $freeSpace = (int) $view->free_space(); $fileInfo = $view->getFileInfo('/'); Assertion::notEmpty($fileInfo); $usedSpace = $fileInfo->getSize(); return KiloBytes::allocateUnits($freeSpace + $usedSpace)->units(); }
/** * @test */ public function shouldIterate() { $collection = $this->createCollection([TeraBytes::allocateUnits(1), GigaBytes::allocateUnits(1), MegaBytes::allocateUnits(1), KiloBytes::allocateUnits(1), Bytes::allocateUnits(1)]); $i = 0; foreach ($collection as $key => $bytes) { $this->assertSame($i, $key); $this->assertInstanceOf(Bytes::class, $bytes); $i++; } $this->assertSame(5, $i); }
/** * @param string $userName * @return integer */ public function byUsername($userName) { $data = new Home(array('user' => \OC_User::getManager()->get($userName))); return KiloBytes::allocateUnits($data->getCache('files')->calculateFolderSize('files'))->units(); }
public function listOfAddingUnits() { return [[KiloBytes::allocateUnits(1), KiloBytes::allocateUnits(1), KiloBytes::allocateUnits(2)], [MegaBytes::allocateUnits(1), MegaBytes::allocateUnits(1), MegaBytes::allocateUnits(2)], [GigaBytes::allocateUnits(1), GigaBytes::allocateUnits(1), GigaBytes::allocateUnits(2)], [TeraBytes::allocateUnits(1), TeraBytes::allocateUnits(1), TeraBytes::allocateUnits(2)], [Bytes::allocateUnits(1), KiloBytes::allocateUnits(1), Bytes::allocateUnits(1025)], [KiloBytes::allocateUnits(1), MegaBytes::allocateUnits(1), KiloBytes::allocateUnits(1025)], [MegaBytes::allocateUnits(1), GigaBytes::allocateUnits(1), MegaBytes::allocateUnits(1025)], [GigaBytes::allocateUnits(1), TeraBytes::allocateUnits(1), GigaBytes::allocateUnits(1025)]]; }
/** * @test */ public function shouldConvertKiloBytesToMegaBytes() { $bytes = KiloBytes::allocateUnits(1 * 1024); $this->assertEquals($bytes->megaBytes()->units(), 1); }
/** * @param Bytes $bytes * @return Bytes */ private static function findLargestUnitOfMeasurementPossible(Bytes $bytes) { $tb = TeraBytes::allocateBytes($bytes); if (!$tb->hasZeroBytes()) { return $tb; } $gb = GigaBytes::allocateBytes($bytes); if (!$gb->hasZeroBytes()) { return $gb; } $mb = MegaBytes::allocateBytes($bytes); if (!$mb->hasZeroBytes()) { return $mb; } $kb = KiloBytes::allocateBytes($bytes); if (!$kb->hasZeroBytes()) { return $kb; } return Bytes::allocateBytes($bytes); }