Skip to content

Commit

Permalink
Merge pull request #1326 from creative-commoners/pulls/7/phpunit11
Browse files Browse the repository at this point in the history
DEP Use PHPUnit 11
  • Loading branch information
GuySartorelli committed Sep 18, 2024
2 parents f4321ee + b060fa6 commit 9e61ae3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 7 additions & 8 deletions tests/php/Control/UserDefinedFormControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use SilverStripe\View\ArrayData;
use SilverStripe\View\SSViewer;
use function filesize;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @package userforms
Expand Down Expand Up @@ -525,7 +526,7 @@ public function testEmailAttachmentMaximumSizeCanBeConfigured()
$this->assertSame(5 * 1024 * 1024, $udfController->getMaximumAllowedEmailAttachmentSize());
}

public function getParseByteSizeStringTestValues()
public static function getParseByteSizeStringTestValues()
{
return [
['9846', 9846],
Expand All @@ -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'],
Expand All @@ -572,17 +571,17 @@ public function getParseByteSizeStringTestBadValues()
}

/**
* @dataProvider getParseByteSizeStringTestBadValues
* @expectedException \InvalidArgumentException
*/
#[DataProvider('getParseByteSizeStringTestBadValues')]
public function testParseByteSizeStringBadValuesThrowException($input)
{
$this->expectException('\InvalidArgumentException');
$controller = new SizeStringTestableController(); // extends UserDefinedFormController
$controller->convertSizeStringToBytes($input);
}

public function provideValidEmailsToArray()
public static function provideValidEmailsToArray()
{
return [
[[], [null]],
Expand All @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions tests/php/Form/UserFormsRequiredFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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' => [
Expand Down Expand Up @@ -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');
Expand All @@ -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],
Expand Down Expand Up @@ -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');
Expand Down
5 changes: 3 additions & 2 deletions tests/php/Model/EditableCustomRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\EditableCustomRule;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Class EditableCustomRulesTest
Expand Down Expand Up @@ -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' =>
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 3 additions & 2 deletions tests/php/Model/EditableFormFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 9e61ae3

Please sign in to comment.