DEP Use PHPUnit 11

This commit is contained in:
Steve Boyd 2024-09-10 11:28:45 +12:00
parent f4321ee218
commit b060fa63fd
6 changed files with 20 additions and 18 deletions

View File

@ -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",

View File

@ -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);

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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 */