mirror of
https://codeberg.org/icewind/streams.git
synced 2026-06-03 16:44:07 +02:00
Add test for retry wrapper
This commit is contained in:
parent
6eaa5952be
commit
2000e1567c
2 changed files with 56 additions and 1 deletions
|
|
@ -20,7 +20,7 @@ class RetryWrapper extends Wrapper {
|
|||
*/
|
||||
public static function wrap($source) {
|
||||
$context = stream_context_create(array(
|
||||
'callback' => array(
|
||||
'retry' => array(
|
||||
'source' => $source
|
||||
)
|
||||
));
|
||||
|
|
|
|||
55
tests/RetryWrapper.php
Normal file
55
tests/RetryWrapper.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
||||
* This file is licensed under the Licensed under the MIT license:
|
||||
* http://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Icewind\Streams\Tests;
|
||||
|
||||
class PartialWrapper extends \Icewind\Streams\NullWrapper {
|
||||
/**
|
||||
* Wraps a stream with the provided callbacks
|
||||
*
|
||||
* @param resource $source
|
||||
* @return resource
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public static function wrap($source) {
|
||||
$context = stream_context_create(array(
|
||||
'null' => array(
|
||||
'source' => $source)
|
||||
));
|
||||
return self::wrapSource($source, $context, 'partial', '\Icewind\Streams\Tests\PartialWrapper');
|
||||
}
|
||||
|
||||
public function stream_read($count) {
|
||||
$count = min($count, 2); // return as most 2 bytes
|
||||
return parent::stream_read($count);
|
||||
}
|
||||
|
||||
public function stream_write($data) {
|
||||
$data = substr($data, 0, 2); //write as most 2 bytes
|
||||
return parent::stream_write($data);
|
||||
}
|
||||
}
|
||||
|
||||
class RetryWrapper extends Wrapper {
|
||||
|
||||
/**
|
||||
* @param resource $source
|
||||
* @return resource
|
||||
*/
|
||||
protected function wrapSource($source) {
|
||||
return \Icewind\Streams\RetryWrapper::wrap(PartialWrapper::wrap($source));
|
||||
}
|
||||
|
||||
public function testReadDir() {
|
||||
$this->markTestSkipped('directories not supported');
|
||||
}
|
||||
|
||||
public function testRewindDir() {
|
||||
$this->markTestSkipped('directories not supported');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue