/**
  * @param AddStorage $addStorage
  */
 public function add(AddStorage $addStorage)
 {
     Assertion::integer($addStorage->storage);
     Assertion::integer($addStorage->quota);
     $storage = Storage::withUserDateUsageQuota(User::named($addStorage->name), new \DateTime(), Bytes::allocateUnits((int) $addStorage->storage), Quota::fromBytes(Bytes::allocateUnits((int) $addStorage->quota)));
     $this->storageRepository->add($storage);
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function shouldReturnDateSeparatelyOnJsonSerialize()
 {
     $dateTime = new \DateTime("2015-12-31 23:50:01");
     $storage = Storage::withUserDateUsageQuota(User::named('username'), $dateTime, Bytes::allocateUnits(0), Quota::fromBytes(Bytes::allocateUnits(1)));
     $serializedStorage = $storage->jsonSerialize();
     $this->assertSame('2015', $serializedStorage['year']);
     $this->assertSame('12', $serializedStorage['month']);
     $this->assertSame('31', $serializedStorage['day']);
     $this->assertSame('23', $serializedStorage['hour']);
     $this->assertSame('50', $serializedStorage['minute']);
 }
 /**
  * @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);
 }
Ejemplo n.º 4
0
 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)]];
 }
Ejemplo n.º 5
0
 /**
  * @test
  */
 public function shouldConvertBytesToTeraBytes()
 {
     $bytes = Bytes::allocateUnits(1 * 1024 * 1024 * 1024 * 1024);
     $this->assertEquals($bytes->teraBytes()->units(), 1);
 }
 /**
  * @param array $row
  * @param string $unitOfMeasurement
  * @return Storage
  */
 private function mapStorageUsageRowToStorage($row, $unitOfMeasurement = 'b')
 {
     $bytes = Bytes::allocateUnits((int) $row['usage']);
     switch ($unitOfMeasurement) {
         case 'gb':
             $bytes = $bytes->gigaBytes();
             break;
         case 'mb':
             $bytes = $bytes->megaBytes();
             break;
         case 'kb':
             $bytes = $bytes->kiloBytes();
             break;
     }
     return Storage::withUserDateUsageQuota(User::named($row['username']), \DateTime::createFromFormat("Y-m-d H:i:s", $row['created']), $bytes, Quota::fromBytes(Bytes::allocateUnits((int) $row['maximumusage'])));
 }
Ejemplo n.º 7
0
 /**
  * @test
  */
 public function shouldReturnNumberOfBytesWhenUnitIsCalledFromByteClass()
 {
     $bytes = Bytes::allocateUnits(1);
     $this->assertSame(1, $bytes->units());
 }
Ejemplo n.º 8
0
 /**
  * @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);
 }
 /**
  * @param StorageCollection $collection
  * @param string $username
  */
 private function addStorageToCollection(StorageCollection $collection, $username)
 {
     $collection->add(Storage::withUserDateUsageQuota(User::named($username), new \DateTime("2015-12-31 23:50:01"), Bytes::allocateUnits(0), Quota::fromBytes(Bytes::allocateUnits(1))));
 }