Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing stream wrapper functions #2979

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/S3/StreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,28 @@ public function stream_cast($cast_as)
return false;
}

public function stream_set_option($option, $arg1, $arg2)
{
return false;
}

public function stream_metadata($path, $option, $value)
{
return false;
}

public function stream_lock($operation)
{
trigger_error('stream_lock() is not supported by the Amazon S3 stream wrapper', E_USER_WARNING);
return false;
}

public function stream_truncate($new_size)
{
trigger_error('stream_truncate() is not supported by the Amazon S3 stream wrapper', E_USER_WARNING);
return false;
}

/**
* Validates the provided stream arguments for fopen and returns an array
* of errors.
Expand Down
50 changes: 50 additions & 0 deletions tests/S3/StreamWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1035,4 +1035,54 @@ public function testTriggersErrorOnNoFlushOrClose($content)
$stream = fopen('s3://bucket/key', 'a');
fwrite($stream, $content);
}

public function testStreamSetOptionReturnsFalse()
{
$this->addMockResults(
$this->client,
[
new Result(),
]
);
$stream = fopen('s3://bucket/key', 'r');
$this->assertFalse(stream_set_option($stream, STREAM_OPTION_READ_TIMEOUT, 1));
}

public function testStreamMetadataReturnsFalse()
{
$this->addMockResults(
$this->client,
[
new Result(),
]
);
$stream = fopen('s3://bucket/key', 'r');
$this->assertFalse(stream_metadata($stream, STREAM_META_TOUCH, 1));
}

public function testStreamLockReturnsFalse()
{
$this->addMockResults(
$this->client,
[
new Result(),
]
);
$stream = fopen('s3://bucket/key', 'r');
$this->assertFalse(flock($stream, LOCK_EX));
$this->assertFalse(flock($stream, LOCK_UN));
$this->assertFalse(flock($stream, LOCK_SH));
}

public function testStreamTruncateReturnsFalse()
{
$this->addMockResults(
$this->client,
[
new Result(),
]
);
$stream = fopen('s3://bucket/key', 'r');
$this->assertFalse(ftruncate($stream, 1));
}
}