Skip to content

Simplify examples and tests by updating to new default loop #19

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

Merged
merged 1 commit into from
Aug 11, 2021
Merged
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
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
}
}