Skip to content

A free open source IT asset/license management system

1.9 KB
Raw Blame
<?php

declare(strict_types=1);

namespace Tests\Support\Importing;

use Illuminate\Support\Str;

/**
 * Build a components import file at runtime for testing.
 *
 * @template Row of array{
 *  category?: string,
 *  companyName?: string,
 *  itemName?: string,
 *  location?: string,
 *  notes?: string,
 *  orderNumber?: string,
 *  purchaseCost?: int,
 *  purchaseDate?: string,
 *  quantity?: int,
 *  serialNumber?: string,
 * }
 *
 * @extends FileBuilder<Row>
 */
class ComponentsImportFileBuilder extends FileBuilder
{
    /**
     * {@inheritdoc}
     */
    protected function getDictionary(): array
    {
        return [
            'assetTag' => 'Asset Tag',
            'category' => 'Category',
            'companyName' => 'Company',
            'itemName' => 'item Name',
            'location' => 'Location',
            'notes' => 'Notes',
            'orderNumber' => 'Order Number',
            'purchaseCost' => 'Purchase Cost',
            'purchaseDate' => 'Purchase Date',
            'quantity' => 'Quantity',
            'serialNumber' => 'Serial number',
            'requestable' => 'Requestable',
            'archived' => 'Archived',
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function definition(): array
    {
        $faker = fake();

        return [
            'assetTag' => '',
            'category' => Str::random(),
            'companyName' => Str::random()." {$faker->companySuffix}",
            'itemName' => Str::random(),
            'location' => "{$faker->city}, {$faker->country}",
            'notes' => $faker->sentence(),
            'orderNumber' => "ON:COM:{$faker->uuid}",
            'purchaseCost' => rand(1, 100_000),
            'purchaseDate' => $faker->date,
            'quantity' => rand(1, 100_000),
            'serialNumber' => 'SN:COM:'.Str::random(),
            'requestable' => '',
            'archived' => '',
        ];
    }
}