Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche authored and github-actions[bot] committed Feb 10, 2023
1 parent b860a9d commit 4191674
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 45 deletions.
78 changes: 39 additions & 39 deletions tests/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
});

it('can include a lazy property', function () {
$data = new LazyData(Lazy::create(fn() => 'test'));
$data = new LazyData(Lazy::create(fn () => 'test'));

expect($data->toArray())->toBe([]);

Expand Down Expand Up @@ -121,8 +121,8 @@ public function __construct(


$data = new \TestIncludeableNestedLazyDataProperties(
Lazy::create(fn() => LazyData::from('Hello')),
Lazy::create(fn() => LazyData::collection(['is', 'it', 'me', 'your', 'looking', 'for',])),
Lazy::create(fn () => LazyData::from('Hello')),
Lazy::create(fn () => LazyData::collection(['is', 'it', 'me', 'your', 'looking', 'for',])),
);

expect((clone $data)->toArray())->toBe([]);
Expand Down Expand Up @@ -172,7 +172,7 @@ public function __construct(
}
}

$collection = Lazy::create(fn() => MultiLazyData::collection([
$collection = Lazy::create(fn () => MultiLazyData::collection([
DummyDto::rick(),
DummyDto::bon(),
]));
Expand Down Expand Up @@ -228,7 +228,7 @@ public function __construct(
public static function create(string $name): static
{
return new self(
Lazy::when(fn() => $name === 'Ruben', fn() => $name)
Lazy::when(fn () => $name === 'Ruben', fn () => $name)
);
}
};
Expand All @@ -252,7 +252,7 @@ public function __construct(
public static function create(string $name): static
{
return new self(
Lazy::when(fn() => $name === 'Ruben', fn() => $name)
Lazy::when(fn () => $name === 'Ruben', fn () => $name)
);
}
};
Expand Down Expand Up @@ -314,7 +314,7 @@ public function __construct(
public static function create(string $name): static
{
return new self(
Lazy::inertia(fn() => $name)
Lazy::inertia(fn () => $name)
);
}
};
Expand Down Expand Up @@ -544,7 +544,7 @@ public function __construct(
$data = new class (
$dataObject = new SimpleData('Test'),
$dataCollection = SimpleData::collection([new SimpleData('A'), new SimpleData('B')]),
Lazy::create(fn() => new SimpleData('Lazy')),
Lazy::create(fn () => new SimpleData('Lazy')),
'Test',
$transformable = new DateTime('16 may 1994')
) extends Data {
Expand Down Expand Up @@ -678,7 +678,7 @@ public function __construct(public string $name)

$transformed = $data->additional([
'company' => 'Spatie',
'alt_name' => fn(Data $data) => "{$data->name} from Spatie",
'alt_name' => fn (Data $data) => "{$data->name} from Spatie",
])->toArray();

expect($transformed)->toMatchArray([
Expand Down Expand Up @@ -960,7 +960,7 @@ public function __construct(
public Data $nestedData,
#[
WithTransformer(ConfidentialDataCollectionTransformer::class),
DataCollectionOf(SimpleData::class)
DataCollectionOf(SimpleData::class)
]
public DataCollection $nestedDataCollection,
) {
Expand Down Expand Up @@ -1154,7 +1154,7 @@ public function __construct(
});

it('will not include lazy optional values when transforming', function () {
$data = new class ('Hello World', Lazy::create(fn() => Optional::make())) extends Data {
$data = new class ('Hello World', Lazy::create(fn () => Optional::make())) extends Data {
public function __construct(
public string $string,
public string|Optional|Lazy $lazy_optional_string,
Expand Down Expand Up @@ -1212,7 +1212,7 @@ public function __construct(
public DataCollection $nested_collection,
#[
MapOutputName('nested_other_collection'),
DataCollectionOf(SimpleDataWithMappedProperty::class)
DataCollectionOf(SimpleDataWithMappedProperty::class)
]
public DataCollection $nested_renamed_collection,
) {
Expand Down Expand Up @@ -1352,7 +1352,7 @@ public static function fromData(Data $data)

expect(
MultiLazyData::from(DummyDto::rick())
->includeWhen('name', fn(MultiLazyData $data) => $data->artist->resolve() === 'Rick Astley')
->includeWhen('name', fn (MultiLazyData $data) => $data->artist->resolve() === 'Rick Astley')
->toArray()
)
->toMatchArray([
Expand All @@ -1377,7 +1377,7 @@ public static function fromData(Data $data)

it('can conditionally include using class defaults', function () {
PartialClassConditionalData::setDefinitions(includeDefinitions: [
'string' => fn(PartialClassConditionalData $data) => $data->enabled,
'string' => fn (PartialClassConditionalData $data) => $data->enabled,
]);

expect(PartialClassConditionalData::createLazy(enabled: false))
Expand All @@ -1391,7 +1391,7 @@ public static function fromData(Data $data)

it('can conditionally include using class defaults nested', function () {
PartialClassConditionalData::setDefinitions(includeDefinitions: [
'nested.string' => fn(PartialClassConditionalData $data) => $data->enabled,
'nested.string' => fn (PartialClassConditionalData $data) => $data->enabled,
]);

expect(PartialClassConditionalData::createLazy(enabled: true))
Expand All @@ -1401,8 +1401,8 @@ public static function fromData(Data $data)

it('can conditionally include using class defaults multiple', function () {
PartialClassConditionalData::setDefinitions(includeDefinitions: [
'nested.string' => fn(PartialClassConditionalData $data) => $data->enabled,
'string' => fn(PartialClassConditionalData $data) => $data->enabled,
'nested.string' => fn (PartialClassConditionalData $data) => $data->enabled,
'string' => fn (PartialClassConditionalData $data) => $data->enabled,
]);

expect(PartialClassConditionalData::createLazy(enabled: false))
Expand All @@ -1420,8 +1420,8 @@ public static function fromData(Data $data)

it('can conditionally exclude', function () {
$data = new MultiLazyData(
Lazy::create(fn() => 'Rick Astley')->defaultIncluded(),
Lazy::create(fn() => 'Never gonna give you up')->defaultIncluded(),
Lazy::create(fn () => 'Rick Astley')->defaultIncluded(),
Lazy::create(fn () => 'Never gonna give you up')->defaultIncluded(),
1989
);

Expand All @@ -1440,7 +1440,7 @@ public static function fromData(Data $data)

expect(
(clone $data)
->exceptWhen('name', fn(MultiLazyData $data) => $data->artist->resolve() === 'Rick Astley')
->exceptWhen('name', fn (MultiLazyData $data) => $data->artist->resolve() === 'Rick Astley')
->toArray()
)
->toMatchArray([
Expand All @@ -1454,7 +1454,7 @@ public static function fromData(Data $data)
public NestedLazyData $nested;
};

$data->nested = new NestedLazyData(Lazy::create(fn() => SimpleData::from('Hello World'))->defaultIncluded());
$data->nested = new NestedLazyData(Lazy::create(fn () => SimpleData::from('Hello World'))->defaultIncluded());

expect($data->toArray())->toMatchArray([
'nested' => ['simple' => ['string' => 'Hello World']],
Expand All @@ -1466,7 +1466,7 @@ public static function fromData(Data $data)

it('can conditionally exclude using class defaults', function () {
PartialClassConditionalData::setDefinitions(excludeDefinitions: [
'string' => fn(PartialClassConditionalData $data) => $data->enabled,
'string' => fn (PartialClassConditionalData $data) => $data->enabled,
]);

expect(PartialClassConditionalData::createDefaultIncluded(enabled: false))
Expand All @@ -1487,7 +1487,7 @@ public static function fromData(Data $data)

it('can conditionally exclude using class defaults nested', function () {
PartialClassConditionalData::setDefinitions(excludeDefinitions: [
'nested.string' => fn(PartialClassConditionalData $data) => $data->enabled,
'nested.string' => fn (PartialClassConditionalData $data) => $data->enabled,
]);

expect(PartialClassConditionalData::createDefaultIncluded(enabled: false))
Expand All @@ -1508,8 +1508,8 @@ public static function fromData(Data $data)

it('can conditionally exclude using multiple class defaults', function () {
PartialClassConditionalData::setDefinitions(excludeDefinitions: [
'string' => fn(PartialClassConditionalData $data) => $data->enabled,
'nested.string' => fn(PartialClassConditionalData $data) => $data->enabled,
'string' => fn (PartialClassConditionalData $data) => $data->enabled,
'nested.string' => fn (PartialClassConditionalData $data) => $data->enabled,
]);

expect(PartialClassConditionalData::createDefaultIncluded(enabled: false))
Expand Down Expand Up @@ -1545,15 +1545,15 @@ public static function fromData(Data $data)

expect(
(clone $data)
->onlyWhen('second', fn(MultiData $data) => $data->second === 'World')
->onlyWhen('second', fn (MultiData $data) => $data->second === 'World')
->toArray()
)
->toMatchArray(['second' => 'World']);

expect(
(clone $data)
->onlyWhen('first', fn(MultiData $data) => $data->first === 'Hello')
->onlyWhen('second', fn(MultiData $data) => $data->second === 'World')
->onlyWhen('first', fn (MultiData $data) => $data->first === 'Hello')
->onlyWhen('second', fn (MultiData $data) => $data->second === 'World')
->toArray()
)
->toMatchArray([
Expand Down Expand Up @@ -1587,7 +1587,7 @@ public static function fromData(Data $data)

it('can conditionally define only using class defaults', function () {
PartialClassConditionalData::setDefinitions(onlyDefinitions: [
'string' => fn(PartialClassConditionalData $data) => $data->enabled,
'string' => fn (PartialClassConditionalData $data) => $data->enabled,
]);

expect(PartialClassConditionalData::create(enabled: false))
Expand All @@ -1605,7 +1605,7 @@ public static function fromData(Data $data)

it('can conditionally define only using class defaults nested', function () {
PartialClassConditionalData::setDefinitions(onlyDefinitions: [
'nested.string' => fn(PartialClassConditionalData $data) => $data->enabled,
'nested.string' => fn (PartialClassConditionalData $data) => $data->enabled,
]);

expect(PartialClassConditionalData::create(enabled: false))
Expand All @@ -1625,8 +1625,8 @@ public static function fromData(Data $data)

it('can conditionally define only using multiple class defaults', function () {
PartialClassConditionalData::setDefinitions(onlyDefinitions: [
'string' => fn(PartialClassConditionalData $data) => $data->enabled,
'nested.string' => fn(PartialClassConditionalData $data) => $data->enabled,
'string' => fn (PartialClassConditionalData $data) => $data->enabled,
'nested.string' => fn (PartialClassConditionalData $data) => $data->enabled,
]);

expect(PartialClassConditionalData::create(enabled: false))
Expand Down Expand Up @@ -1661,7 +1661,7 @@ public static function fromData(Data $data)

expect(
(clone $data)
->exceptWhen('second', fn(MultiData $data) => $data->second === 'World')
->exceptWhen('second', fn (MultiData $data) => $data->second === 'World')
)
->toArray()
->toMatchArray([
Expand All @@ -1670,8 +1670,8 @@ public static function fromData(Data $data)

expect(
(clone $data)
->exceptWhen('first', fn(MultiData $data) => $data->first === 'Hello')
->exceptWhen('second', fn(MultiData $data) => $data->second === 'World')
->exceptWhen('first', fn (MultiData $data) => $data->first === 'Hello')
->exceptWhen('second', fn (MultiData $data) => $data->second === 'World')
->toArray()
)->toBeEmpty();
});
Expand All @@ -1694,7 +1694,7 @@ public static function fromData(Data $data)

it('can conditionally define except using class defaults', function () {
PartialClassConditionalData::setDefinitions(exceptDefinitions: [
'string' => fn(PartialClassConditionalData $data) => $data->enabled,
'string' => fn (PartialClassConditionalData $data) => $data->enabled,
]);

expect(PartialClassConditionalData::create(enabled: false))
Expand All @@ -1715,7 +1715,7 @@ public static function fromData(Data $data)

it('can conditionally define except using class defaults nested', function () {
PartialClassConditionalData::setDefinitions(exceptDefinitions: [
'nested.string' => fn(PartialClassConditionalData $data) => $data->enabled,
'nested.string' => fn (PartialClassConditionalData $data) => $data->enabled,
]);

expect(PartialClassConditionalData::create(enabled: false))
Expand All @@ -1737,8 +1737,8 @@ public static function fromData(Data $data)

it('can conditionally define except using multiple class defaults', function () {
PartialClassConditionalData::setDefinitions(exceptDefinitions: [
'string' => fn(PartialClassConditionalData $data) => $data->enabled,
'nested.string' => fn(PartialClassConditionalData $data) => $data->enabled,
'string' => fn (PartialClassConditionalData $data) => $data->enabled,
'nested.string' => fn (PartialClassConditionalData $data) => $data->enabled,
]);

expect(PartialClassConditionalData::create(enabled: false))
Expand Down
1 change: 0 additions & 1 deletion tests/Fakes/NestedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Spatie\LaravelData\Tests\Fakes;

use Spatie\LaravelData\Data;
use Spatie\LaravelData\Support\Validation\ValidationContext;

class NestedData extends Data
{
Expand Down
1 change: 0 additions & 1 deletion tests/Fakes/SimpleData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Spatie\LaravelData\Tests\Fakes;

use Spatie\LaravelData\Data;
use Spatie\LaravelData\Support\Validation\ValidationContext;

class SimpleData extends Data
{
Expand Down
9 changes: 5 additions & 4 deletions tests/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
use Illuminate\Validation\ValidationException;
use Illuminate\Validation\Validator;

use Spatie\LaravelData\Tests\Fakes\NestedData;
use function Pest\Laravel\mock;
use function PHPUnit\Framework\assertFalse;

use Spatie\LaravelData\Attributes\DataCollectionOf;
use Spatie\LaravelData\Attributes\MapInputName;

use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\MapName;

use Spatie\LaravelData\Attributes\Validation\ArrayType;
use Spatie\LaravelData\Attributes\Validation\Bail;

use Spatie\LaravelData\Attributes\Validation\Bail;
use Spatie\LaravelData\Attributes\Validation\Exists;

use Spatie\LaravelData\Attributes\Validation\In;
use Spatie\LaravelData\Attributes\Validation\IntegerType;
use Spatie\LaravelData\Attributes\Validation\Max;
Expand All @@ -38,8 +38,8 @@
use Spatie\LaravelData\Attributes\Validation\Unique;
use Spatie\LaravelData\Attributes\WithoutValidation;
use Spatie\LaravelData\Data;

use Spatie\LaravelData\DataCollection;

use Spatie\LaravelData\DataPipeline;
use Spatie\LaravelData\DataPipes\AuthorizedDataPipe;
use Spatie\LaravelData\DataPipes\CastPropertiesDataPipe;
Expand All @@ -62,6 +62,7 @@
use Spatie\LaravelData\Tests\Fakes\Enums\DummyBackedEnum;
use Spatie\LaravelData\Tests\Fakes\Models\DummyModel;
use Spatie\LaravelData\Tests\Fakes\MultiData;
use Spatie\LaravelData\Tests\Fakes\NestedData;
use Spatie\LaravelData\Tests\Fakes\NestedNullableData;
use Spatie\LaravelData\Tests\Fakes\SimpleData;
use Spatie\LaravelData\Tests\Fakes\SimpleDataWithExplicitValidationRuleAttributeData;
Expand Down

0 comments on commit 4191674

Please sign in to comment.