Skip to content

Commit dd25dd5

Browse files
authored
Merge pull request php-vcr#412 from lstrojny/fix-stream-handler-set-option
Fix stream handler set option
2 parents 9374f45 + ce9eea3 commit dd25dd5

2 files changed

Lines changed: 40 additions & 8 deletions

File tree

src/VCR/Util/StreamProcessor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,14 @@ public function stream_lock(int $operation): bool
493493
*
494494
* @codeCoverageIgnore
495495
*
496-
* @param int $option one of STREAM_OPTION_BLOCKING, STREAM_OPTION_READ_TIMEOUT, STREAM_OPTION_WRITE_BUFFER
497-
* @param int $arg1 depending on option
498-
* @param int $arg2 depending on option
496+
* @param int $option one of STREAM_OPTION_BLOCKING, STREAM_OPTION_READ_TIMEOUT, STREAM_OPTION_WRITE_BUFFER
497+
* @param int $arg1 depending on option
498+
* @param int|null $arg2 depending on option
499499
*
500500
* @return bool Returns TRUE on success or FALSE on failure. If option is not implemented,
501501
* FALSE should be returned.
502502
*/
503-
public function stream_set_option(int $option, int $arg1, int $arg2): bool
503+
public function stream_set_option(int $option, int $arg1, ?int $arg2 = null): bool
504504
{
505505
if (false === $this->resource) {
506506
return false;

tests/Unit/Util/StreamProcessorTest.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,32 @@ public function testFlockWithFilePutContents(): void
2727
$this->assertEquals(\strlen($testData), $res);
2828
}
2929

30+
public function testSetStreamOptions(): void
31+
{
32+
$processor = new StreamProcessor();
33+
$processor->intercept();
34+
35+
$handle = fopen('tests/fixtures/file_put_contents', 'w');
36+
37+
self::assertTrue(stream_set_blocking($handle, true));
38+
self::assertFalse(stream_set_timeout($handle, 10));
39+
self::assertFalse(stream_set_timeout($handle, 5, 2));
40+
self::assertSame(-1, stream_set_write_buffer($handle, 0));
41+
self::assertSame(0, stream_set_read_buffer($handle, 0));
42+
43+
fclose($handle);
44+
45+
$processor->restore();
46+
}
47+
3048
/**
3149
* @dataProvider streamOpenAppendFilterProvider
3250
*/
3351
public function testStreamOpenShouldAppendFilters(bool $expected, int $option, ?bool $shouldProcess = null): void
3452
{
3553
$mock = $this->getMockBuilder('VCR\Util\StreamProcessor')
3654
->disableOriginalConstructor()
37-
->setMethods(['intercept', 'restore', 'appendFiltersToStream', 'shouldProcess'])
55+
->onlyMethods(['intercept', 'restore', 'appendFiltersToStream', 'shouldProcess'])
3856
->getMock();
3957

4058
if (null !== $shouldProcess) {
@@ -109,8 +127,22 @@ public function testUrlStatSuccessfully(): void
109127
public function testUrlStatFileNotFound(): void
110128
{
111129
$processor = new StreamProcessor();
112-
$this->expectWarning();
113-
$processor->url_stat('file_not_found', 0);
130+
131+
set_error_handler(static function (
132+
int $errno,
133+
string $errstr,
134+
string $errfile = '',
135+
int $errline = 0
136+
): void {
137+
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
138+
}, \E_WARNING);
139+
140+
try {
141+
$this->expectException(\ErrorException::class);
142+
$processor->url_stat('file_not_found', 0);
143+
} finally {
144+
restore_error_handler();
145+
}
114146
}
115147

116148
/**
@@ -195,7 +227,7 @@ protected function getStreamProcessorMock()
195227
{
196228
return $this->getMockBuilder(StreamProcessor::class)
197229
->disableOriginalConstructor()
198-
->setMethods(['intercept', 'restore'])
230+
->onlyMethods(['intercept', 'restore'])
199231
->getMock();
200232
}
201233
}

0 commit comments

Comments
 (0)