<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digital-creative / fakeable-data-transfer-object example snippets
use DigitalCreative\FakeableDataTransferObject\DataTransferObject;
class SomeObject extends DataTransferObject
{
public string $name;
public int $age;
}
$dto1 = SomeObject::fake();
$dto2 = SomeObject::fake(age: 18);
echo $dto1->name; // random word
echo $dto1->age; // random int
echo $dto2->name; // random word
echo $dto2->age; // 18
namespace App\Providers;
use BenSampo\Enum\Enum;
use DigitalCreative\FakeableDataTransferObject\FakerRegistrar;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
FakerRegistrar::register(Enum::class, function (string $class, mixed $value = null) {
return blank($value) ? $class::getRandomInstance() : $class::fromValue($value);
});
FakerRegistrar::register(UploadedFile::class, function (string $class, mixed $value = null) {
/** @var UploadedFile $class */
return blank($value) ? $class::fake()->create('file.png') : $value;
});
}
}
use DigitalCreative\FakeableDataTransferObject\DataTransferObject;
class SomeObject extends DataTransferObject
{
public GenderEnum $gender;
public UploadedFile $attachment;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.