Skip to content

Commit

Permalink
Fix memory leak in silent method
Browse files Browse the repository at this point in the history
  • Loading branch information
almasaeed2010 committed Aug 10, 2018
1 parent e469f7f commit 8654968
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Services/SilentResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function startBuffer()
$this->content = '';

ob_start(function ($buffer) {
$this->content .= $buffer;
$this->content = $buffer;
});

putenv('TRIPAL_SUPPRESS_ERRORS=TRUE');
Expand Down

0 comments on commit 8654968

Please sign in to comment.