[ // User is logged in true, // Expected isMet() result true ], 'Anonymous user' => [ // User is not logged in false, // Expected isMet() result false ] ]; } /** * @covers ::getName */ public function testGetName() { // Mock the User object $userMock = $this->createMock( UserIdentity::class ); $requirementName = 'mockedUserLoggedInRequirement'; // Instantiate the LoggedInRequirement with the mock User object and the requirement name $loggedInRequirement = new LoggedInRequirement( $userMock, $requirementName ); // Assert that the getName method returns the correct requirement name $this->assertEquals( $requirementName, $loggedInRequirement->getName(), 'Failed testing getName method.' ); } /** * @dataProvider userProvider * @covers ::isMet * @param bool $isUserLoggedIn * @param bool $expectedResult */ public function testIsMet( bool $isUserLoggedIn, bool $expectedResult ) { // Mock the User object $userMock = $this->createMock( UserIdentity::class ); // Setup the isRegistered method to return the login state $userMock->method( 'isRegistered' )->willReturn( $isUserLoggedIn ); // Instantiate the LoggedInRequirement with the mock User object and a dummy name $loggedInRequirement = new LoggedInRequirement( $userMock, 'mockedUserLoggedInRequirement' ); // Assert that the isMet method returns the expected boolean value $this->assertEquals( $expectedResult, $loggedInRequirement->isMet(), 'Failed testing isMet method.' ); } }