Skip to content

Commit f6e401f

Browse files
committed
Added async collection tests for accessor methods.
1 parent e9a3266 commit f6e401f

File tree

8 files changed

+105
-4
lines changed

8 files changed

+105
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scriptfusion/porter",
3-
"description": "Scalable and efficient data import abstraction for APIs.",
3+
"description": "Scalable and durable data import abstraction for APIs.",
44
"authors": [
55
{
66
"name": "Bilge",

infection.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"logs": {
1212
"text": "infection.log",
1313
"badge": {
14-
"branch": "5.0"
14+
"branch": "master"
1515
}
1616
},
1717
"mutators": {

test/Integration/PorterSyncTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use ScriptFUSION\Retry\FailingTooHardException;
2828
use ScriptFUSIONTest\MockFactory;
2929
use ScriptFUSIONTest\Stubs\TestRecoverableException;
30+
use ScriptFUSIONTest\Stubs\TestRecoverableExceptionHandler;
3031

3132
final class PorterSyncTest extends PorterTest
3233
{
@@ -235,6 +236,8 @@ public function testDerivedRecoverableException(): void
235236
public function testDefaultTries(): void
236237
{
237238
$this->arrangeConnectorException(new TestRecoverableException);
239+
// Speed up test by circumventing exponential backoff default handler.
240+
$this->specification->setRecoverableExceptionHandler(new TestRecoverableExceptionHandler);
238241

239242
$this->expectException(FailingTooHardException::class);
240243
$this->expectExceptionMessage((string)ImportSpecification::DEFAULT_FETCH_ATTEMPTS);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ScriptFUSIONTest\Unit\Collection;
5+
6+
use Amp\Iterator;
7+
use PHPUnit\Framework\TestCase;
8+
use ScriptFUSION\Porter\Collection\AsyncFilteredRecords;
9+
use ScriptFUSION\Porter\Collection\AsyncRecordCollection;
10+
11+
/**
12+
* @see AsyncFilteredRecords
13+
*/
14+
final class AsyncFilteredRecordsTest extends TestCase
15+
{
16+
/**
17+
* Tests that the filter passed at construction time is the same as that retrieved from the accessor method.
18+
*/
19+
public function testGetResource(): void
20+
{
21+
$records = new AsyncFilteredRecords(
22+
\Mockery::mock(Iterator::class),
23+
\Mockery::mock(AsyncRecordCollection::class),
24+
$callable = [$this, __FUNCTION__]
25+
);
26+
27+
self::assertSame($callable, $records->getFilter());
28+
}
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ScriptFUSIONTest\Unit\Collection;
5+
6+
use PHPUnit\Framework\TestCase;
7+
use ScriptFUSION\Porter\Collection\AsyncPorterRecords;
8+
use ScriptFUSION\Porter\Collection\AsyncRecordCollection;
9+
use ScriptFUSION\Porter\Specification\AsyncImportSpecification;
10+
11+
/**
12+
* @see AsyncPorterRecords
13+
*/
14+
final class AsyncPorterRecordsTest extends TestCase
15+
{
16+
/**
17+
* Tests that the specification passed at construction time is the same as that retrieved from the accessor method.
18+
*/
19+
public function testGetSpecification(): void
20+
{
21+
$records = new AsyncPorterRecords(
22+
\Mockery::mock(AsyncRecordCollection::class),
23+
$specification = \Mockery::mock(AsyncImportSpecification::class)
24+
);
25+
26+
self::assertSame($specification, $records->getSpecification());
27+
}
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ScriptFUSIONTest\Unit\Collection;
5+
6+
use Amp\Iterator;
7+
use PHPUnit\Framework\TestCase;
8+
use ScriptFUSION\Porter\Collection\AsyncProviderRecords;
9+
use ScriptFUSION\Porter\Collection\ProviderRecords;
10+
use ScriptFUSION\Porter\Provider\Resource\AsyncResource;
11+
12+
/**
13+
* @see ProviderRecords
14+
*/
15+
final class AsyncProviderRecordsTest extends TestCase
16+
{
17+
/**
18+
* Tests that the resource passed at construction time is the same as that retrieved from the accessor method.
19+
*/
20+
public function testGetResource(): void
21+
{
22+
$records = new AsyncProviderRecords(
23+
\Mockery::mock(Iterator::class),
24+
$resource = \Mockery::mock(AsyncResource::class)
25+
);
26+
27+
self::assertSame($resource, $records->getResource());
28+
}
29+
}

test/Unit/Collection/PorterRecordsTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
use ScriptFUSION\Porter\Collection\RecordCollection;
99
use ScriptFUSION\Porter\Specification\ImportSpecification;
1010

11+
/**
12+
* @see PorterRecords
13+
*/
1114
final class PorterRecordsTest extends TestCase
1215
{
13-
public function test(): void
16+
/**
17+
* Tests that the specification passed at construction time is the same as that retrieved from the accessor method.
18+
*/
19+
public function testGetSpecification(): void
1420
{
1521
$records = new PorterRecords(
1622
\Mockery::mock(RecordCollection::class),

test/Unit/Collection/ProviderRecordsTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
use ScriptFUSION\Porter\Collection\ProviderRecords;
88
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
99

10+
/**
11+
* @see ProviderRecords
12+
*/
1013
final class ProviderRecordsTest extends TestCase
1114
{
12-
public function test(): void
15+
/**
16+
* Tests that the resource passed at construction time is the same as that retrieved from the accessor method.
17+
*/
18+
public function testGetResource(): void
1319
{
1420
$records = new ProviderRecords(
1521
\Mockery::mock(\Iterator::class),

0 commit comments

Comments
 (0)