Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP Use PHPUnit 11 #565

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"silverstripe/login-forms": "^6"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^11.3",
"squizlabs/php_codesniffer": "^3",
"silverstripe/documentation-lint": "^1",
"silverstripe/standards": "^1",
Expand Down
14 changes: 7 additions & 7 deletions tests/php/Authenticator/ChangePasswordHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function testStartMfaCheckThrowsExceptionWithoutStore()
/** @var ChangePasswordHandler&MockObject $handler */
$handler = $this->getMockBuilder(ChangePasswordHandler::class)
->disableOriginalConstructor()
->setMethods(['getStore'])
->onlyMethods(['getStore'])
->getMock();

$handler->expects($this->once())->method('getStore')->willReturn(null);
Expand All @@ -143,7 +143,7 @@ public function testStartMfaReturnsForbiddenWithoutMember()
/** @var ChangePasswordHandler&MockObject $handler */
$handler = $this->getMockBuilder(ChangePasswordHandler::class)
->disableOriginalConstructor()
->setMethods(['getStore'])
->onlyMethods(['getStore'])
->getMock();

$store = $this->createMock(TestStore::class);
Expand All @@ -160,7 +160,7 @@ public function testMfaStartsVerificationResponse()
/** @var ChangePasswordHandler&MockObject $handler */
$handler = $this->getMockBuilder(ChangePasswordHandler::class)
->disableOriginalConstructor()
->setMethods(['getStore', 'createStartVerificationResponse'])
->onlyMethods(['getStore', 'createStartVerificationResponse'])
->getMock();

$store = $this->createMock(TestStore::class);
Expand All @@ -185,7 +185,7 @@ public function testVerifyMfaCheckReturnsForbiddenOnVerificationFailure()
/** @var ChangePasswordHandler&MockObject $handler */
$handler = $this->getMockBuilder(ChangePasswordHandler::class)
->disableOriginalConstructor()
->setMethods(['getStore', 'completeVerificationRequest'])
->onlyMethods(['getStore', 'completeVerificationRequest'])
->getMock();

/** @var LoggerInterface&MockObject $logger */
Expand All @@ -209,7 +209,7 @@ public function testVerifyMfaCheckReturnsUnsuccessfulValidationResult()
/** @var ChangePasswordHandler&MockObject $handler */
$handler = $this->getMockBuilder(ChangePasswordHandler::class)
->disableOriginalConstructor()
->setMethods(['getStore', 'completeVerificationRequest'])
->onlyMethods(['getStore', 'completeVerificationRequest'])
->getMock();

$store = $this->createMock(TestStore::class);
Expand All @@ -229,7 +229,7 @@ public function testVerifyMfaReturnsWhenVerificationIsNotComplete()
/** @var ChangePasswordHandler&MockObject $handler */
$handler = $this->getMockBuilder(ChangePasswordHandler::class)
->disableOriginalConstructor()
->setMethods(['getStore', 'completeVerificationRequest', 'isVerificationComplete'])
->onlyMethods(['getStore', 'completeVerificationRequest', 'isVerificationComplete'])
->getMock();

$store = $this->createMock(TestStore::class);
Expand All @@ -248,7 +248,7 @@ public function testVerifyMfaResultSuccessful()
/** @var ChangePasswordHandler&MockObject $handler */
$handler = $this->getMockBuilder(ChangePasswordHandler::class)
->disableOriginalConstructor()
->setMethods(['getStore', 'completeVerificationRequest', 'isVerificationComplete'])
->onlyMethods(['getStore', 'completeVerificationRequest', 'isVerificationComplete'])
->getMock();

$store = new SessionStore($this->createMock(Member::class));
Expand Down
19 changes: 10 additions & 9 deletions tests/php/Authenticator/LoginHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use SilverStripe\Security\SecurityToken;
use SilverStripe\Security\SudoMode\SudoModeServiceInterface;
use SilverStripe\SiteConfig\SiteConfig;
use PHPUnit\Framework\Attributes\DataProvider;

class LoginHandlerTest extends FunctionalTest
{
Expand Down Expand Up @@ -201,8 +202,8 @@ public function testMFASchemaEndpointProvidesDefaultMethodIfSet()
/**
* @param bool $mfaRequired
* @param string|null $member
* @dataProvider cannotSkipMFAProvider
*/
#[DataProvider('cannotSkipMFAProvider')]
public function testCannotSkipMFA($mfaRequired, $member = 'robbie')
{
$this->setSiteConfig(['MFARequired' => $mfaRequired]);
Expand All @@ -218,7 +219,7 @@ public function testCannotSkipMFA($mfaRequired, $member = 'robbie')
/**
* @return array[]
*/
public function cannotSkipMFAProvider()
public static function cannotSkipMFAProvider()
{
return [
'mfa is required' => [true],
Expand All @@ -231,8 +232,8 @@ public function cannotSkipMFAProvider()
* @param string $memberFixture
* @param bool $mfaRequiredInGrace
* @param string|null $expectedRedirect
* @dataProvider skipRegistrationProvider
*/
#[DataProvider('skipRegistrationProvider')]
public function testSkipRegistration($memberFixture, $mfaRequiredInGrace = false, $expectedRedirect = null)
{
if ($mfaRequiredInGrace) {
Expand Down Expand Up @@ -270,7 +271,7 @@ public function testSkipRegistration($memberFixture, $mfaRequiredInGrace = false
$this->assertTrue((bool)$member->HasSkippedMFARegistration);
}

public function skipRegistrationProvider()
public static function skipRegistrationProvider()
{
return [
['guy'],
Expand All @@ -282,8 +283,8 @@ public function skipRegistrationProvider()

/**
* @param string $memberFixture
* @dataProvider methodlessMemberFixtureProvider
*/
#[DataProvider('methodlessMemberFixtureProvider')]
public function testBackURLIsPreservedWhenSkipping($memberFixture)
{
/** @var Member $member */
Expand Down Expand Up @@ -499,7 +500,7 @@ public function testFinishVerificationPassesExceptionMessagesThroughFromMethodsW

/** @var LoginHandler|MockObject $handler */
$handler = $this->getMockBuilder(LoginHandler::class)
->setMethods(['completeVerificationRequest'])
->onlyMethods(['completeVerificationRequest'])
->disableOriginalConstructor()
->getMock();

Expand All @@ -522,8 +523,8 @@ public function testFinishVerificationPassesExceptionMessagesThroughFromMethodsW

/**
* @param string $memberFixture
* @dataProvider methodlessMemberFixtureProvider
*/
#[DataProvider('methodlessMemberFixtureProvider')]
public function testFinishVerificationWillRedirectToTheBackURLSetAsLoginIsStarted($memberFixture)
{
/** @var Member $member */
Expand All @@ -534,7 +535,7 @@ public function testFinishVerificationWillRedirectToTheBackURLSetAsLoginIsStarte

/** @var LoginHandler|MockObject $handler */
$handler = $this->getMockBuilder(LoginHandler::class)
->setMethods(['completeVerificationRequest'])
->onlyMethods(['completeVerificationRequest'])
->disableOriginalConstructor()
->getMock();

Expand Down Expand Up @@ -572,7 +573,7 @@ public function testGetBackURL()
$this->assertSame('foobar', $handler->getBackURL());
}

public function methodlessMemberFixtureProvider()
public static function methodlessMemberFixtureProvider()
{
return [['guy', 'carla']];
}
Expand Down
7 changes: 3 additions & 4 deletions tests/php/BackupCode/VerifyHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
use SilverStripe\MFA\Tests\Stub\Store\TestStore;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member;
use PHPUnit\Framework\Attributes\DataProvider;

class VerifyHandlerTest extends SapphireTest
{
protected static $fixture_file = 'VerifyHandlerTest.yml';

/**
* @dataProvider getVerifyTests
*/
#[DataProvider('getVerifyTests')]
public function testVerifyValidatesCodes($expectedResult, $input, $message)
{
$handler = (new VerifyHandler())->setNotificationService($this->createMock(Notification::class));
Expand Down Expand Up @@ -57,7 +56,7 @@ public function testVerifyInvalidatesCodesThatHaveBeenUsed()
);
}

public function getVerifyTests()
public static function getVerifyTests()
{
return [
[false, 'asw123', 'Invalid characters are handled'],
Expand Down
5 changes: 3 additions & 2 deletions tests/php/Report/EnabledMembersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SilverStripe\MFA\Service\MethodRegistry;
use SilverStripe\MFA\Tests\Stub\BasicMath\Method as BasicMathMethod;
use SilverStripe\MFA\Tests\Stub\Null\Method as NullMethod;
use PHPUnit\Framework\Attributes\DataProvider;

class EnabledMembersTest extends SapphireTest
{
Expand All @@ -34,18 +35,18 @@ public function testRegisteredMethodFilterFieldDoesNotContainBackupMethod()
}

/**
* @dataProvider sourceRecordsParamsProvider
* @param array $params
* @param int $expectedRows
*/
#[DataProvider('sourceRecordsParamsProvider')]
public function testSourceRecords($params, $expectedRows)
{
$report = new EnabledMembers();
$records = $report->sourceRecords($params);
$this->assertCount($expectedRows, $records);
}

public function sourceRecordsParamsProvider()
public static function sourceRecordsParamsProvider()
{
return [
'no filters' => [[], 5],
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Service/RegisteredMethodManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function testCanRemoveOneOfTwoMethodsWhenMFAIsRequired()
private function registerServiceForMFAToBeRequired($required = false)
{
$enforcementMock = $this->getMockBuilder(EnforcementManager::class)
->setMethods(['isMFARequired'])
->onlyMethods(['isMFARequired'])
->getMock();
$enforcementMock
->method('isMFARequired')
Expand Down
Loading