include missing
This commit is contained in:
parent
88b5850c32
commit
d3e12785bb
20 changed files with 584 additions and 4 deletions
16
tests/Classes/ArrayDataObject.php
Normal file
16
tests/Classes/ArrayDataObject.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Classes;
|
||||
|
||||
use Icefox\DTO\DataObject;
|
||||
|
||||
readonly class ArrayDataObject
|
||||
{
|
||||
use DataObject;
|
||||
/**
|
||||
* @param array<int,int> $values
|
||||
*/
|
||||
public function __construct(public array $values) {}
|
||||
}
|
||||
22
tests/Classes/CarbonPeriodMapper.php
Normal file
22
tests/Classes/CarbonPeriodMapper.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Classes;
|
||||
|
||||
use Carbon\CarbonPeriodImmutable;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class CarbonPeriodMapper
|
||||
{
|
||||
public function map(mixed $value): CarbonPeriodImmutable
|
||||
{
|
||||
return new CarbonPeriodImmutable(Carbon::parse($value['start']), Carbon::parse($value['end']));
|
||||
}
|
||||
|
||||
public static function rules(): array
|
||||
{
|
||||
return [
|
||||
'start' => ['required', 'date'],
|
||||
'end' => ['required', 'date'],
|
||||
];
|
||||
}
|
||||
}
|
||||
17
tests/Classes/CollectionDataObject.php
Normal file
17
tests/Classes/CollectionDataObject.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Classes;
|
||||
|
||||
use Icefox\DTO\DataObject;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
readonly class CollectionDataObject
|
||||
{
|
||||
use DataObject;
|
||||
/**
|
||||
* @param Collection<OptionalNullableData> $values
|
||||
*/
|
||||
public function __construct(public Collection $values) {}
|
||||
}
|
||||
19
tests/Classes/FromInputObject.php
Normal file
19
tests/Classes/FromInputObject.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Classes;
|
||||
|
||||
use Icefox\DTO\Attributes\FromInput;
|
||||
use Icefox\DTO\DataObject;
|
||||
|
||||
readonly class FromInputObject
|
||||
{
|
||||
use DataObject;
|
||||
|
||||
public function __construct(
|
||||
#[FromInput('other_name')]
|
||||
public string $text,
|
||||
public int $standard,
|
||||
) {}
|
||||
}
|
||||
17
tests/Classes/ObjectWithoutMapper.php
Normal file
17
tests/Classes/ObjectWithoutMapper.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Classes;
|
||||
|
||||
use Icefox\DTO\DataObject;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
readonly class ObjectWithoutMapper
|
||||
{
|
||||
use DataObject;
|
||||
|
||||
public function __construct(
|
||||
public Carbon $date,
|
||||
) {}
|
||||
}
|
||||
19
tests/Classes/OptionalData.php
Normal file
19
tests/Classes/OptionalData.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Classes;
|
||||
|
||||
use Icefox\DTO\DataObject;
|
||||
|
||||
readonly class OptionalData
|
||||
{
|
||||
use DataObject;
|
||||
|
||||
public function __construct(
|
||||
public string $string = 'xyz',
|
||||
public float $float = 0.777,
|
||||
public int $int = 3,
|
||||
public bool $bool = false,
|
||||
) {}
|
||||
}
|
||||
19
tests/Classes/OptionalNullableData.php
Normal file
19
tests/Classes/OptionalNullableData.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Classes;
|
||||
|
||||
use Icefox\DTO\DataObject;
|
||||
|
||||
readonly class OptionalNullableData
|
||||
{
|
||||
use DataObject;
|
||||
|
||||
public function __construct(
|
||||
public string $string,
|
||||
public ?int $int,
|
||||
public float $float = 0.999,
|
||||
public bool $bool = false,
|
||||
) {}
|
||||
}
|
||||
19
tests/Classes/PrimitiveData.php
Normal file
19
tests/Classes/PrimitiveData.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Classes;
|
||||
|
||||
use Icefox\DTO\DataObject;
|
||||
|
||||
readonly class PrimitiveData
|
||||
{
|
||||
use DataObject;
|
||||
|
||||
public function __construct(
|
||||
public string $string,
|
||||
public int $int,
|
||||
public float $float,
|
||||
public bool $bool,
|
||||
) {}
|
||||
}
|
||||
17
tests/Classes/RecursiveDataObject.php
Normal file
17
tests/Classes/RecursiveDataObject.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Classes;
|
||||
|
||||
use Icefox\DTO\DataObject;
|
||||
|
||||
readonly class RecursiveDataObject
|
||||
{
|
||||
use DataObject;
|
||||
|
||||
public function __construct(
|
||||
public string $string,
|
||||
public PrimitiveData $extra,
|
||||
) {}
|
||||
}
|
||||
19
tests/Classes/WithMapperObject.php
Normal file
19
tests/Classes/WithMapperObject.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Classes;
|
||||
|
||||
use Carbon\CarbonPeriodImmutable;
|
||||
use Icefox\DTO\Attributes\FromMapper;
|
||||
use Icefox\DTO\DataObject;
|
||||
|
||||
readonly class WithMapperObject
|
||||
{
|
||||
use DataObject;
|
||||
|
||||
public function __construct(
|
||||
#[FromMapper(CarbonPeriodMapper::class)]
|
||||
public CarbonPeriodImmutable $period,
|
||||
) {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue