Skip to content

Commit

Permalink
Merge branch '9.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 17, 2020
2 parents 1d221c1 + beea391 commit 2a37f33
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 84 deletions.
45 changes: 18 additions & 27 deletions tests/unit/Framework/MockObject/Builder/InvocationMockerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public function testWillReturnWithOneValue(): void
->setMethods(['foo'])
->getMock();

$mock->expects($this->any())
->method('foo')
->willReturn(1);
$mock->method('foo')
->willReturn(1);

$this->assertEquals(1, $mock->foo());
}
Expand All @@ -43,9 +42,8 @@ public function testWillReturnWithMultipleValues(): void
->setMethods(['foo'])
->getMock();

$mock->expects($this->any())
->method('foo')
->willReturn(1, 2, 3);
$mock->method('foo')
->willReturn(1, 2, 3);

$this->assertEquals(1, $mock->foo());
$this->assertEquals(2, $mock->foo());
Expand All @@ -58,9 +56,8 @@ public function testWillReturnOnConsecutiveCalls(): void
->setMethods(['foo'])
->getMock();

$mock->expects($this->any())
->method('foo')
->willReturnOnConsecutiveCalls(1, 2, 3);
$mock->method('foo')
->willReturnOnConsecutiveCalls(1, 2, 3);

$this->assertEquals(1, $mock->foo());
$this->assertEquals(2, $mock->foo());
Expand All @@ -73,9 +70,8 @@ public function testWillReturnByReference(): void
->setMethods(['foo'])
->getMock();

$mock->expects($this->any())
->method('foo')
->willReturnReference($value);
$mock->method('foo')
->willReturnReference($value);

$this->assertNull($mock->foo());
$value = 'foo';
Expand Down Expand Up @@ -162,9 +158,8 @@ public function testWillReturnValidType(): void
$mock = $this->getMockBuilder(ClassWithAllPossibleReturnTypes::class)
->getMock();

$mock->expects($this->any())
->method('methodWithBoolReturnTypeDeclaration')
->willReturn(true);
$mock->method('methodWithBoolReturnTypeDeclaration')
->willReturn(true);

$this->assertEquals(true, $mock->methodWithBoolReturnTypeDeclaration());
}
Expand All @@ -174,9 +169,8 @@ public function testWillReturnValidTypeForLowercaseCall(): void
$mock = $this->getMockBuilder(ClassWithAllPossibleReturnTypes::class)
->getMock();

$mock->expects($this->any())
->method('methodWithBoolReturnTypeDeclaration')
->willReturn(true);
$mock->method('methodWithBoolReturnTypeDeclaration')
->willReturn(true);

$this->assertEquals(true, $mock->methodwithboolreturntypedeclaration());
}
Expand All @@ -186,9 +180,8 @@ public function testWillReturnValidTypeForLowercaseMethod(): void
$mock = $this->getMockBuilder(ClassWithAllPossibleReturnTypes::class)
->getMock();

$mock->expects($this->any())
->method('methodwithboolreturntypedeclaration')
->willReturn(true);
$mock->method('methodwithboolreturntypedeclaration')
->willReturn(true);

$this->assertEquals(true, $mock->methodWithBoolReturnTypeDeclaration());
}
Expand Down Expand Up @@ -246,13 +239,11 @@ public function testWillReturnAlreadyInstantiatedStubs(): void
->setMethods(['foo', 'bar'])
->getMock();

$mock->expects($this->any())
->method('foo')
->willReturn(new ReturnStub('foo'));
$mock->method('foo')
->willReturn(new ReturnStub('foo'));

$mock->expects($this->any())
->method('bar')
->willReturn(new ReturnSelf());
$mock->method('bar')
->willReturn(new ReturnSelf());

$this->assertSame('foo', $mock->foo());
$this->assertSame($mock, $mock->bar());
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/Framework/MockObject/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public function testGetMockForAbstractClassShouldCreateStubsOnlyForAbstractMetho
{
$mock = $this->generator->getMockForAbstractClass(AbstractMockTestClass::class);

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->willReturn('testing');

$this->assertEquals('testing', $mock->doSomething());
Expand Down Expand Up @@ -198,7 +197,7 @@ public function testGetMockForSingletonWithReflectionSuccess(): void
{
$mock = $this->generator->getMock(SingletonClass::class, ['doSomething'], [], '', false);

$this->assertInstanceOf('SingletonClass', $mock);
$this->assertInstanceOf(SingletonClass::class, $mock);
}

public function testExceptionIsRaisedForMutuallyExclusiveOptions(): void
Expand Down
12 changes: 5 additions & 7 deletions tests/unit/Framework/MockObject/InvocationHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ public function testNonUniqueMatchThrowsException(): void
->addMethods(['foo'])
->getMock();

$mock->expects($this->any())
->method($this->stringStartsWith('foo'))
->willReturn('result');
$mock->method($this->stringStartsWith('foo'))
->willReturn('result');

$mock->expects($this->any())
->method('foo')
->with('bar')
->willReturn('result');
$mock->method('foo')
->with('bar')
->willReturn('result');

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('More than one invocation handler has been configured for stdClass::foo()');
Expand Down
59 changes: 20 additions & 39 deletions tests/unit/Framework/MockObject/MockObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public function testMockedMethodIsNotCalledWhenExpectsAnyWithParameter(): void
$mock = $this->getMockBuilder(SomeClass::class)
->getMock();

$mock->expects($this->any())
->method('doSomethingElse')
$mock->method('doSomethingElse')
->with('someArg');
}

