createMock( FooBar::class ); $mock->method( 'foo' )->willReturn( 1 ); $mock->method( 'bar' ) ->willReturn( 2 ); $mock->method( 'arg1' )->willReturnArgument( 0 ); $mock->method( 'ucfirst' )->willReturnCallback( 'ucfirst' ); $mock->method( 'boolIsTrue' )->willReturnMap( [ [ true, true ], [ false, false ], ] ); $mock->method( 'self' )->willReturnSelf(); $mock->method( 'error' )->willThrowException( $ex ); } /** @coversNothing */ public function testExactlyShortcut() { $mock = $this->createMock( FooBar::class ); $mock->expects( $this->once() )->method( 'foo' )->willReturn( 1 ); $mock->expects( $this->never() ) ->method( 'bar' ); } /** @coversNothing */ public function testWithEqualTo() { $mock = $this->createMock( FooBar::class ); $mock->method( 'has' )->with( 'value' )->willReturn( true ); $mock->method( 'get' )->with( 'value' )->willReturn( 1 ); $mock->method( 'multi' )->with( 'first', 'second', 'third' )->willReturn( false ); // equalTo() with a parameter that includes a comma (function call) $mock->method( 'calculated' )->with( addValues( 1, 2 ) )->willReturn( false ); } /** @coversNothing */ public function testNotChanged() { $mock = $this->createMock( FooBar::class ); $mock->expects( $this->exactly( 2 ) )->method( 'foo' ); $mock->expects( $this->once() )->method( 'bar' ); // equalTo() with a second parameter is skipped $mock->method( 'baz' )->with( $this->equalTo( 10, 0.1 ) )->willReturn( false ); // equalTo() within a logicalNot() $mock->method( 'qux' ) ->with( $this->logicalNot( $this->equalTo( 'quxParam' ) ) ) ->willThrowException( $this->createMock( InvalidArgumentException::class ) ); // equalTo() within a logicalOr() $mock->method( 'other' ) ->with( $this->logicalOr( $this->equalTo( 'other1' ), $this->equalTo( 'other2' ) ) ) ->willReturn( true ); } }