wiki.techinc.nl/tests/phpunit/includes/auth/ConfirmLinkAuthenticationRequestTest.php
Daimona Eaytoy 535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +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->expects( $this->any() )->method( 'getUniqueId' )
->will( $this->returnValue( "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()
);
}
}