Skip to content

Commit 42cd12b

Browse files
committed
Changed AsyncConnector to return Promise instead of mixed (usually generator).
Changed PorterTest base to AsyncTestCase. Added PHP 7.3 to Travis.
1 parent f79ad75 commit 42cd12b

File tree

6 files changed

+17
-20
lines changed

6 files changed

+17
-20
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ language: php
88
php:
99
- 7.1
1010
- 7.2
11+
- 7.3
1112

1213
env:
1314
matrix:

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"psr/cache": "^1"
1919
},
2020
"require-dev": {
21+
"amphp/phpunit-util": "^1.1",
2122
"phpunit/phpunit": "^7.1.3",
2223
"mockery/mockery": "^1.1"
2324
},

src/Connector/AsyncConnector.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace ScriptFUSION\Porter\Connector;
55

6+
use Amp\Promise;
7+
68
/**
79
* Provides a method for fetching data from a remote source asynchronously.
810
*/
@@ -13,7 +15,7 @@ interface AsyncConnector
1315
*
1416
* @param string $source Source.
1517
*
16-
* @return mixed Async generator function or any return value compatible with Amp\call.
18+
* @return Promise Fetched data.
1719
*/
18-
public function fetchAsync(string $source);
20+
public function fetchAsync(string $source): Promise;
1921
}

src/Connector/ImportConnector.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use ScriptFUSION\Porter\Connector\Recoverable\RecoverableException;
99
use ScriptFUSION\Porter\Connector\Recoverable\RecoverableExceptionHandler;
1010
use ScriptFUSION\Porter\Connector\Recoverable\StatelessRecoverableExceptionHandler;
11-
use function Amp\call;
1211
use function Amp\Promise\all;
1312
use function ScriptFUSION\Retry\retry;
1413
use function ScriptFUSION\Retry\retryAsync;
@@ -83,11 +82,7 @@ public function fetchAsync(string $source): Promise
8382
return retryAsync(
8483
$this->maxFetchAttempts,
8584
function () use ($source): Promise {
86-
return call(
87-
function () use ($source) {
88-
return $this->connector->fetchAsync($source);
89-
}
90-
);
85+
return $this->connector->fetchAsync($source);
9186
},
9287
$this->createExceptionHandler()
9388
);

test/Integration/Porter/PorterAsyncTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,17 @@ protected function setUp(): void
2222
$this->specification = new AsyncImportSpecification($this->resource);
2323
}
2424

25-
public function testImportAsync(): void
25+
public function testImportAsync(): \Generator
2626
{
27-
Loop::run(function () {
28-
$records = $this->porter->importAsync($this->specification);
27+
$records = $this->porter->importAsync($this->specification);
2928

30-
self::assertTrue(yield $records->advance());
31-
self::assertSame(['foo'], $records->getCurrent());
32-
});
29+
self::assertTrue(yield $records->advance());
30+
self::assertSame(['foo'], $records->getCurrent());
3331
}
3432

35-
public function testImportOneAsync(): void
33+
public function testImportOneAsync(): \Generator
3634
{
37-
Loop::run(function () {
38-
self::assertSame(['foo'], yield $this->porter->importOneAsync($this->specification));
39-
});
35+
self::assertSame(['foo'], yield $this->porter->importOneAsync($this->specification));
4036
}
4137

4238
/**

test/Integration/Porter/PorterTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace ScriptFUSIONTest\Integration\Porter;
55

6+
use Amp\PHPUnit\AsyncTestCase;
67
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
78
use Mockery\MockInterface;
8-
use PHPUnit\Framework\TestCase;
99
use Psr\Container\ContainerInterface;
1010
use ScriptFUSION\Porter\Connector\AsyncConnector;
1111
use ScriptFUSION\Porter\Connector\Connector;
@@ -18,7 +18,7 @@
1818
use ScriptFUSION\Porter\Specification\ImportSpecification;
1919
use ScriptFUSIONTest\MockFactory;
2020

21-
abstract class PorterTest extends TestCase
21+
abstract class PorterTest extends AsyncTestCase
2222
{
2323
use MockeryPHPUnitIntegration;
2424

@@ -54,6 +54,8 @@ abstract class PorterTest extends TestCase
5454

5555
protected function setUp(): void
5656
{
57+
parent::setUp();
58+
5759
$this->porter = new Porter($this->container = \Mockery::spy(ContainerInterface::class));
5860

5961
$this->registerProvider($this->provider = MockFactory::mockProvider());

0 commit comments

Comments
 (0)