mirror of
https://codeberg.org/icewind/streams.git
synced 2026-06-03 16:44:07 +02:00
Merge pull request #19 from icewind1991/countwrapper-seek
handle seeks in countwrapper
This commit is contained in:
commit
cb2bd3ed41
3 changed files with 42 additions and 9 deletions
22
.github/workflows/ci.yaml
vendored
22
.github/workflows/ci.yaml
vendored
|
|
@ -7,13 +7,13 @@ name: CI
|
||||||
jobs:
|
jobs:
|
||||||
php-cs-fixer:
|
php-cs-fixer:
|
||||||
name: PHP-CS-Fixer
|
name: PHP-CS-Fixer
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: '8.0'
|
php-version: '8.3'
|
||||||
- name: PHP-CS-Fixer
|
- name: PHP-CS-Fixer
|
||||||
uses: OskarStark/php-cs-fixer-ga@2.16.7
|
uses: OskarStark/php-cs-fixer-ga@2.16.7
|
||||||
with:
|
with:
|
||||||
|
|
@ -21,14 +21,14 @@ jobs:
|
||||||
|
|
||||||
phpstan:
|
phpstan:
|
||||||
name: PHPStan Static Analysis
|
name: PHPStan Static Analysis
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: '8.0'
|
php-version: '8.3'
|
||||||
- name: Composer
|
- name: Composer
|
||||||
run: composer install
|
run: composer install
|
||||||
- env:
|
- env:
|
||||||
|
|
@ -36,7 +36,7 @@ jobs:
|
||||||
run: php ./vendor/bin/phpstan analyse --level 5 src
|
run: php ./vendor/bin/phpstan analyse --level 5 src
|
||||||
|
|
||||||
phpunit:
|
phpunit:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-latest
|
||||||
name: Unit tests
|
name: Unit tests
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
|
|
@ -45,9 +45,13 @@ jobs:
|
||||||
- "7.3"
|
- "7.3"
|
||||||
- "7.4"
|
- "7.4"
|
||||||
- "8.0"
|
- "8.0"
|
||||||
|
- "8.1"
|
||||||
|
- "8.2"
|
||||||
|
- "8.3"
|
||||||
|
- "8.4"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
|
|
@ -62,7 +66,7 @@ jobs:
|
||||||
files: ./coverage.xml
|
files: ./coverage.xml
|
||||||
|
|
||||||
phpunit-8:
|
phpunit-8:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-latest
|
||||||
name: Unit tests
|
name: Unit tests
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
|
|
@ -72,7 +76,7 @@ jobs:
|
||||||
- "7.2"
|
- "7.2"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,17 @@ class CountWrapper extends Wrapper {
|
||||||
return true;
|
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) {
|
public function dir_opendir($path, $options) {
|
||||||
return $this->open();
|
return $this->open();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,4 +46,22 @@ class CountWrapperTest extends WrapperTest {
|
||||||
fclose($wrapped);
|
fclose($wrapped);
|
||||||
$this->assertSame(6, $count);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue