Laravel Hetzner Storagebox

PHP MIT

Production-ready Laravel package for integrating Hetzner Storage Box into Laravel applications using the native Storage facade and filesystem API.

Stars
19
Forks
0
Downloads
2,357
Open Issues
0
Files main

Repository Files

Loading file structure...
tests/Unit/DTOTest.php
<?php

namespace GhostCompiler\Hetzner\StorageBox\Tests\Unit;

use GhostCompiler\Hetzner\StorageBox\DTOs\Action;
use GhostCompiler\Hetzner\StorageBox\DTOs\Location;
use GhostCompiler\Hetzner\StorageBox\DTOs\PaginationMeta;
use GhostCompiler\Hetzner\StorageBox\DTOs\StorageBox;
use GhostCompiler\Hetzner\StorageBox\DTOs\StorageBoxType;
use GhostCompiler\Hetzner\StorageBox\Tests\TestCase;

class DTOTest extends TestCase
{
    public function test_storage_box_dto_hydration()
    {
        $data = [
            'id' => 123,
            'username' => 'sb123',
            'status' => 'active',
            'name' => 'my-box',
            'storage_box_type' => ['name' => 'bx11'],
            'location' => ['name' => 'nbg1'],
            'access_settings' => ['ssh_enabled' => true],
            'server' => 'box.example.com',
            'system' => 'linux',
            'stats' => ['size' => 100],
            'labels' => ['env' => 'prod'],
            'protection' => ['delete' => false],
            'snapshot_plan' => ['max_snapshots' => 5],
            'created' => '2026-06-11T12:00:00Z',
        ];

        $box = StorageBox::fromArray($data);

        $this->assertEquals(123, $box->id);
        $this->assertEquals('sb123', $box->username);
        $this->assertEquals('active', $box->status);
        $this->assertEquals('my-box', $box->name);
        $this->assertEquals(['name' => 'bx11'], $box->storageBoxType);
        $this->assertEquals(['name' => 'nbg1'], $box->location);
        $this->assertEquals(['ssh_enabled' => true], $box->accessSettings);
        $this->assertEquals('box.example.com', $box->server);
        $this->assertEquals('linux', $box->system);
        $this->assertEquals(['size' => 100], $box->stats);
        $this->assertEquals(['env' => 'prod'], $box->labels);
        $this->assertEquals(['delete' => false], $box->protection);
        $this->assertEquals(['max_snapshots' => 5], $box->snapshotPlan);
        $this->assertEquals('2026-06-11T12:00:00Z', $box->created);
    }

    public function test_storage_box_type_dto_hydration()
    {
        $data = [
            'id' => 4,
            'name' => 'bx11',
            'description' => 'BX11 Storage Box',
            'subaccount_limit' => 10,
            'snapshot_limit' => 5,
            'prices' => [['price' => 2.99]],
        ];

        $type = StorageBoxType::fromArray($data);

        $this->assertEquals(4, $type->id);
        $this->assertEquals('bx11', $type->name);
        $this->assertEquals('BX11 Storage Box', $type->description);
        $this->assertEquals(10, $type->subaccountLimit);
        $this->assertEquals(5, $type->snapshotLimit);
        $this->assertEquals([['price' => 2.99]], $type->prices);
    }

    public function test_location_dto_hydration()
    {
        $data = [
            'id' => 1,
            'name' => 'fsn1',
            'description' => 'Falkenstein',
            'country' => 'DE',
            'city' => 'Falkenstein',
            'latitude' => 50.4,
            'longitude' => 12.3,
            'network_zone' => 'eu-central',
        ];

        $loc = Location::fromArray($data);

        $this->assertEquals(1, $loc->id);
        $this->assertEquals('DE', $loc->country);
    }

    public function test_action_dto_hydration()
    {
        $data = [
            'id' => 12,
            'command' => 'change_protection',
            'status' => 'success',
            'progress' => 100,
            'started' => '2026-06-11T12:00:00Z',
            'finished' => '2026-06-11T12:01:00Z',
            'resources' => [['id' => 1, 'type' => 'storage_box']],
            'error' => null,
        ];

        $action = Action::fromArray($data);

        $this->assertEquals(12, $action->id);
        $this->assertEquals('change_protection', $action->command);
        $this->assertEquals('success', $action->status);
    }

    public function test_pagination_meta_dto_hydration()
    {
        $data = [
            'page' => 2,
            'per_page' => 25,
            'previous_page' => 1,
            'next_page' => 3,
            'last_page' => 4,
            'total_entries' => 100,
        ];

        $meta = PaginationMeta::fromArray($data);

        $this->assertEquals(2, $meta->page);
        $this->assertEquals(25, $meta->perPage);
    }
}