Expand Down Expand Up @@ -172,8 +171,7 @@ public function testStubbedException(): void
$mock = $this->getMockBuilder(AnInterface::class)
->getMock();

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->will($this->throwException(new \Exception));

$this->expectException(\Exception::class);
Expand All @@ -186,8 +184,7 @@ public function testStubbedWillThrowException(): void
$mock = $this->getMockBuilder(AnInterface::class)
->getMock();

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->willThrowException(new \Exception);

$this->expectException(\Exception::class);
Expand All @@ -200,17 +197,15 @@ public function testStubbedReturnValue(): void
$mock = $this->getMockBuilder(AnInterface::class)
->getMock();

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->will($this->returnValue('something'));

$this->assertEquals('something', $mock->doSomething());

$mock = $this->getMockBuilder(AnInterface::class)
->getMock();

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->willReturn('something');

$this->assertEquals('something', $mock->doSomething());
Expand All @@ -226,8 +221,7 @@ public function testStubbedReturnValueMap(): void
$mock = $this->getMockBuilder(AnInterface::class)
->getMock();

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->will($this->returnValueMap($map));

$this->assertEquals('d', $mock->doSomething('a', 'b', 'c'));
Expand All @@ -237,8 +231,7 @@ public function testStubbedReturnValueMap(): void
$mock = $this->getMockBuilder(AnInterface::class)
->getMock();

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->willReturnMap($map);

$this->assertEquals('d', $mock->doSomething('a', 'b', 'c'));
Expand All @@ -251,17 +244,15 @@ public function testStubbedReturnArgument(): void
$mock = $this->getMockBuilder(AnInterface::class)
->getMock();

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->will($this->returnArgument(1));

$this->assertEquals('b', $mock->doSomething('a', 'b'));

$mock = $this->getMockBuilder(AnInterface::class)
->getMock();

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->willReturnArgument(1);

$this->assertEquals('b', $mock->doSomething('a', 'b'));
Expand All @@ -275,7 +266,7 @@ public function testFunctionCallback(): void

$mock->expects($this->once())
->method('doSomething')
->will($this->returnCallback('FunctionCallbackWrapper::functionCallback'));
->willReturnCallback('FunctionCallbackWrapper::functionCallback');

$this->assertEquals('pass', $mock->doSomething('foo', 'bar'));

Expand All @@ -295,17 +286,15 @@ public function testStubbedReturnSelf(): void
$mock = $this->getMockBuilder(AnInterface::class)
->getMock();

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->will($this->returnSelf());

$this->assertEquals($mock, $mock->doSomething());

$mock = $this->getMockBuilder(AnInterface::class)
->getMock();

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->willReturnSelf();

$this->assertEquals($mock, $mock->doSomething());
Expand All @@ -316,8 +305,7 @@ public function testStubbedReturnOnConsecutiveCalls(): void
$mock = $this->getMockBuilder(AnInterface::class)
->getMock();

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->will($this->onConsecutiveCalls('a', 'b', 'c'));

$this->assertEquals('a', $mock->doSomething());
Expand All @@ -327,8 +315,7 @@ public function testStubbedReturnOnConsecutiveCalls(): void
$mock = $this->getMockBuilder(AnInterface::class)
->getMock();

$mock->expects($this->any())
->method('doSomething')
$mock->method('doSomething')
->willReturnOnConsecutiveCalls('a', 'b', 'c');

$this->assertEquals('a', $mock->doSomething());
Expand Down Expand Up @@ -586,8 +573,7 @@ public function testObjectMethodCallWithArgumentCloningEnabled(): void

$actualArguments = [];

$mock->expects($this->any())
->method('doSomethingElse')
$mock->method('doSomethingElse')
->will(
$this->returnCallback(
function () use (&$actualArguments): void {
Expand All @@ -614,8 +600,7 @@ public function testObjectMethodCallWithArgumentCloningDisabled(): void

$actualArguments = [];

$mock->expects($this->any())
->method('doSomethingElse')
$mock->method('doSomethingElse')
->will(
$this->returnCallback(
function () use (&$actualArguments): void {
Expand Down Expand Up @@ -823,8 +808,7 @@ public function testMockArgumentsPassedByReference(): void
->disableArgumentCloning()
->getMock();

$foo->expects($this->any())
->method('bar')
$foo->method('bar')
->will($this->returnCallback([$foo, 'callback']));

$a = $b = $c = 0;
Expand All @@ -844,8 +828,7 @@ public function testMockArgumentsPassedByReference2(): void
->disableArgumentCloning()
->getMock();

$foo->expects($this->any())
->method('bar')
$foo->method('bar')
->will($this->returnCallback(
function (&$a, &$b, $c): void {
$b = 1;
Expand Down Expand Up @@ -873,8 +856,7 @@ public function testMockArgumentsPassedByReference3(): void
$a = new stdClass;
$b = $c = 0;

$foo->expects($this->any())
->method('bar')
$foo->method('bar')
->with($a, $b, $c)
->will($this->returnCallback([$foo, 'callback']));

Expand All @@ -895,8 +877,7 @@ public function testMockArgumentsPassedByReference4(): void
$a = new stdClass;
$b = $c = 0;

$foo->expects($this->any())
->method('bar')
$foo->method('bar')
->with($this->isInstanceOf(stdClass::class), $b, $c)
->will($this->returnCallback([$foo, 'callback']));

Expand Down
Loading

0 comments on commit 2a37f33

Please sign in to comment.