From b060fa63fd55528a742f7f9d55c3bf4f3c978187 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 10 Sep 2024 11:28:45 +1200 Subject: [PATCH] DEP Use PHPUnit 11 --- composer.json | 2 +- .../php/Control/UserDefinedFormControllerTest.php | 15 +++++++-------- tests/php/Form/UserFormsRequiredFieldsTest.php | 9 +++++---- tests/php/Model/EditableCustomRuleTest.php | 5 +++-- .../EditableLiteralFieldTest.php | 2 +- tests/php/Model/EditableFormFieldTest.php | 5 +++-- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index a2f08c159..d69a2ba76 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "silverstripe/mimevalidator": "^4" }, "require-dev": { - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^11.3", "squizlabs/php_codesniffer": "^3", "silverstripe/documentation-lint": "^1", "silverstripe/standards": "^1", diff --git a/tests/php/Control/UserDefinedFormControllerTest.php b/tests/php/Control/UserDefinedFormControllerTest.php index 24d4e79b1..2cb09db4c 100644 --- a/tests/php/Control/UserDefinedFormControllerTest.php +++ b/tests/php/Control/UserDefinedFormControllerTest.php @@ -30,6 +30,7 @@ use SilverStripe\View\ArrayData; use SilverStripe\View\SSViewer; use function filesize; +use PHPUnit\Framework\Attributes\DataProvider; /** * @package userforms @@ -525,7 +526,7 @@ public function testEmailAttachmentMaximumSizeCanBeConfigured() $this->assertSame(5 * 1024 * 1024, $udfController->getMaximumAllowedEmailAttachmentSize()); } - public function getParseByteSizeStringTestValues() + public static function getParseByteSizeStringTestValues() { return [ ['9846', 9846], @@ -549,16 +550,14 @@ public function getParseByteSizeStringTestValues() ]; } - /** - * @dataProvider getParseByteSizeStringTestValues - */ + #[DataProvider('getParseByteSizeStringTestValues')] public function testParseByteSizeString($input, $expectedOutput) { $controller = new SizeStringTestableController(); // extends UserDefinedFormController $this->assertSame($expectedOutput, $controller->convertSizeStringToBytes($input)); } - public function getParseByteSizeStringTestBadValues() + public static function getParseByteSizeStringTestBadValues() { return [ ['1234b'], @@ -572,9 +571,9 @@ public function getParseByteSizeStringTestBadValues() } /** - * @dataProvider getParseByteSizeStringTestBadValues * @expectedException \InvalidArgumentException */ + #[DataProvider('getParseByteSizeStringTestBadValues')] public function testParseByteSizeStringBadValuesThrowException($input) { $this->expectException('\InvalidArgumentException'); @@ -582,7 +581,7 @@ public function testParseByteSizeStringBadValuesThrowException($input) $controller->convertSizeStringToBytes($input); } - public function provideValidEmailsToArray() + public static function provideValidEmailsToArray() { return [ [[], [null]], @@ -600,9 +599,9 @@ public function provideValidEmailsToArray() } /** - * @dataProvider provideValidEmailsToArray * Test that provided email is valid */ + #[DataProvider('provideValidEmailsToArray')] public function testValidEmailsToArray(array $expectedOutput, array $input) { $class = new ReflectionClass(UserDefinedFormController::class); diff --git a/tests/php/Form/UserFormsRequiredFieldsTest.php b/tests/php/Form/UserFormsRequiredFieldsTest.php index 9aae7beae..9b45f96d2 100644 --- a/tests/php/Form/UserFormsRequiredFieldsTest.php +++ b/tests/php/Form/UserFormsRequiredFieldsTest.php @@ -8,6 +8,7 @@ use SilverStripe\UserForms\Form\UserFormsRequiredFields; use SilverStripe\UserForms\Model\UserDefinedForm; use SilverStripe\UserForms\Form\UserForm; +use PHPUnit\Framework\Attributes\DataProvider; class UserFormsRequiredFieldsTest extends SapphireTest { @@ -29,7 +30,7 @@ public function testUsesUserFormsRequiredFieldsValidator() $this->assertInstanceOf(UserFormsRequiredFields::class, $validator, 'Uses UserFormsRequiredFields validator'); } - public function dataProviderValidationOfConditionalRequiredFields() + public static function dataProviderValidationOfConditionalRequiredFields() { return [ 'Passes when non-conditional required field has a value' => [ @@ -62,8 +63,8 @@ public function dataProviderValidationOfConditionalRequiredFields() /** * @param $data * @param $expected - * @dataProvider dataProviderValidationOfConditionalRequiredFields */ + #[DataProvider('dataProviderValidationOfConditionalRequiredFields')] public function testValidationOfConditionalRequiredFields($data, $expected) { $page = $this->objFromFixture(UserDefinedForm::class, 'required-custom-rules-form'); @@ -78,7 +79,7 @@ public function testValidationOfConditionalRequiredFields($data, $expected) $this->assertEquals($expected, $validator->php($data)); } - public function dataProviderValidationOfNestedConditionalRequiredFields() + public static function dataProviderValidationOfNestedConditionalRequiredFields() { return [ 'Fails when non-conditional required field is empty' => [[], false], @@ -133,8 +134,8 @@ public function dataProviderValidationOfNestedConditionalRequiredFields() /** * @param string $data * @param array $expected - * @dataProvider dataProviderValidationOfNestedConditionalRequiredFields */ + #[DataProvider('dataProviderValidationOfNestedConditionalRequiredFields')] public function testValidationOfNestedConditionalRequiredFields($data, $expected) { $page = $this->objFromFixture(UserDefinedForm::class, 'required-nested-custom-rules-form'); diff --git a/tests/php/Model/EditableCustomRuleTest.php b/tests/php/Model/EditableCustomRuleTest.php index e717cd39e..87c786024 100644 --- a/tests/php/Model/EditableCustomRuleTest.php +++ b/tests/php/Model/EditableCustomRuleTest.php @@ -4,6 +4,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\UserForms\Model\EditableCustomRule; +use PHPUnit\Framework\Attributes\DataProvider; /** * Class EditableCustomRulesTest @@ -61,7 +62,7 @@ public function testToggleDisplayEvent() $this->assertSame('userform.field.hide', $rule1->toggleDisplayEvent('hide', true)); } - public function dataProviderValidateAgainstFormData() + public static function dataProviderValidateAgainstFormData() { return [ 'IsNotBlank with blank value' => @@ -114,8 +115,8 @@ public function dataProviderValidateAgainstFormData() /** * Test that methods are returned for manipulating the presence of the "hide" CSS class depending * on whether the field should be hidden or shown - * @dataProvider dataProviderValidateAgainstFormData */ + #[DataProvider('dataProviderValidateAgainstFormData')] public function testValidateAgainstFormData($condition, $targetValue, $value, $expected) { $rule1 = $this->objFromFixture(EditableCustomRule::class, 'rule1'); diff --git a/tests/php/Model/EditableFormField/EditableLiteralFieldTest.php b/tests/php/Model/EditableFormField/EditableLiteralFieldTest.php index fa2753031..94931912a 100644 --- a/tests/php/Model/EditableFormField/EditableLiteralFieldTest.php +++ b/tests/php/Model/EditableFormField/EditableLiteralFieldTest.php @@ -59,7 +59,7 @@ public function testHideLabel() public function testLiteralFieldHasUpdateFormFieldMethodCalled() { $field = $this->getMockBuilder(EditableLiteralField::class) - ->setMethods(array('doUpdateFormField')) + ->onlyMethods(array('doUpdateFormField')) ->getMock(); $field->expects($this->once())->method('doUpdateFormField'); diff --git a/tests/php/Model/EditableFormFieldTest.php b/tests/php/Model/EditableFormFieldTest.php index 0e970540e..209cd5a52 100644 --- a/tests/php/Model/EditableFormFieldTest.php +++ b/tests/php/Model/EditableFormFieldTest.php @@ -15,6 +15,7 @@ use SilverStripe\UserForms\Model\EditableFormField\EditableRadioField; use SilverStripe\UserForms\Model\EditableFormField\EditableTextField; use SilverStripe\UserForms\Model\EditableCustomRule; +use PHPUnit\Framework\Attributes\DataProvider; /** * @package userforms @@ -257,7 +258,7 @@ public function testGetIcon() $this->assertStringContainsString('/images/editabletextfield.png', $field->getIcon()); } - public function displayedProvider() + public static function displayedProvider() { $one = ['basic_text_name' => 'foobar']; $two = array_merge($one, ['basic_text_name_2' => 'foobar']); @@ -301,8 +302,8 @@ public function displayedProvider() * @param $fieldName * @param $data * @param $expected - * @dataProvider displayedProvider */ + #[DataProvider('displayedProvider')] public function testIsDisplayed($fieldName, $data, $expected) { /** @var EditableFormField $field */