Skip to content

Commit

Permalink
Merge pull request #3 from cspray/bug/fix-stop-intercepting-not-remov…
Browse files Browse the repository at this point in the history
…e-filter

Make sure to remove filter when stop intercepting
  • Loading branch information
cspray committed Jun 15, 2024
2 parents f9fe026 + 8075a74 commit c37517f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
26 changes: 16 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ on:
branches: [ main ]

jobs:
continuous-integration:

unit-testing:
runs-on: ubuntu-latest

env:
XDEBUG_MODE: coverage

steps:
- uses: actions/checkout@v3
- name: Composer
uses: php-actions/composer@v6
- name: Tests
uses: php-actions/phpunit@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php_extensions: "xdebug"
php-version: 8.2
extensions: xdebug
tools: composer:2
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Composer
run: composer install
- name: Unit Testing
env:
XDEBUG_MODE: coverage
run: ./vendor/bin/phpunit
1 change: 1 addition & 0 deletions src/StreamFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function() use($bufferId) : void {
if (!isset(self::$cache[$bufferId])) {
throw BufferNotFound::fromStopInterceptingMissingBuffer();
}
stream_filter_remove(self::$cache[$bufferId]['filter']);
unset(self::$cache[$bufferId]);
}
) implements Buffer {
Expand Down
27 changes: 14 additions & 13 deletions tests/StreamFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public function testRegisterAddsAppropriateFilter() : void {
);
}

#[RunInSeparateProcess]
public function testInterceptAddsBuffers() : void {
StreamFilter::register();

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

#[RunInSeparateProcess]
public function testResetAllResetsBuffersToEmptyCollection() : void {
StreamFilter::register();

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

}

#[RunInSeparateProcess]
public function testWritingToInterceptedStreamAddedToCorrectOutput() : void {
StreamFilter::register();

Expand All @@ -101,7 +98,6 @@ public function testWritingToInterceptedStreamAddedToCorrectOutput() : void {
);
}

#[RunInSeparateProcess]
public function testResetIndividualBufferClearsToEmptyString() : void {
StreamFilter::register();

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

#[RunInSeparateProcess]
public function testStopInterceptingRemovesBufferedResourceFromCache() : void {
StreamFilter::register();

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

#[RunInSeparateProcess]
public function testStopInterceptingBufferIdentifierNotFoundThrowsException() : void {
StreamFilter::register();

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

#[RunInSeparateProcess]
public function testOutputForBufferStoppedInterceptingThrowsException() : void {
StreamFilter::register();

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

#[RunInSeparateProcess]
public function testResetForBufferNotFoundThrowsException() : void {
StreamFilter::register();

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

#[RunInSeparateProcess]
public function testInterceptOptionsDefaultDoesNotHaveContentsInResource() : void {
StreamFilter::register();

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

#[RunInSeparateProcess]
public function testInterceptOptionsTrapDoesNotHaveContentsInResource() : void {
StreamFilter::register();

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

#[RunInSeparateProcess]
public function testInterceptOptionsPassThruDoesHaveContentsInResource() : void {
StreamFilter::register();

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

#[RunInSeparateProcess]
public function testInterceptOptionsFatalErrorThrowsError() : void {
StreamFilter::register();

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

#[RunInSeparateProcess]
public function testWritingToSeparateStreams() : void {
StreamFilter::register();

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

public function testInterceptingStoppingAndStartingAgainDoesNotResultInNullPointer() : void {
StreamFilter::register();

$buffer = StreamFilter::intercept($this->resource);
$buffer->stopIntercepting();

$buffer = StreamFilter::intercept($this->resource);
fwrite($this->resource, 'Some content');

self::assertSame('Some content', $buffer->output());

$buffer->stopIntercepting();
}

}

0 comments on commit c37517f

Please sign in to comment.