From e6e2cb3166eafa28ff7eb70c77ae0fa87237a04a Mon Sep 17 00:00:00 2001 From: Erin Millard Date: Fri, 18 Mar 2016 11:07:08 +1000 Subject: [PATCH] Fix for segfault/memleak issues under PHP 7. Closes #143. --- CHANGELOG.md | 2 ++ src/Stub/Stub.php | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4da8c8250..9b2f932bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,12 @@ - **[NEW]** Implemented generator stubs ([#11]). - **[IMPROVED]** More default values for built-in return types ([#138], [#139]). +- **[FIXED]** Fixed memory leak under PHP 7 ([#143]). [#11]: https://github.com/eloquent/phony/issues/11 [#138]: https://github.com/eloquent/phony/issues/138 [#139]: https://github.com/eloquent/phony/pull/139 +[#143]: https://github.com/eloquent/phony/issues/143 ## 0.8.0 (2016-02-12) diff --git a/src/Stub/Stub.php b/src/Stub/Stub.php index 98286a99c..fb6273f7b 100644 --- a/src/Stub/Stub.php +++ b/src/Stub/Stub.php @@ -11,6 +11,7 @@ namespace Eloquent\Phony\Stub; +use Eloquent\Phony\Assertion\Renderer\AssertionRenderer; use Eloquent\Phony\Call\Argument\Arguments; use Eloquent\Phony\Call\Argument\ArgumentsInterface; use Eloquent\Phony\Invocation\AbstractWrappedInvocable; @@ -132,10 +133,16 @@ public function __construct( */ public function __destruct() { - try { - $this->closeRule(); - } catch (Exception $e) { - printf("WARNING: %s\n", $e->getMessage()); + if (!$this->answers && null !== $this->criteria) { + printf( + 'WARNING: Stub criteria %s were never used. ' . + "Check for incomplete stub rules.\n", + var_export( + AssertionRenderer::instance() + ->renderMatchers($this->criteria), + true + ) + ); } }