diff --git a/src/Framework/MockObject/MockBuilder.php b/src/Framework/MockObject/MockBuilder.php index 73a34a4e3f4..8c884a45fd0 100644 --- a/src/Framework/MockObject/MockBuilder.php +++ b/src/Framework/MockObject/MockBuilder.php @@ -207,6 +207,12 @@ public function setMethods(array $methods = null): self */ public function onlyMethods(array $methods): self { + if (!$methods) { + $this->methods = null; + + return $this; + } + if ($this->alreadyUsedMockMethodConfiguration) { throw new RuntimeException( \sprintf( @@ -254,6 +260,12 @@ public function onlyMethods(array $methods): self */ public function addMethods(array $methods): self { + if (!$methods) { + $this->methods = null; + + return $this; + } + if ($this->alreadyUsedMockMethodConfiguration) { throw new RuntimeException( \sprintf( diff --git a/tests/unit/Framework/MockObject/MockBuilderTest.php b/tests/unit/Framework/MockObject/MockBuilderTest.php index f7034ac8981..12ff2e19717 100644 --- a/tests/unit/Framework/MockObject/MockBuilderTest.php +++ b/tests/unit/Framework/MockObject/MockBuilderTest.php @@ -79,6 +79,15 @@ public function testOnlyMethodsWithExistingMethodNames(): void $this->assertTrue($mock->anotherMockableMethod()); } + public function testOnlyMethodsWithBlankArray(): void + { + $mock = $this->getMockBuilder(Mockable::class) + ->onlyMethods([]) + ->getMock(); + + $this->assertTrue($mock->mockableMethod()); + } + public function testAddMethodsWithNonExistentMethodNames(): void { $this->expectException(RuntimeException::class); @@ -98,6 +107,15 @@ public function testAddMethodsWithExistingMethodNames(): void $this->assertTrue($mock->anotherMockableMethod()); } + public function testAddMethodsWithBlankArray(): void + { + $mock = $this->getMockBuilder(Mockable::class) + ->addMethods([]) + ->getMock(); + + $this->assertTrue($mock->mockableMethod()); + } + public function testEmptyMethodExceptionsToMockCanBeSpecified(): void { $mock = $this->getMockBuilder(Mockable::class)