From 4a637c33a35334b68d123bfe187588d1b204a870 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 12 Sep 2021 22:16:09 +0200 Subject: [PATCH] Container: getValues(true) is deprecated (BC break) --- src/Forms/Container.php | 6 +++++- tests/Forms/Container.values.array.phpt | 20 ++++++++++---------- tests/Forms/Container.values.mapping.phpt | 8 ++++---- tests/Forms/Forms.getHttpData.get.2.phpt | 2 +- tests/Forms/Forms.getHttpData.get.phpt | 6 +++--- tests/Forms/Forms.getHttpData.post.phpt | 8 ++++---- tests/Forms/Forms.omittedValue.phpt | 2 +- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/Forms/Container.php b/src/Forms/Container.php index 859c03cc2..92b5bbcbb 100644 --- a/src/Forms/Container.php +++ b/src/Forms/Container.php @@ -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); } diff --git a/tests/Forms/Container.values.array.phpt b/tests/Forms/Container.values.array.phpt index 8fb3df46d..b273e7ecb 100644 --- a/tests/Forms/Container.values.array.phpt +++ b/tests/Forms/Container.values.array.phpt @@ -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(); @@ -83,7 +83,7 @@ test('submitted form + getValues(true)', function () { 'city' => 'sent city', ], ], - ], $form->getValues(true)); + ], $form->getValues('array')); }); @@ -105,7 +105,7 @@ test('submitted form + reset()', function () { 'city' => '', ], ], - ], $form->getValues(true)); + ], $form->getValues('array')); }); @@ -131,7 +131,7 @@ test('setValues() + array', function () { 'city' => 'sent city', ], ], - ], $form->getValues(true)); + ], $form->getValues('array')); // erase $form->setValues([ @@ -150,7 +150,7 @@ test('setValues() + array', function () { 'city' => '', ], ], - ], $form->getValues(true)); + ], $form->getValues('array')); }); @@ -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'] = ''; @@ -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'] = ''; @@ -312,5 +312,5 @@ test('submitted form + setValidationScope() + getValues(array)', function () { 'city' => 'sent city', ], ], - ], $form->getValues(true)); + ], $form->getValues('array')); }); diff --git a/tests/Forms/Container.values.mapping.phpt b/tests/Forms/Container.values.mapping.phpt index b735d3d7e..a51c618e0 100644 --- a/tests/Forms/Container.values.mapping.phpt +++ b/tests/Forms/Container.values.mapping.phpt @@ -101,7 +101,7 @@ test('setDefaults() + object', function () { 'city' => 'zzz', ], ], - ], $form->getValues(true)); + ], $form->getValues('array')); }); @@ -244,7 +244,7 @@ test('getValues(...arguments...)', function () { 'city' => '', ]), ]), - ], $form->getValues(true)); + ], $form->getValues('array')); }); @@ -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'] = ''; @@ -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'] = ''; diff --git a/tests/Forms/Forms.getHttpData.get.2.phpt b/tests/Forms/Forms.getHttpData.get.2.phpt index c1dbcd519..14efaf66e 100644 --- a/tests/Forms/Forms.getHttpData.get.2.phpt +++ b/tests/Forms/Forms.getHttpData.get.2.phpt @@ -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')); }); diff --git a/tests/Forms/Forms.getHttpData.get.phpt b/tests/Forms/Forms.getHttpData.get.phpt index 53efa6196..c8478e4fb 100644 --- a/tests/Forms/Forms.getHttpData.get.phpt +++ b/tests/Forms/Forms.getHttpData.get.phpt @@ -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')); }); @@ -39,7 +39,7 @@ test('', function () { Assert::false($form->isSubmitted()); Assert::same([], $form->getHttpData()); - Assert::same([], $form->getValues(true)); + Assert::same([], $form->getValues('array')); }); @@ -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()); }); diff --git a/tests/Forms/Forms.getHttpData.post.phpt b/tests/Forms/Forms.getHttpData.post.phpt index dea8a8d23..f8cca7377 100644 --- a/tests/Forms/Forms.getHttpData.post.phpt +++ b/tests/Forms/Forms.getHttpData.post.phpt @@ -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')); }); @@ -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')); }); @@ -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')); }); @@ -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()); }); diff --git a/tests/Forms/Forms.omittedValue.phpt b/tests/Forms/Forms.omittedValue.phpt index 54e952b3a..ae5ed9882 100644 --- a/tests/Forms/Forms.omittedValue.phpt +++ b/tests/Forms/Forms.omittedValue.phpt @@ -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());