Skip to content

Commit c37517f

Browse files
authored
Merge pull request #3 from cspray/bug/fix-stop-intercepting-not-remove-filter
Make sure to remove filter when stop intercepting
2 parents f9fe026 + 8075a74 commit c37517f

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

.github/workflows/ci.yml

+16-10
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@ on:
77
branches: [ main ]
88

99
jobs:
10-
continuous-integration:
11-
10+
unit-testing:
1211
runs-on: ubuntu-latest
1312

14-
env:
15-
XDEBUG_MODE: coverage
16-
1713
steps:
1814
- uses: actions/checkout@v3
19-
- name: Composer
20-
uses: php-actions/composer@v6
21-
- name: Tests
22-
uses: php-actions/phpunit@v3
15+
- name: Setup PHP
16+
uses: shivammathur/setup-php@v2
2317
with:
24-
php_extensions: "xdebug"
18+
php-version: 8.2
19+
extensions: xdebug
20+
tools: composer:2
21+
- name: Setup problem matchers for PHP
22+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
23+
- name: Setup problem matchers for PHPUnit
24+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
25+
- name: Composer
26+
run: composer install
27+
- name: Unit Testing
28+
env:
29+
XDEBUG_MODE: coverage
30+
run: ./vendor/bin/phpunit

src/StreamFilter.php

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function() use($bufferId) : void {
6161
if (!isset(self::$cache[$bufferId])) {
6262
throw BufferNotFound::fromStopInterceptingMissingBuffer();
6363
}
64+
stream_filter_remove(self::$cache[$bufferId]['filter']);
6465
unset(self::$cache[$bufferId]);
6566
}
6667
) implements Buffer {

tests/StreamFilterTest.php

+14-13
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public function testRegisterAddsAppropriateFilter() : void {
5858
);
5959
}
6060

61-
#[RunInSeparateProcess]
6261
public function testInterceptAddsBuffers() : void {
6362
StreamFilter::register();
6463

@@ -71,7 +70,6 @@ public function testInterceptAddsBuffers() : void {
7170
self::assertContainsEquals($buffer, $buffers);
7271
}
7372

74-
#[RunInSeparateProcess]
7573
public function testResetAllResetsBuffersToEmptyCollection() : void {
7674
StreamFilter::register();
7775

@@ -87,7 +85,6 @@ public function testResetAllResetsBuffersToEmptyCollection() : void {
8785

8886
}
8987

90-
#[RunInSeparateProcess]
9188
public function testWritingToInterceptedStreamAddedToCorrectOutput() : void {
9289
StreamFilter::register();
9390

@@ -101,7 +98,6 @@ public function testWritingToInterceptedStreamAddedToCorrectOutput() : void {
10198
);
10299
}
103100

104-
#[RunInSeparateProcess]
105101
public function testResetIndividualBufferClearsToEmptyString() : void {
106102
StreamFilter::register();
107103

@@ -116,7 +112,6 @@ public function testResetIndividualBufferClearsToEmptyString() : void {
116112
self::assertSame('', $buffer->output());
117113
}
118114

119-
#[RunInSeparateProcess]
120115
public function testStopInterceptingRemovesBufferedResourceFromCache() : void {
121116
StreamFilter::register();
122117

@@ -129,7 +124,6 @@ public function testStopInterceptingRemovesBufferedResourceFromCache() : void {
129124
self::assertSame([], StreamFilter::buffers());
130125
}
131126

132-
#[RunInSeparateProcess]
133127
public function testStopInterceptingBufferIdentifierNotFoundThrowsException() : void {
134128
StreamFilter::register();
135129

@@ -142,7 +136,6 @@ public function testStopInterceptingBufferIdentifierNotFoundThrowsException() :
142136
$buffer->stopIntercepting();
143137
}
144138

145-
#[RunInSeparateProcess]
146139
public function testOutputForBufferStoppedInterceptingThrowsException() : void {
147140
StreamFilter::register();
148141

@@ -156,7 +149,6 @@ public function testOutputForBufferStoppedInterceptingThrowsException() : void {
156149
$buffer->output();
157150
}
158151

159-
#[RunInSeparateProcess]
160152
public function testResetForBufferNotFoundThrowsException() : void {
161153
StreamFilter::register();
162154

@@ -170,7 +162,6 @@ public function testResetForBufferNotFoundThrowsException() : void {
170162
$buffer->reset();
171163
}
172164

173-
#[RunInSeparateProcess]
174165
public function testInterceptOptionsDefaultDoesNotHaveContentsInResource() : void {
175166
StreamFilter::register();
176167

@@ -184,7 +175,6 @@ public function testInterceptOptionsDefaultDoesNotHaveContentsInResource() : voi
184175
self::assertSame('', stream_get_contents($this->resource));
185176
}
186177

187-
#[RunInSeparateProcess]
188178
public function testInterceptOptionsTrapDoesNotHaveContentsInResource() : void {
189179
StreamFilter::register();
190180

@@ -198,7 +188,6 @@ public function testInterceptOptionsTrapDoesNotHaveContentsInResource() : void {
198188
self::assertSame('', stream_get_contents($this->resource));
199189
}
200190

201-
#[RunInSeparateProcess]
202191
public function testInterceptOptionsPassThruDoesHaveContentsInResource() : void {
203192
StreamFilter::register();
204193

@@ -212,7 +201,6 @@ public function testInterceptOptionsPassThruDoesHaveContentsInResource() : void
212201
self::assertSame('Content written to stream', stream_get_contents($this->resource));
213202
}
214203

215-
#[RunInSeparateProcess]
216204
public function testInterceptOptionsFatalErrorThrowsError() : void {
217205
StreamFilter::register();
218206

@@ -226,7 +214,6 @@ public function testInterceptOptionsFatalErrorThrowsError() : void {
226214
self::assertSame('', stream_get_contents($this->resource));
227215
}
228216

229-
#[RunInSeparateProcess]
230217
public function testWritingToSeparateStreams() : void {
231218
StreamFilter::register();
232219

@@ -240,4 +227,18 @@ public function testWritingToSeparateStreams() : void {
240227
self::assertSame('stdout output', $stdout->output());
241228
}
242229

230+
public function testInterceptingStoppingAndStartingAgainDoesNotResultInNullPointer() : void {
231+
StreamFilter::register();
232+
233+
$buffer = StreamFilter::intercept($this->resource);
234+
$buffer->stopIntercepting();
235+
236+
$buffer = StreamFilter::intercept($this->resource);
237+
fwrite($this->resource, 'Some content');
238+
239+
self::assertSame('Some content', $buffer->output());
240+
241+
$buffer->stopIntercepting();
242+
}
243+
243244
}

0 commit comments

Comments
 (0)