Skip to content

Commit

Permalink
Revert changes to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bentleyo committed Dec 3, 2022
1 parent c89dde3 commit c5f7f07
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
2 changes: 1 addition & 1 deletion tests/Resolvers/DataClassValidationRulesResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function rules(): array
};

expect(
$this->resolver->execute($data::class, ['collection' => [[]]])->all()
$this->resolver->execute($data::class)->all()
)->toEqualCanonicalizing([
'nested' => ['array', 'required'],
'nested.string' => ['string', 'required', 'min:10', 'max:100'],
Expand Down
28 changes: 7 additions & 21 deletions tests/Resolvers/DataPropertyValidationRulesResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ function resolveRules(object $class, array $payload = []): array
$rules = resolveRules(new class () {
#[DataCollectionOf(SimpleData::class)]
public DataCollection $property;
}, [
'property' => [[]],
]);
});

expect($rules)->toMatchArray([
'property' => ['present', 'array'],
Expand All @@ -166,9 +164,7 @@ function resolveRules(object $class, array $payload = []): array
$rules = resolveRules(new class () {
#[DataCollectionOf(SimpleData::class)]
public ?DataCollection $property;
}, [
'property' => [[]],
]);
});

expect($rules)->toMatchArray([
'property' => ['nullable', 'array'],
Expand All @@ -178,9 +174,7 @@ function resolveRules(object $class, array $payload = []): array
$rules = resolveRules(new class () {
#[DataCollectionOf(SimpleData::class)]
public Optional|DataCollection $property;
}, [
'property' => [[]],
]);
});

expect($rules)->toMatchArray([
'property' => ['sometimes', 'array'],
Expand All @@ -190,9 +184,7 @@ function resolveRules(object $class, array $payload = []): array
$rules = resolveRules(new class () {
#[DataCollectionOf(SimpleData::class)]
public null|Optional|DataCollection $property;
}, [
'property' => [[]],
]);
});

expect($rules)->toMatchArray([
'property' => ['nullable', 'sometimes', 'array'],
Expand Down Expand Up @@ -291,9 +283,7 @@ function resolveRules(object $class, array $payload = []): array
$rules = resolveRules(new class () {
#[DataCollectionOf(SimpleData::class), MapName('other')]
public DataCollection $property;
}, [
'other' => [[]],
]);
});

expect($rules)->toMatchArray([
'other' => ['present', 'array'],
Expand All @@ -303,11 +293,7 @@ function resolveRules(object $class, array $payload = []): array
$rules = resolveRules(new class () {
#[MapName('other')]
public DataWithMapper $property;
}, [
'other' => [
'data_collection_cased_property' => [[]],
],
]);
});

expect($rules)->toMatchArray([
'other' => ['required', 'array'],
Expand Down Expand Up @@ -360,7 +346,7 @@ function () {
public DataCollection $property;
};

expect(resolveRules($data, ['property' => [[]]]))->toMatchArray([
expect(resolveRules($data))->toMatchArray([
'property' => ['present', 'array', 'size:10'],
'property.*.string' => ['string', 'required'],
]);
Expand Down
13 changes: 2 additions & 11 deletions tests/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,6 @@ class NestedClassG extends Data {
->assertRules([
'collection' => ['present', 'array'],
'collection.*.string' => ['string', 'required'],
], [
'collection' => [[]],
]);
});

Expand Down Expand Up @@ -518,8 +516,6 @@ class NestedClassG extends Data {
->assertRules([
'collection' => ['nullable', 'array'],
'collection.*.string' => ['string', 'required'],
], [
'collection' => [[]],
]);
});

Expand Down Expand Up @@ -547,8 +543,6 @@ class NestedClassG extends Data {
->assertRules([
'collection' => ['sometimes', 'array'],
'collection.*.string' => ['string', 'required'],
], [
'collection' => [[]],
]);
});

Expand Down Expand Up @@ -584,8 +578,6 @@ public static function rules(): array
->assertRules([
'collection' => ['present', 'array', 'min:10'],
'collection.*.email' => ['string', 'required', 'email:rfc'],
], [
'collection' => [[]],
]);
});

Expand All @@ -610,14 +602,13 @@ class CollectionClassA extends Data {
public DataCollection $collection;
};

$payload = ['collection' => [['nested' => ['string' => 'Hello World']]]];
DataValidationAsserter::for($dataClass)
->assertRules([
'collection' => ['present', 'array'],
'collection.*.nested' => ['required', 'array'],
'collection.*.nested.string' => ['required', 'string'],
], $payload)
->assertOk($payload);
])
->assertOk(['collection' => [['nested' => ['string' => 'Hello World']]]]);
});

it('can nest data with payload using relative rule generation', function () {
Expand Down

0 comments on commit c5f7f07

Please sign in to comment.