From 865496817647d36e5aa3cb217ab2f5ceefcda4be Mon Sep 17 00:00:00 2001 From: Abdullah Almsaeed Date: Fri, 10 Aug 2018 15:20:38 -0400 Subject: [PATCH] Fix memory leak in silent method --- README.md | 6 ++++-- src/Services/SilentResponse.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4cc8377..bdd9457 100644 --- a/README.md +++ b/README.md @@ -440,8 +440,7 @@ $output = ob_get_contents(); // Clean the buffer and unset tripal errors suppression ob_end_clean(); putenv("TRIPAL_SUPPRESS_ERRORS"); -``` -**Note**: the above code will **not** work with large strings. +``` However, TripalTestSuite provides a `silent()` method that automates this process, provides helpful assertions and supports larger strings. Example usage: @@ -452,6 +451,9 @@ $output = silent(function() { }); $output->assertSee('testing'); // true! ``` +**WARNING:** This method has a maximum string size to avoid memory leaks. The size is set in PHP's ini file +as `output_buffering`, which by default is set to 4KB. If you would like to collect larger strings, you must +adjust your PHP settings. #### Assertions and Methods The silent method returns a SilentResponse which provides the following methods. diff --git a/src/Services/SilentResponse.php b/src/Services/SilentResponse.php index 63a3cd3..1609fa7 100644 --- a/src/Services/SilentResponse.php +++ b/src/Services/SilentResponse.php @@ -85,7 +85,7 @@ protected function startBuffer() $this->content = ''; ob_start(function ($buffer) { - $this->content .= $buffer; + $this->content = $buffer; }); putenv('TRIPAL_SUPPRESS_ERRORS=TRUE');