Skip to content

Commit

Permalink
Merge pull request #19 from SimonFrings/updates
Browse files Browse the repository at this point in the history
Simplify examples and tests by updating to new default loop
  • Loading branch information
clue committed Aug 11, 2021
2 parents 338b838 + 894370d commit 4faf1c4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
11 changes: 6 additions & 5 deletions README.md
Expand Up @@ -27,8 +27,11 @@ Once [installed](#install), you can use the following code to pipe a readable
tar stream into the `Decoder` which emits "entry" events for each individual file:

```php
$loop = React\EventLoop\Factory::create();
$stream = new ReadableResourceStream(fopen('archive.tar', 'r'), $loop);
<?php

require __DIR__ . '/vendor/autoload.php';

$stream = new ReadableResourceStream(fopen('archive.tar', 'r'));

$decoder = new Decoder();

Expand All @@ -42,8 +45,6 @@ $decoder->on('entry', function (array $header, React\Stream\ReadableStreamInterf
});

$stream->pipe($decoder);

$loop->run();
```

See also the [examples](examples).
Expand Down Expand Up @@ -78,7 +79,7 @@ $ composer install
To run the test suite, go to the project root and run:

```bash
$ php vendor/bin/phpunit
$ vendor/bin/phpunit
```

## License
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -12,11 +12,11 @@
],
"require": {
"php": ">=5.3",
"react/stream": "^1.0 || ^0.7"
"react/stream": "^1.2"
},
"require-dev": {
"clue/hexdump": "~0.2.0",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
"react/event-loop": "^1.2",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
},
"autoload": {
Expand Down
6 changes: 1 addition & 5 deletions examples/dump.php
Expand Up @@ -2,7 +2,6 @@

use Clue\Hexdump\Hexdump;
use Clue\React\Tar\Decoder;
use React\EventLoop\Factory;
use React\Stream\ReadableResourceStream;
use React\Stream\ReadableStreamInterface;

Expand All @@ -11,8 +10,7 @@
$in = isset($argv[1]) ? $argv[1] : (__DIR__ . '/../tests/fixtures/alice-bob.tar');
echo 'Reading file "' . $in . '" (pass as argument to example)' . PHP_EOL;

$loop = Factory::create();
$stream = new ReadableResourceStream(fopen($in, 'r'), $loop);
$stream = new ReadableResourceStream(fopen($in, 'r'));

$decoder = new Decoder();
$decoder->on('entry', function (array $header, ReadableStreamInterface $file) {
Expand Down Expand Up @@ -41,5 +39,3 @@
});

$stream->pipe($decoder);

$loop->run();
11 changes: 5 additions & 6 deletions tests/FunctionalDecoderTest.php
Expand Up @@ -3,7 +3,7 @@
namespace Clue\Tests\React\Tar;

use Clue\React\Tar\Decoder;
use React\EventLoop\Factory;
use React\EventLoop\Loop;
use React\Stream\ReadableResourceStream;

class FunctionDecoderTest extends TestCase
Expand All @@ -16,7 +16,6 @@ class FunctionDecoderTest extends TestCase
public function setUpDecoderAndLoop()
{
$this->decoder = new Decoder();
$this->loop = Factory::create();
}

/**
Expand All @@ -28,7 +27,7 @@ public function testAliceBob()

$stream->pipe($this->decoder);

$this->loop->run();
Loop::run();
}

/**
Expand All @@ -41,7 +40,7 @@ public function testAliceBobWithSmallBufferSize()

$stream->pipe($this->decoder);

$this->loop->run();
Loop::run();
}

public function testStreamingSingleEmptyEmitsSingleEntryWithEmptyStream()
Expand Down Expand Up @@ -69,7 +68,7 @@ public function testStreamingSingleEmptyEmitsSingleEntryWithEmptyStream()

$stream->pipe($this->decoder);

$this->loop->run();
Loop::run();
}

public function testCompleteEndSingleEmtpyBehavesSameAsStreaming()
Expand All @@ -83,6 +82,6 @@ public function testCompleteEndSingleEmtpyBehavesSameAsStreaming()

private function createStream($name, $readChunkSize = null)
{
return new ReadableResourceStream(fopen(__DIR__ . '/fixtures/' . $name, 'r'), $this->loop, $readChunkSize);
return new ReadableResourceStream(fopen(__DIR__ . '/fixtures/' . $name, 'r'), null, $readChunkSize);
}
}

0 comments on commit 4faf1c4

Please sign in to comment.