From a1ae139540f37ed789da7cd80ef53261973e275d Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 16 Dec 2024 13:13:26 +1300 Subject: [PATCH 1/2] API Make validator param nullable --- src/Forms/Form.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Forms/Form.php b/src/Forms/Form.php index 40d6f8c252a..3f0dfe2004f 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -114,9 +114,9 @@ class Form extends ModelData implements HasRequestHandler protected $name; /** - * @var Validator + * @var null|Validator */ - protected $validator; + protected $validator = null; /** * @see setValidationResponseCallback() @@ -635,7 +635,7 @@ public function transform(FormTransformation $trans) /** * Get the {@link Validator} attached to this form. - * @return Validator + * @return null|Validator */ public function getValidator() { @@ -644,10 +644,10 @@ public function getValidator() /** * Set the {@link Validator} on this form. - * @param Validator $validator + * @param null|Validator $validator * @return $this */ - public function setValidator(Validator $validator) + public function setValidator(?Validator $validator) { if ($validator) { $this->validator = $validator; From bfe6f945f4c7826214e555a7f796c46a9c2b9420 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 16 Dec 2024 16:46:16 +1300 Subject: [PATCH 2/2] MNT Fix unit test --- tests/php/Forms/DropdownFieldTest.php | 6 ++---- tests/php/Forms/TreeDropdownFieldTest.php | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/php/Forms/DropdownFieldTest.php b/tests/php/Forms/DropdownFieldTest.php index 8af81e7af1b..321546be928 100644 --- a/tests/php/Forms/DropdownFieldTest.php +++ b/tests/php/Forms/DropdownFieldTest.php @@ -601,7 +601,7 @@ public function testEmptySourceDoesntBlockValidation() $this->assertTrue($field->validate()->isValid()); } - public function provideGetDefaultValue(): array + public static function provideGetDefaultValue(): array { return [ [ @@ -648,9 +648,7 @@ public function provideGetDefaultValue(): array ]; } - /** - * @dataProvider provideGetDefaultValue - */ + #[DataProvider('provideGetDefaultValue')] public function testGetDefaultValue(mixed $value, bool $hasEmptyDefault, mixed $expected): void { $field = new DropdownField('MyField', source: ['one' => 'one', 'two' => 'two', '3' => 'three']); diff --git a/tests/php/Forms/TreeDropdownFieldTest.php b/tests/php/Forms/TreeDropdownFieldTest.php index fbf15de4f1e..cc2c67a2d4c 100644 --- a/tests/php/Forms/TreeDropdownFieldTest.php +++ b/tests/php/Forms/TreeDropdownFieldTest.php @@ -303,9 +303,9 @@ public function testTreeSearchUsingSubObject() $cssPath = 'ul.tree li#selector-TestTree-' . $subObject1->ID . ' li#selector-TestTree-' . $subObject1ChildB->ID . ' a'; $firstResult = $parser->getBySelector($cssPath); $this->assertEquals( - $subObject1ChildB->Name, + $subObject1ChildB->Title, (string)$firstResult[0], - $subObject1ChildB->Name . ' is found, nested under ' . $subObject1->Name + $subObject1ChildB->Title . ' is found, nested under ' . $subObject1->Title ); // other objects which don't contain the keyword 'SubObject' are not returned in search results