Skip to content

Commit

Permalink
fix synthax test
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Oct 30, 2023
1 parent 90ad255 commit c34c35d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/Resources/CursorCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection
{
$page = $this;

var_dump(get_class($page));
die;
return new LazyCollection(function () use ($page, $iterateBackwards): Generator {

Check failure on line 111 in src/Resources/CursorCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Unreachable statement - code above always terminates.

Check failure on line 111 in src/Resources/CursorCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Unreachable statement - code above always terminates.

Check failure on line 111 in src/Resources/CursorCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Unreachable statement - code above always terminates.

Check failure on line 111 in src/Resources/CursorCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Unreachable statement - code above always terminates.

Check failure on line 111 in src/Resources/CursorCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Unreachable statement - code above always terminates.

Check failure on line 111 in src/Resources/CursorCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Unreachable statement - code above always terminates.

Check failure on line 111 in src/Resources/CursorCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Unreachable statement - code above always terminates.

Check failure on line 111 in src/Resources/CursorCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.2

Unreachable statement - code above always terminates.

Check failure on line 111 in src/Resources/CursorCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Unreachable statement - code above always terminates.
while (true) {
foreach ($page as $item) {
Expand Down
39 changes: 28 additions & 11 deletions src/Resources/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace Mollie\Api\Resources;

use ArrayIterator;
use Iterator;
use IteratorAggregate;
use Traversable;

class LazyCollection implements IteratorAggregate
{
Expand Down Expand Up @@ -48,7 +47,7 @@ public function get($key)
* @param (callable(value, key): bool) $callback
* @return static
*/
public function filter(callable $callback): static
public function filter(callable $callback): self

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\key.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\value.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\key.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\value.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\key.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\value.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\key.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\value.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\key.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\value.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\key.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\value.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\key.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\value.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.2

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\key.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.2

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\value.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\key.

Check failure on line 50 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Parameter $callback of method Mollie\Api\Resources\LazyCollection::filter() has invalid type Mollie\Api\Resources\value.
{
return new static(function () use ($callback) {

Check failure on line 52 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Unsafe usage of new static().

Check failure on line 52 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Unsafe usage of new static().

Check failure on line 52 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Unsafe usage of new static().

Check failure on line 52 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Unsafe usage of new static().

Check failure on line 52 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Unsafe usage of new static().

Check failure on line 52 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Unsafe usage of new static().

Check failure on line 52 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Unsafe usage of new static().

Check failure on line 52 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.2

Unsafe usage of new static().

Check failure on line 52 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Unsafe usage of new static().
foreach ($this as $key => $value) {
Expand Down Expand Up @@ -92,7 +91,7 @@ public function first(callable $callback = null): mixed
* @param callable(value, key): mixed $callback
* @return static<key, mixed>
*/
public function map(callable $callback): static
public function map(callable $callback): self

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Method Mollie\Api\Resources\LazyCollection::map() has invalid return type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\value.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Method Mollie\Api\Resources\LazyCollection::map() has invalid return type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\value.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Method Mollie\Api\Resources\LazyCollection::map() has invalid return type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\value.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Method Mollie\Api\Resources\LazyCollection::map() has invalid return type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\value.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Method Mollie\Api\Resources\LazyCollection::map() has invalid return type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\value.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Method Mollie\Api\Resources\LazyCollection::map() has invalid return type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\value.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Method Mollie\Api\Resources\LazyCollection::map() has invalid return type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\value.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.2

Method Mollie\Api\Resources\LazyCollection::map() has invalid return type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.2

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.2

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\value.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Method Mollie\Api\Resources\LazyCollection::map() has invalid return type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\key.

Check failure on line 94 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Parameter $callback of method Mollie\Api\Resources\LazyCollection::map() has invalid type Mollie\Api\Resources\value.
{
return new static(function () use ($callback) {

Check failure on line 96 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Unsafe usage of new static().

Check failure on line 96 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Unsafe usage of new static().

Check failure on line 96 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Unsafe usage of new static().

Check failure on line 96 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Unsafe usage of new static().

Check failure on line 96 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.4

Unsafe usage of new static().

Check failure on line 96 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8

Unsafe usage of new static().

Check failure on line 96 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 7.3

Unsafe usage of new static().

Check failure on line 96 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.2

Unsafe usage of new static().

Check failure on line 96 in src/Resources/LazyCollection.php

View workflow job for this annotation

GitHub Actions / PHP - 8.1

Unsafe usage of new static().
foreach ($this as $key => $value) {
Expand All @@ -107,7 +106,7 @@ public function map(callable $callback): static
* @param int $limit
* @return static
*/
public function take(int $limit): static
public function take(int $limit): self
{
return new static(function () use ($limit) {
$iterator = $this->getIterator();
Expand All @@ -126,6 +125,12 @@ public function take(int $limit): static
});
}

/**
* Determine if all items pass the given truth test.
*
* @param callable $callback
* @return boolean
*/
public function every(callable $callback): bool
{
$iterator = $this->getIterator();
Expand All @@ -149,21 +154,33 @@ public function count(): int
return iterator_count($this->getIterator());
}

public function getIterator(): Traversable
/**
* Get an iterator for the items.
*
* @return Iterator
*/
public function getIterator(): Iterator
{
return $this->makeIterator($this->source);
}

protected function makeIterator($source): Traversable
/**
* Get an iterator for the given value.
*
* @param callable|IteratorAggregate $source
* @return Iterator
*/
protected function makeIterator($source): Iterator
{
if ($source instanceof IteratorAggregate) {
return $source->getIterator();
}

if (is_array($source)) {
return new ArrayIterator($source);
}

return $source();
}

public function __call($name, $arguments)
{
var_dump($this->getIterator());
}
}
8 changes: 6 additions & 2 deletions tests/Mollie/API/Resources/CursorCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Mollie\Api\MollieApiClient;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\MandateCollection;
use Mollie\Api\Resources\OrderCollection;
use Mollie\Api\Types\MandateStatus;
use PHPUnit\Framework\TestCase;

class CursorCollectionTest extends TestCase
Expand Down Expand Up @@ -113,12 +115,14 @@ public function testWillReturnNullIfNoPreviousResultIsAvailable()

public function testAutoPaginatorReturnsLazyCollection()
{
$collection = new OrderCollection(
$collection = new MandateCollection(
$this->createMock(MollieApiClient::class),
1,
(object) []
);

$this->assertInstanceOf(LazyCollection::class, $collection->getAutoIterator());
$this->assertInstanceOf(LazyCollection::class, $collection = $collection->getAutoIterator());

$collection->whereStatus(MandateStatus::STATUS_PENDING);
}
}
16 changes: 16 additions & 0 deletions tests/Mollie/API/Resources/LazyCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Tests\Mollie\API\Resources;

use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\MandateCollection;
use Mollie\Api\Types\MandateStatus;
use PHPUnit\Framework\TestCase;

class LazyCollectionTest extends TestCase
Expand Down Expand Up @@ -81,4 +83,18 @@ public function testEvery()
return $value > 1;
}));
}

public function testItRemainsAccessToOriginalCollectionMethods()
{
$collection = new MandateCollection(
$this->createMock(\Mollie\Api\MollieApiClient::class),
1,
(object) []
);
$collection[0] = (object) ['id' => 'mdt_12345', 'status' => MandateStatus::STATUS_VALID];
$collection[1] = (object) ['id' => 'mdt_12346', 'status' => MandateStatus::STATUS_PENDING];

$pendingMandates = $collection->getAutoIterator()->whereStatus(MandateStatus::STATUS_PENDING);
$this->assertCount(1, $pendingMandates);
}
}

0 comments on commit c34c35d

Please sign in to comment.