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 a2f08c1..d69a2ba 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 24d4e79..2cb09db 100644 --- a/tests/php/Control/UserDefinedFormControllerTest.php +++ b/tests/php/Control/UserDefinedFormControllerTest.php @@ -30,6 +30,7 @@ use SilverStripe\Versioned\Versioned; use SilverStripe\View\ArrayData; use SilverStripe\View\SSViewer; use function filesize; +use PHPUnit\Framework\Attributes\DataProvider; /** * @package userforms @@ -525,7 +526,7 @@ class UserDefinedFormControllerTest extends FunctionalTest $this->assertSame(5 * 1024 * 1024, $udfController->getMaximumAllowedEmailAttachmentSize()); } - public function getParseByteSizeStringTestValues() + public static function getParseByteSizeStringTestValues() { return [ ['9846', 9846], @@ -549,16 +550,14 @@ class UserDefinedFormControllerTest extends FunctionalTest ]; } - /** - * @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 @@ class UserDefinedFormControllerTest extends FunctionalTest } /** - * @dataProvider getParseByteSizeStringTestBadValues * @expectedException \InvalidArgumentException */ + #[DataProvider('getParseByteSizeStringTestBadValues')] public function testParseByteSizeStringBadValuesThrowException($input) { $this->expectException('\InvalidArgumentException'); @@ -582,7 +581,7 @@ class UserDefinedFormControllerTest extends FunctionalTest $controller->convertSizeStringToBytes($input); } - public function provideValidEmailsToArray() + public static function provideValidEmailsToArray() { return [ [[], [null]], @@ -600,9 +599,9 @@ class UserDefinedFormControllerTest extends FunctionalTest } /** - * @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 9aae7be..9b45f96 100644 --- a/tests/php/Form/UserFormsRequiredFieldsTest.php +++ b/tests/php/Form/UserFormsRequiredFieldsTest.php @@ -8,6 +8,7 @@ use SilverStripe\Dev\SapphireTest; 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 @@ class UserFormsRequiredFieldsTest extends SapphireTest $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 @@ class UserFormsRequiredFieldsTest extends SapphireTest /** * @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 @@ class UserFormsRequiredFieldsTest extends SapphireTest $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 @@ class UserFormsRequiredFieldsTest extends SapphireTest /** * @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 e717cd3..87c7860 100644 --- a/tests/php/Model/EditableCustomRuleTest.php +++ b/tests/php/Model/EditableCustomRuleTest.php @@ -4,6 +4,7 @@ namespace SilverStripe\UserForms\Tests\Model; use SilverStripe\Dev\SapphireTest; use SilverStripe\UserForms\Model\EditableCustomRule; +use PHPUnit\Framework\Attributes\DataProvider; /** * Class EditableCustomRulesTest @@ -61,7 +62,7 @@ class EditableCustomRuleTest extends SapphireTest $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 @@ class EditableCustomRuleTest extends SapphireTest /** * 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 fa27530..9493191 100644 --- a/tests/php/Model/EditableFormField/EditableLiteralFieldTest.php +++ b/tests/php/Model/EditableFormField/EditableLiteralFieldTest.php @@ -59,7 +59,7 @@ class EditableLiteralFieldTest extends SapphireTest 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 0e97054..209cd5a 100644 --- a/tests/php/Model/EditableFormFieldTest.php +++ b/tests/php/Model/EditableFormFieldTest.php @@ -15,6 +15,7 @@ use SilverStripe\UserForms\Model\EditableFormField\EditableOption; 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 @@ class EditableFormFieldTest extends FunctionalTest $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 @@ class EditableFormFieldTest extends FunctionalTest * @param $fieldName * @param $data * @param $expected - * @dataProvider displayedProvider */ + #[DataProvider('displayedProvider')] public function testIsDisplayed($fieldName, $data, $expected) { /** @var EditableFormField $field */