From c1a2c7141596adee984b306f425f762fcd756488 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Wed, 24 Aug 2022 07:35:48 -0400 Subject: [PATCH] Remove workarounds for unsupported HHVM And clean up redundant test case `@requires`, composer.json requires php 7.2. See #561 --- .../ClassPatch/HhvmExceptionPatchSpec.php | 34 ---------- .../Doubler/ClassPatch/HhvmExceptionPatch.php | 63 ------------------- src/Prophecy/Prophet.php | 1 - src/Prophecy/Util/ExportUtil.php | 12 ---- tests/Doubler/Generator/ClassMirrorTest.php | 12 +--- 5 files changed, 1 insertion(+), 121 deletions(-) delete mode 100644 spec/Prophecy/Doubler/ClassPatch/HhvmExceptionPatchSpec.php delete mode 100644 src/Prophecy/Doubler/ClassPatch/HhvmExceptionPatch.php diff --git a/spec/Prophecy/Doubler/ClassPatch/HhvmExceptionPatchSpec.php b/spec/Prophecy/Doubler/ClassPatch/HhvmExceptionPatchSpec.php deleted file mode 100644 index 9d04421af..000000000 --- a/spec/Prophecy/Doubler/ClassPatch/HhvmExceptionPatchSpec.php +++ /dev/null @@ -1,34 +0,0 @@ -shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface'); - } - - function its_priority_is_minus_50() - { - $this->getPriority()->shouldReturn(-50); - } - - function it_uses_parent_code_for_setTraceOptions(ClassNode $node, MethodNode $method, MethodNode $getterMethod) - { - $node->hasMethod('setTraceOptions')->willReturn(true); - $node->getMethod('setTraceOptions')->willReturn($method); - $node->hasMethod('getTraceOptions')->willReturn(true); - $node->getMethod('getTraceOptions')->willReturn($getterMethod); - - $method->useParentCode()->shouldBeCalled(); - $getterMethod->useParentCode()->shouldBeCalled(); - - $this->apply($node); - } -} diff --git a/src/Prophecy/Doubler/ClassPatch/HhvmExceptionPatch.php b/src/Prophecy/Doubler/ClassPatch/HhvmExceptionPatch.php deleted file mode 100644 index fa38fc0d1..000000000 --- a/src/Prophecy/Doubler/ClassPatch/HhvmExceptionPatch.php +++ /dev/null @@ -1,63 +0,0 @@ - - * Marcello Duarte - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Prophecy\Doubler\ClassPatch; - -use Prophecy\Doubler\Generator\Node\ClassNode; - -/** - * Exception patch for HHVM to remove the stubs from special methods - * - * @author Christophe Coevoet - */ -class HhvmExceptionPatch implements ClassPatchInterface -{ - /** - * Supports exceptions on HHVM. - * - * @param ClassNode $node - * - * @return bool - */ - public function supports(ClassNode $node) - { - if (!defined('HHVM_VERSION')) { - return false; - } - - return 'Exception' === $node->getParentClass() || is_subclass_of($node->getParentClass(), 'Exception'); - } - - /** - * Removes special exception static methods from the doubled methods. - * - * @param ClassNode $node - * - * @return void - */ - public function apply(ClassNode $node) - { - if ($node->hasMethod('setTraceOptions')) { - $node->getMethod('setTraceOptions')->useParentCode(); - } - if ($node->hasMethod('getTraceOptions')) { - $node->getMethod('getTraceOptions')->useParentCode(); - } - } - - /** - * {@inheritdoc} - */ - public function getPriority() - { - return -50; - } -} diff --git a/src/Prophecy/Prophet.php b/src/Prophecy/Prophet.php index d37c92a34..15a4969dc 100644 --- a/src/Prophecy/Prophet.php +++ b/src/Prophecy/Prophet.php @@ -59,7 +59,6 @@ public function __construct( $doubler->registerClassPatch(new ClassPatch\DisableConstructorPatch); $doubler->registerClassPatch(new ClassPatch\ProphecySubjectPatch); $doubler->registerClassPatch(new ClassPatch\ReflectionClassNewInstancePatch); - $doubler->registerClassPatch(new ClassPatch\HhvmExceptionPatch()); $doubler->registerClassPatch(new ClassPatch\MagicCallPatch); $doubler->registerClassPatch(new ClassPatch\KeywordPatch); } diff --git a/src/Prophecy/Util/ExportUtil.php b/src/Prophecy/Util/ExportUtil.php index 0c66cba04..e3a02c031 100644 --- a/src/Prophecy/Util/ExportUtil.php +++ b/src/Prophecy/Util/ExportUtil.php @@ -78,18 +78,6 @@ public static function toArray($value) // above (fast) mechanism nor with reflection in Zend. // Format the output similarly to print_r() in this case if ($value instanceof \SplObjectStorage) { - // However, the fast method does work in HHVM, and exposes the - // internal implementation. Hide it again. - if (property_exists('\SplObjectStorage', '__storage')) { - unset($array['__storage']); - } elseif (property_exists('\SplObjectStorage', 'storage')) { - unset($array['storage']); - } - - if (property_exists('\SplObjectStorage', '__key')) { - unset($array['__key']); - } - foreach ($value as $key => $val) { // Use the same identifier that would be printed alongside the object's representation elsewhere. $array[spl_object_id($val)] = array( diff --git a/tests/Doubler/Generator/ClassMirrorTest.php b/tests/Doubler/Generator/ClassMirrorTest.php index 03f5964ec..18c966837 100644 --- a/tests/Doubler/Generator/ClassMirrorTest.php +++ b/tests/Doubler/Generator/ClassMirrorTest.php @@ -123,7 +123,6 @@ public function it_properly_reads_methods_arguments_with_types() /** * @test - * @requires PHP 5.4 */ public function it_properly_reads_methods_arguments_with_callable_types() { @@ -153,7 +152,6 @@ public function it_properly_reads_methods_arguments_with_callable_types() /** * @test - * @requires PHP 5.6 */ public function it_properly_reads_methods_variadic_arguments() { @@ -176,14 +174,9 @@ public function it_properly_reads_methods_variadic_arguments() /** * @test - * @requires PHP 5.6 */ public function it_properly_reads_methods_typehinted_variadic_arguments() { - if (defined('HHVM_VERSION_ID')) { - $this->markTestSkipped('HHVM does not support typehints on variadic arguments.'); - } - $class = new \ReflectionClass('Fixtures\Prophecy\WithTypehintedVariadicArgument'); $mirror = new ClassMirror(); @@ -337,7 +330,6 @@ public function it_does_not_throw_exception_for_virtually_private_finals() /** * @test - * @requires PHP 7 */ public function it_reflects_return_typehints() { @@ -418,7 +410,6 @@ public function it_doesnt_fail_to_typehint_nonexistent_FQCN() /** * @test - * @requires PHP 7.1 */ public function it_doesnt_fail_on_array_nullable_parameter_with_not_null_default_value() { @@ -445,7 +436,6 @@ public function it_doesnt_fail_to_typehint_nonexistent_RQCN() /** * @test - * @requires PHP 7.2 */ function it_doesnt_fail_when_method_is_extended_with_more_params() { @@ -614,7 +604,7 @@ public function it_can_not_double_an_enum() } $this->expectException(ClassMirrorException::class); - + $classNode = (new ClassMirror())->reflect(new \ReflectionClass('Fixtures\Prophecy\Enum'), []); }