From f60bb61f81bd89cbea01adcf379aa046085015a8 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Mon, 10 Jan 2022 20:17:09 -0500 Subject: [PATCH 1/4] Add tests and fixtures Signed-off-by: Nathanael Esayeas --- .../Fixtures/MethodWithStaticReturnType.php | 30 +++++++++++++++ ...MockingMethodsWithStaticReturnTypeTest.php | 37 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 tests/Mockery/Fixtures/MethodWithStaticReturnType.php create mode 100644 tests/Mockery/MockingMethodsWithStaticReturnTypeTest.php diff --git a/tests/Mockery/Fixtures/MethodWithStaticReturnType.php b/tests/Mockery/Fixtures/MethodWithStaticReturnType.php new file mode 100644 index 000000000..4ec926ac6 --- /dev/null +++ b/tests/Mockery/Fixtures/MethodWithStaticReturnType.php @@ -0,0 +1,30 @@ +shouldReceive("returnType"); + + $this->assertSame($mock, $mock->returnType()); + } +} From 037705d23e25c34bb07614cc99ecfe103135aea7 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Mon, 10 Jan 2022 20:18:28 -0500 Subject: [PATCH 2/4] Mock method with static return type Signed-off-by: Nathanael Esayeas --- library/Mockery/Mock.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/Mockery/Mock.php b/library/Mockery/Mock.php index d6ac4ff42..2a7e43907 100644 --- a/library/Mockery/Mock.php +++ b/library/Mockery/Mock.php @@ -747,6 +747,9 @@ public function mockery_returnValueForMethod($name) case 'void': return null; + case 'static': + return $this; + case 'object': $mock = \Mockery::mock(); if ($this->_mockery_ignoreMissingRecursive) { From 4461cf1b2ee36d16ffeec983d70499696df01138 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Mon, 10 Jan 2022 23:15:02 -0500 Subject: [PATCH 3/4] Requires PHP 8 Signed-off-by: Nathanael Esayeas --- tests/Mockery/Fixtures/MethodWithStaticReturnType.php | 10 ++++++---- .../Mockery/MockingMethodsWithStaticReturnTypeTest.php | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/Mockery/Fixtures/MethodWithStaticReturnType.php b/tests/Mockery/Fixtures/MethodWithStaticReturnType.php index 4ec926ac6..eabc1e1ab 100644 --- a/tests/Mockery/Fixtures/MethodWithStaticReturnType.php +++ b/tests/Mockery/Fixtures/MethodWithStaticReturnType.php @@ -21,10 +21,12 @@ namespace test\Mockery\Fixtures; -class MethodWithStaticReturnType -{ - public function returnType(): static +if (\PHP_VERSION_ID >= 80000) { + class MethodWithStaticReturnType { - return $this; + public function returnType(): static + { + return $this; + } } } diff --git a/tests/Mockery/MockingMethodsWithStaticReturnTypeTest.php b/tests/Mockery/MockingMethodsWithStaticReturnTypeTest.php index 52b04e795..a7afae702 100644 --- a/tests/Mockery/MockingMethodsWithStaticReturnTypeTest.php +++ b/tests/Mockery/MockingMethodsWithStaticReturnTypeTest.php @@ -28,6 +28,10 @@ class MockingMethodsWithStaticReturnTypeTest extends MockeryTestCase { public function testMockingStaticReturnType() { + if (\PHP_VERSION_ID < 80000) { + $this->markTestSkipped('Requires PHP >= 8'); + } + $mock = mock(MethodWithStaticReturnType::class); $mock->shouldReceive("returnType"); From 66c767fa6834a4c7b2b6bf1f5d9d8434bf9e542b Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Mon, 10 Jan 2022 23:17:42 -0500 Subject: [PATCH 4/4] Fix StyleCI issues Signed-off-by: Nathanael Esayeas --- library/Mockery/Mock.php | 2 +- tests/Mockery/MockingMethodsWithStaticReturnTypeTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/Mockery/Mock.php b/library/Mockery/Mock.php index 2a7e43907..4605bef80 100644 --- a/library/Mockery/Mock.php +++ b/library/Mockery/Mock.php @@ -749,7 +749,7 @@ public function mockery_returnValueForMethod($name) case 'static': return $this; - + case 'object': $mock = \Mockery::mock(); if ($this->_mockery_ignoreMissingRecursive) { diff --git a/tests/Mockery/MockingMethodsWithStaticReturnTypeTest.php b/tests/Mockery/MockingMethodsWithStaticReturnTypeTest.php index a7afae702..774dc90ee 100644 --- a/tests/Mockery/MockingMethodsWithStaticReturnTypeTest.php +++ b/tests/Mockery/MockingMethodsWithStaticReturnTypeTest.php @@ -31,7 +31,7 @@ public function testMockingStaticReturnType() if (\PHP_VERSION_ID < 80000) { $this->markTestSkipped('Requires PHP >= 8'); } - + $mock = mock(MethodWithStaticReturnType::class); $mock->shouldReceive("returnType");