MediaWiki-CodeSniffer
MediaWiki CodeSniffer Standards
Loading...
Searching...
No Matches
MediaWiki\Sniffs\PHPUnit\MockBoilerplateSniff Class Reference

Simplify set up of mocks in PHPUnit test cases: ->will( $this->returnValue( ... ) ) becomes ->willReturn( ... ) as well as other ->will() shortcuts, see PHPUnit docs table 8.1 ->with( $this->equalTo( ... ) ) becomes ->with( ... ), for any number of parameters provided, since equalTo() is the default constraint checked if a value is provided (as long as the equalTo() call only had a single parameter) ->exactly( 1 ) becomes ->once() ->exactly( 0 ) becomes ->never() More...

+ Inheritance diagram for MediaWiki\Sniffs\PHPUnit\MockBoilerplateSniff:

Public Member Functions

 register ()
 @inheritDoc
 
 process (File $phpcsFile, $stackPtr)
 
 handleExactly (File $phpcsFile, $stackPtr, $exactlyOpener)
 
 handleWill (File $phpcsFile, $stackPtr, $willOpener)
 
 handleWith (File $phpcsFile, $withOpener)
 

Detailed Description

Simplify set up of mocks in PHPUnit test cases: ->will( $this->returnValue( ... ) ) becomes ->willReturn( ... ) as well as other ->will() shortcuts, see PHPUnit docs table 8.1 ->with( $this->equalTo( ... ) ) becomes ->with( ... ), for any number of parameters provided, since equalTo() is the default constraint checked if a value is provided (as long as the equalTo() call only had a single parameter) ->exactly( 1 ) becomes ->once() ->exactly( 0 ) becomes ->never()

Potential future improvements include

  • replace unneeded $this->any() calls, i.e. ->expects( $this->any() )->method( ... ) becomes ->method( ... )
  • apply the with() replacements to withConsecutive() as well
Author
DannyS712

Member Function Documentation

◆ handleExactly()

MediaWiki\Sniffs\PHPUnit\MockBoilerplateSniff::handleExactly ( File $phpcsFile,
$stackPtr,
$exactlyOpener )
Parameters
File$phpcsFile
int$stackPtr
int$exactlyOpener
Returns
void|int

◆ handleWill()

MediaWiki\Sniffs\PHPUnit\MockBoilerplateSniff::handleWill ( File $phpcsFile,
$stackPtr,
$willOpener )
Parameters
File$phpcsFile
int$stackPtr
int$willOpener
Returns
void|int

◆ handleWith()

MediaWiki\Sniffs\PHPUnit\MockBoilerplateSniff::handleWith ( File $phpcsFile,
$withOpener )
Parameters
File$phpcsFile
int$withOpener
Returns
int

◆ process()

MediaWiki\Sniffs\PHPUnit\MockBoilerplateSniff::process ( File $phpcsFile,
$stackPtr )
Parameters
File$phpcsFile
int$stackPtr
Returns
void|int

The documentation for this class was generated from the following file: