wiki.techinc.nl/tests/phpunit/includes/auth/ConfirmLinkAuthenticationRequestTest.php
Thiemo Kreuz 40764d277c Replace PHPUnit ->returnValue() with ->willReturn() shortcut
It's the same and makes the test code much more readable, I
would like to argue.

Because of the was I split all the changes I made into smaller
patches this patch contains some other changes in the same
lines where I could not split them off. E.g. removal of
->any(), which is the default anyway and doesn't do anything.

Change-Id: Ib297b989d4aec33b31a4e33fe9d5032865b39be0
2021-04-22 10:37:45 +02:00

66 lines
1.6 KiB
PHP

<?php
namespace MediaWiki\Auth;
use InvalidArgumentException;
/**
* @group AuthManager
* @covers \MediaWiki\Auth\ConfirmLinkAuthenticationRequest
*/
class ConfirmLinkAuthenticationRequestTest extends AuthenticationRequestTestCase {
protected function getInstance( array $args = [] ) {
return new ConfirmLinkAuthenticationRequest( $this->getLinkRequests() );
}
public function testConstructorException() {
$this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessage( '$linkRequests must not be empty' );
new ConfirmLinkAuthenticationRequest( [] );
}
/**
* Get requests for testing
* @return AuthenticationRequest[]
*/
private function getLinkRequests() {
$reqs = [];
$mb = $this->getMockBuilder( AuthenticationRequest::class )
->onlyMethods( [ 'getUniqueId' ] );
for ( $i = 1; $i <= 3; $i++ ) {
$req = $mb->getMockForAbstractClass();
$req->method( 'getUniqueId' )
->willReturn( "Request$i" );
$reqs[$req->getUniqueId()] = $req;
}
return $reqs;
}
public function provideLoadFromSubmission() {
$reqs = $this->getLinkRequests();
return [
'Empty request' => [
[],
[],
[ 'linkRequests' => $reqs ],
],
'Some confirmed' => [
[],
[ 'confirmedLinkIDs' => [ 'Request1', 'Request3' ] ],
[ 'confirmedLinkIDs' => [ 'Request1', 'Request3' ], 'linkRequests' => $reqs ],
],
];
}
public function testGetUniqueId() {
$req = new ConfirmLinkAuthenticationRequest( $this->getLinkRequests() );
$this->assertSame(
get_class( $req ) . ':Request1|Request2|Request3',
$req->getUniqueId()
);
}
}