Skip to content

Commit 4faf1c4

Browse files
authored
Merge pull request #19 from SimonFrings/updates
Simplify examples and tests by updating to new default loop
2 parents 338b838 + 894370d commit 4faf1c4

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ Once [installed](#install), you can use the following code to pipe a readable
2727
tar stream into the `Decoder` which emits "entry" events for each individual file:
2828

2929
```php
30-
$loop = React\EventLoop\Factory::create();
31-
$stream = new ReadableResourceStream(fopen('archive.tar', 'r'), $loop);
30+
<?php
31+
32+
require __DIR__ . '/vendor/autoload.php';
33+
34+
$stream = new ReadableResourceStream(fopen('archive.tar', 'r'));
3235

3336
$decoder = new Decoder();
3437

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

4447
$stream->pipe($decoder);
45-
46-
$loop->run();
4748
```
4849

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

8081
```bash
81-
$ php vendor/bin/phpunit
82+
$ vendor/bin/phpunit
8283
```
8384

8485
## License

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
],
1313
"require": {
1414
"php": ">=5.3",
15-
"react/stream": "^1.0 || ^0.7"
15+
"react/stream": "^1.2"
1616
},
1717
"require-dev": {
1818
"clue/hexdump": "~0.2.0",
19-
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
19+
"react/event-loop": "^1.2",
2020
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
2121
},
2222
"autoload": {

examples/dump.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use Clue\Hexdump\Hexdump;
44
use Clue\React\Tar\Decoder;
5-
use React\EventLoop\Factory;
65
use React\Stream\ReadableResourceStream;
76
use React\Stream\ReadableStreamInterface;
87

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

14-
$loop = Factory::create();
15-
$stream = new ReadableResourceStream(fopen($in, 'r'), $loop);
13+
$stream = new ReadableResourceStream(fopen($in, 'r'));
1614

1715
$decoder = new Decoder();
1816
$decoder->on('entry', function (array $header, ReadableStreamInterface $file) {
@@ -41,5 +39,3 @@
4139
});
4240

4341
$stream->pipe($decoder);
44-
45-
$loop->run();

tests/FunctionalDecoderTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Clue\Tests\React\Tar;
44

55
use Clue\React\Tar\Decoder;
6-
use React\EventLoop\Factory;
6+
use React\EventLoop\Loop;
77
use React\Stream\ReadableResourceStream;
88

99
class FunctionDecoderTest extends TestCase
@@ -16,7 +16,6 @@ class FunctionDecoderTest extends TestCase
1616
public function setUpDecoderAndLoop()
1717
{
1818
$this->decoder = new Decoder();
19-
$this->loop = Factory::create();
2019
}
2120

2221
/**
@@ -28,7 +27,7 @@ public function testAliceBob()
2827

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

31-
$this->loop->run();
30+
Loop::run();
3231
}
3332

3433
/**
@@ -41,7 +40,7 @@ public function testAliceBobWithSmallBufferSize()
4140

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

44-
$this->loop->run();
43+
Loop::run();
4544
}
4645

4746
public function testStreamingSingleEmptyEmitsSingleEntryWithEmptyStream()
@@ -69,7 +68,7 @@ public function testStreamingSingleEmptyEmitsSingleEntryWithEmptyStream()
6968

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

72-
$this->loop->run();
71+
Loop::run();
7372
}
7473

7574
public function testCompleteEndSingleEmtpyBehavesSameAsStreaming()
@@ -83,6 +82,6 @@ public function testCompleteEndSingleEmtpyBehavesSameAsStreaming()
8382

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

0 commit comments

Comments
 (0)