From 670db6fabd1933ea538b6521e078622c6dc0cce5 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Mon, 3 Jun 2019 22:58:33 +0900 Subject: [PATCH 01/11] Install any AST version on Travis CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 679c456..0bc4bfd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ jobs: - stage: analyze php: 7.2 install: - - pecl install ast-0.1.7 + - pecl install ast - phpenv config-rm xdebug.ini - composer install --prefer-dist script: From 1f82117a63a3e79490c378e9e01a0c879710aa48 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Mon, 3 Jun 2019 22:59:31 +0900 Subject: [PATCH 02/11] Use general-purpose with a dash --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f7cbb5a..2d84263 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "sanmai/pipeline", "type": "library", - "description": "General purpose collections pipeline", + "description": "General-purpose collections pipeline", "license": "Apache-2.0", "authors": [ { From 30659dd3b208f64b58c8cb4bb7ad910197cfb1a7 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Mon, 3 Jun 2019 23:02:38 +0900 Subject: [PATCH 03/11] Allow never version of PHPStan --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2d84263..952ce33 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "mockery/mockery": "^1.0", "phan/phan": "^1.1", "php-coveralls/php-coveralls": "^2.0", - "phpstan/phpstan": "~0.9", + "phpstan/phpstan": ">=0.9", "phpunit/phpunit": ">=6 <8", "vimeo/psalm": "^2.0 || ^3.0" }, From a9c6f6969e8c4f9a0ef8e0251a6a087251db6f19 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Mon, 3 Jun 2019 23:12:35 +0900 Subject: [PATCH 04/11] Backport some tests from 3.x --- tests/EdgeCasesTest.php | 22 ++++++++++++++++++++++ tests/ErrorsTest.php | 17 +++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/tests/EdgeCasesTest.php b/tests/EdgeCasesTest.php index eef714a..5023e24 100644 --- a/tests/EdgeCasesTest.php +++ b/tests/EdgeCasesTest.php @@ -78,6 +78,28 @@ public function testFilterAnyFalseValueCustomCallback() $this->assertCount(0, $pipeline->toArray()); } + public function testNonUniqueKeys() + { + $pipeline = \Pipeline\map(function () { + yield 'foo' => 'bar'; + yield 'foo' => 'baz'; + }); + + $this->assertSame([ + 'foo' => 'baz', + ], iterator_to_array($pipeline)); + + $pipeline = \Pipeline\map(function () { + yield 'foo' => 'bar'; + yield 'foo' => 'baz'; + }); + + $this->assertSame([ + 'bar', + 'baz', + ], $pipeline->toArray()); + } + public function testMapUnprimed() { $pipeline = new Standard(); diff --git a/tests/ErrorsTest.php b/tests/ErrorsTest.php index 83fbc02..5f1c547 100644 --- a/tests/ErrorsTest.php +++ b/tests/ErrorsTest.php @@ -71,4 +71,21 @@ public function testPipelineInPipelineUsesSelf() $pipeline->reduce(); } + + /** + * @covers \Pipeline\Standard::unpack() + */ + public function testUnpackNonIterable() + { + $pipeline = new \Pipeline\Standard(); + + $pipeline->map(function () { + yield 1; + yield [2, 3]; + })->unpack(); + + $this->expectException(Warning::class); + $this->expectExceptionMessage('Only arrays and Traversables can be unpacked'); + $pipeline->toArray(); + } } From 4e6ccf2eaf3e746b0b6f46f53cb9f2fa7ad99c1e Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Tue, 4 Jun 2019 02:59:45 +0900 Subject: [PATCH 05/11] Fix Phan warning --- src/Standard.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Standard.php b/src/Standard.php index 0c191a1..71ff524 100644 --- a/src/Standard.php +++ b/src/Standard.php @@ -111,6 +111,7 @@ public function reduce(callable $func = null, $initial = null) */ public function __invoke(): \Generator { + /** @phan-suppress-next-line PhanTypeInvalidYieldFrom */ yield from $this; } } From 45e9ae8d0ffb1b2ba98480f43e2b185a03edf6a6 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" Date: Tue, 4 Jun 2019 06:02:59 +0000 Subject: [PATCH 06/11] Update phan/phan requirement from ^1.1 to ^1.1 || ^2.0 (#73) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 952ce33..a211870 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "infection/infection": ">=0.10.5", "league/pipeline": "^1.0 || ^0.3", "mockery/mockery": "^1.0", - "phan/phan": "^1.1", + "phan/phan": "^1.1 || ^2.0", "php-coveralls/php-coveralls": "^2.0", "phpstan/phpstan": ">=0.9", "phpunit/phpunit": ">=6 <8", From da4e887268ae8f11e67044bb74b2b3aa93d80367 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Tue, 25 Jun 2019 06:30:40 +0900 Subject: [PATCH 07/11] Remove unnecessary "else" --- src/Principal.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Principal.php b/src/Principal.php index b870947..e4d34dc 100644 --- a/src/Principal.php +++ b/src/Principal.php @@ -91,10 +91,11 @@ private static function apply(/* iterable */ $previous, callable $func): \Genera $result = $func($value); if ($result instanceof \Generator) { yield from $result; - } else { - // Case of a plain old mapping function - yield $result; + continue; } + + // Case of a plain old mapping function + yield $result; } } From 2e0f3376ec8e8aaedda8bd8a8ce806c344fb762f Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Tue, 2 Jul 2019 03:26:43 +0900 Subject: [PATCH 08/11] Assert that count is zero for an empty pipeline --- tests/StandardTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/StandardTest.php b/tests/StandardTest.php index e897a20..80cb753 100644 --- a/tests/StandardTest.php +++ b/tests/StandardTest.php @@ -34,6 +34,17 @@ public function testEmpty() $pipeline = new Standard(); $this->assertSame([], $pipeline->toArray()); + + $this->assertSame(0, iterator_count(new Standard())); + } + + public function testEmptyPHPUnitWise() + { + try { + $this->assertCount(0, new Standard()); + } catch (\BadMethodCallException $e) { + $this->markTestIncomplete($e->getMessage()); + } } public function testSingle() From 7bfe6798838239d3e2d240a239a28f599844f36a Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 3 Jul 2019 00:23:43 +0900 Subject: [PATCH 09/11] Test that reduce() returns an int for the default reducer --- tests/StandardTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/StandardTest.php b/tests/StandardTest.php index 80cb753..1ebb9b6 100644 --- a/tests/StandardTest.php +++ b/tests/StandardTest.php @@ -203,6 +203,13 @@ public function testReduceToArray() $this->assertSame([9, 27, 36, 216, 81, 729], $result); } + public function testReduceEmpty() + { + $pipeline = new Standard(); + + $this->assertSame(0, $pipeline->reduce()); + } + public function testMeaningless() { $pipeline = new Standard(new \ArrayIterator([])); From 9946bcfa84d6e239647842e2838c79fa4c15ffd2 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 10 Jul 2019 22:43:18 +0900 Subject: [PATCH 10/11] Improve StandardTest --- tests/StandardTest.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/StandardTest.php b/tests/StandardTest.php index 1ebb9b6..90fc317 100644 --- a/tests/StandardTest.php +++ b/tests/StandardTest.php @@ -210,7 +210,25 @@ public function testReduceEmpty() $this->assertSame(0, $pipeline->reduce()); } - public function testMeaningless() + public function testReduceEmptyGeneratorSource() + { + $pipeline = new Standard(); + $pipeline->map(function () { + return; + yield true; + $this->fail(); + }); + + $pipeline->map(function () { + $this->fail(); + + return 1; + }); + + $this->assertSame(0, $pipeline->reduce()); + } + + public function testMapNotCalledForEmptyIterator() { $pipeline = new Standard(new \ArrayIterator([])); From 05673bd3e6461374bdba4652b3fd6b75fd345cf3 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Fri, 4 Oct 2019 23:12:51 +0900 Subject: [PATCH 11/11] Test on PHP 7.4 on Travis + workaround for Composer on PHP 8.0 --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0bc4bfd..439d415 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,12 +6,14 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4snapshot - nightly matrix: fast_finish: true allow_failures: - php: nightly + - php: 7.4snapshot stages: - analyze @@ -41,7 +43,8 @@ install: - composer remove --no-update --dev phan/phan phpstan/phpstan vimeo/psalm infection/infection friendsofphp/php-cs-fixer - - composer install --prefer-dist + - if [[ $TRAVIS_PHP_VERSION = nightly ]]; then export COMPOSER_FLAGS="--ignore-platform-reqs"; fi + - travis_retry composer install --prefer-dist $COMPOSER_FLAGS script: - make ci-test --keep-going