Skip to content

Commit e15e980

Browse files
committed
Added basic tests for Porter::importAsync() and importOneAsync().
1 parent 424a926 commit e15e980

9 files changed

Lines changed: 417 additions & 366 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "^7.1.3",
22-
"mockery/mockery": "^1"
22+
"bilge/mockery": "dev-issue-871"
2323
},
2424
"suggest" : {
2525
"connectors/http": "Provides an HTTP connector for Porter providers.",

src/Collection/RecordCollection.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ public function current(): array
2121
return $this->records->current();
2222
}
2323

24-
/**
25-
* @return void
26-
*/
27-
public function next()
24+
public function next(): void
2825
{
2926
$this->records->next();
3027
}
@@ -37,34 +34,25 @@ public function key()
3734
return $this->records->key();
3835
}
3936

40-
/**
41-
* @return bool
42-
*/
43-
public function valid()
37+
public function valid(): bool
4438
{
4539
return $this->records->valid();
4640
}
4741

48-
/**
49-
* @return void
50-
*/
51-
public function rewind()
42+
public function rewind(): void
5243
{
5344
$this->records->rewind();
5445
}
5546

56-
/**
57-
* @return RecordCollection|null
58-
*/
59-
public function getPreviousCollection()
47+
public function getPreviousCollection(): ?RecordCollection
6048
{
6149
return $this->previousCollection;
6250
}
6351

64-
public function findFirstCollection()
52+
public function findFirstCollection(): ?RecordCollection
6553
{
6654
do {
67-
$previous = isset($nextPrevious) ? $nextPrevious : $this->getPreviousCollection();
55+
$previous = $nextPrevious ?? $this->getPreviousCollection();
6856
} while ($previous && $nextPrevious = $previous->getPreviousCollection());
6957

7058
return $previous ?: $this;

src/Porter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ public function importOneAsync(AsyncImportSpecification $specification): Promise
153153
return \Amp\call(function () use ($specification) {
154154
$results = $this->importAsync($specification);
155155

156-
\Amp\Promise\rethrow(yield $results->advance());
156+
yield $results->advance();
157157

158158
$one = $results->getCurrent();
159159

160-
if (yield $results->advance() !== null) {
160+
if ((yield $results->advance()) !== false) {
161161
throw new ImportException('Cannot import one: more than one record imported.');
162162
}
163163

src/Specification/AsyncImportSpecification.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public function __construct(AsyncResource $resource)
1818
}
1919

2020
parent::__construct($resource);
21+
22+
$this->asyncResource = $resource;
2123
}
2224

2325
public function __clone()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ScriptFUSIONTest\Integration\Porter;
5+
6+
use Amp\Loop;
7+
use ScriptFUSION\Porter\Porter;
8+
use ScriptFUSION\Porter\Specification\AsyncImportSpecification;
9+
10+
/**
11+
* @see Porter
12+
*/
13+
final class AsyncPorterTest extends PorterTest
14+
{
15+
protected function setUp(): void
16+
{
17+
parent::setUp();
18+
19+
$this->specification = new AsyncImportSpecification($this->resource);
20+
}
21+
22+
public function testImportAsync(): void
23+
{
24+
Loop::run(function () {
25+
$records = $this->porter->importAsync($this->specification);
26+
yield $records->advance();
27+
28+
self::assertSame(['foo'], $records->getCurrent());
29+
});
30+
}
31+
32+
public function testImportOneAsync(): void
33+
{
34+
Loop::run(function () {
35+
self::assertSame(['foo'], yield $this->porter->importOneAsync($this->specification));
36+
});
37+
}
38+
}

0 commit comments

Comments
 (0)