Skip to content

Commit

Permalink
Container: getValues(true) is deprecated (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 30, 2024
1 parent f564731 commit 4a637c3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
6 changes: 5 additions & 1 deletion src/Forms/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ public function getValues(string|object|bool|null $returnType = null, ?array $co
}
}

$returnType = $returnType === true ? self::Array : $returnType;
if ($returnType === true) {
trigger_error(static::class . '::' . __FUNCTION__ . "(true) is deprecated, use getValues('array').", E_USER_DEPRECATED);
$returnType = self::Array;
}

return $this->getUntrustedValues($returnType, $controls);
}

Expand Down
20 changes: 10 additions & 10 deletions tests/Forms/Container.values.array.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ test('setDefaults() + array', function () {
'city' => 'zzz',
],
],
], $form->getValues(true));
], $form->getValues('array'));
});


test('submitted form + getValues(true)', function () {
test('submitted form + getValues(array)', function () {
$_SERVER['REQUEST_METHOD'] = 'POST';

$form = createForm();
Expand All @@ -83,7 +83,7 @@ test('submitted form + getValues(true)', function () {
'city' => 'sent city',
],
],
], $form->getValues(true));
], $form->getValues('array'));
});


Expand All @@ -105,7 +105,7 @@ test('submitted form + reset()', function () {
'city' => '',
],
],
], $form->getValues(true));
], $form->getValues('array'));
});


Expand All @@ -131,7 +131,7 @@ test('setValues() + array', function () {
'city' => 'sent city',
],
],
], $form->getValues(true));
], $form->getValues('array'));

// erase
$form->setValues([
Expand All @@ -150,7 +150,7 @@ test('setValues() + array', function () {
'city' => '',
],
],
], $form->getValues(true));
], $form->getValues('array'));
});


Expand Down Expand Up @@ -262,7 +262,7 @@ test('onSuccess test', function () {
});


test('submitted form + setValidationScope() + getValues(true)', function () {
test('submitted form + setValidationScope() + getValues(array)', function () {
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['send'] = '';

Expand All @@ -276,11 +276,11 @@ test('submitted form + setValidationScope() + getValues(true)', function () {
'age' => 999,
'second' => [],
],
], $form->getValues(true));
], $form->getValues('array'));
});


test('submitted form + setValidationScope() + getValues(true)', function () {
test('submitted form + setValidationScope() + getValues(array)', function () {
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['send'] = '';

Expand Down Expand Up @@ -312,5 +312,5 @@ test('submitted form + setValidationScope() + getValues(array)', function () {
'city' => 'sent city',
],
],
], $form->getValues(true));
], $form->getValues('array'));
});
8 changes: 4 additions & 4 deletions tests/Forms/Container.values.mapping.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ test('setDefaults() + object', function () {
'city' => 'zzz',
],
],
], $form->getValues(true));
], $form->getValues('array'));
});


Expand Down Expand Up @@ -244,7 +244,7 @@ test('getValues(...arguments...)', function () {
'city' => '',
]),
]),
], $form->getValues(true));
], $form->getValues('array'));
});


Expand Down Expand Up @@ -337,7 +337,7 @@ test('getValues() + object', function () {
});


test('submitted form + setValidationScope() + getValues(true)', function () {
test('submitted form + setValidationScope() + getValues()', function () {
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['send'] = '';

Expand All @@ -355,7 +355,7 @@ test('submitted form + setValidationScope() + getValues(true)', function () {
});


test('submitted form + setValidationScope() + getValues(true)', function () {
test('submitted form + setValidationScope() + getValues()', function () {
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST['send'] = '';

Expand Down
2 changes: 1 addition & 1 deletion tests/Forms/Forms.getHttpData.get.2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ test('', function () {

Assert::truthy($form->isSubmitted());
Assert::same(['item'], $form->getHttpData());
Assert::same([], $form->getValues(true));
Assert::same([], $form->getValues('array'));
});
6 changes: 3 additions & 3 deletions tests/Forms/Forms.getHttpData.get.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('', function () {
Assert::false($form->isSubmitted());
Assert::false($form->isSuccess());
Assert::same([], $form->getHttpData());
Assert::same([], $form->getValues(true));
Assert::same([], $form->getValues('array'));
});


Expand All @@ -39,7 +39,7 @@ test('', function () {

Assert::false($form->isSubmitted());
Assert::same([], $form->getHttpData());
Assert::same([], $form->getValues(true));
Assert::same([], $form->getValues('array'));
});


Expand All @@ -54,6 +54,6 @@ test('', function () {

Assert::truthy($form->isSubmitted());
Assert::same([Form::TrackerId => $name], $form->getHttpData());
Assert::same([], $form->getValues(true));
Assert::same([], $form->getValues('array'));
Assert::same($name, $form[Form::TrackerId]->getValue());
});
8 changes: 4 additions & 4 deletions tests/Forms/Forms.getHttpData.post.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test('', function () {
Assert::truthy($form->isSubmitted());
Assert::true($form->isSuccess());
Assert::same([], $form->getHttpData());
Assert::same([], $form->getValues(true));
Assert::same([], $form->getValues('array'));
});


Expand All @@ -43,7 +43,7 @@ test('', function () {
Assert::false($form->isSubmitted());
Assert::false($form->isSuccess());
Assert::same([], $form->getHttpData());
Assert::same([], $form->getValues(true));
Assert::same([], $form->getValues('array'));
});


Expand All @@ -55,7 +55,7 @@ test('', function () {
Assert::false($form->isSubmitted());
Assert::false($form->isSuccess());
Assert::same([], $form->getHttpData());
Assert::same([], $form->getValues(true));
Assert::same([], $form->getValues('array'));
});


Expand All @@ -68,7 +68,7 @@ test('', function () {

Assert::truthy($form->isSubmitted());
Assert::same([Form::TrackerId => $name], $form->getHttpData());
Assert::same([], $form->getValues(true));
Assert::same([], $form->getValues('array'));
Assert::same($name, $form[Form::TrackerId]->getValue());
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Forms/Forms.omittedValue.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $form->addText('input');
$form->addText('omittedInput')
->setOmitted();

Assert::same(['input' => ''], $form->getValues(true));
Assert::same(['input' => ''], $form->getValues('array'));


Assert::true((new TextInput)->setDisabled()->isOmitted());
Expand Down

0 comments on commit 4a637c3

Please sign in to comment.