Skip to content

Commit

Permalink
Merge pull request #19 from icewind1991/countwrapper-seek
Browse files Browse the repository at this point in the history
handle seeks in countwrapper
  • Loading branch information
icewind1991 authored Dec 5, 2024
2 parents 89a8191 + 7ad8ece commit cb2bd3e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ name: CI
jobs:
php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.3'
- name: PHP-CS-Fixer
uses: OskarStark/[email protected]
with:
args: --diff --dry-run --allow-risky yes --stop-on-violation --using-cache=no --path-mode=intersection

phpstan:
name: PHPStan Static Analysis
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.3'
- name: Composer
run: composer install
- env:
BACKEND: smbclient
run: php ./vendor/bin/phpstan analyse --level 5 src

phpunit:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
name: Unit tests

strategy:
Expand All @@ -45,9 +45,13 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -62,7 +66,7 @@ jobs:
files: ./coverage.xml

phpunit-8:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
name: Unit tests

strategy:
Expand All @@ -72,7 +76,7 @@ jobs:
- "7.2"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand Down
11 changes: 11 additions & 0 deletions src/CountWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ protected function open() {
return true;
}

public function stream_seek($offset, $whence = SEEK_SET) {
if ($whence === SEEK_SET) {
$this->readCount = $offset;
$this->writeCount = $offset;
} else if ($whence === SEEK_CUR) {
$this->readCount += $offset;
$this->writeCount += $offset;
}
return parent::stream_seek($offset, $whence);
}

public function dir_opendir($path, $options) {
return $this->open();
}
Expand Down
18 changes: 18 additions & 0 deletions tests/CountWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,22 @@ public function testWriteCount() {
fclose($wrapped);
$this->assertSame(6, $count);
}

public function testReadCountSeek() {
$count = 0;

$source = fopen('php://temp', 'r+');
fwrite($source, 'foobar');
rewind($source);

$wrapped = CountWrapper::wrap($source, function ($readCount) use (&$count) {
$count = $readCount;
});

stream_get_contents($wrapped);
fseek($wrapped, 3);
stream_get_contents($wrapped);
fclose($wrapped);
$this->assertSame(6, $count);
}
}

0 comments on commit cb2bd3e

Please sign in to comment.