From 4b922db41575ef5f0498523dfef58729fcb9fcf7 Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Mon, 12 Jul 2021 18:48:33 +0100 Subject: [PATCH 1/2] Add coverage check --- grumphp.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grumphp.yml b/grumphp.yml index e526f8fa7..3edeee144 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -53,6 +53,9 @@ parameters: extra_tasks: phpspec: verbose: true + clover_coverage: + clover_file: build/logs/clover.xml + level: 90 infection: threads: 10 test_framework: phpspec From 271d4d13bb9d5947e1773c01399d120376dde5b3 Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Mon, 12 Jul 2021 19:29:09 +0100 Subject: [PATCH 2/2] Add to workflow and add tests --- .github/workflows/tests.yml | 2 +- grumphp.yml | 2 +- spec/loophp/collection/CollectionSpec.php | 8 +-- .../Iterator/MultipleIterableIteratorSpec.php | 60 +++++++++++++++++++ .../Iterator/StringIteratorSpec.php | 44 ++++++++++++++ src/Iterator/MultipleIterableIterator.php | 8 +-- 6 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 spec/loophp/collection/Iterator/MultipleIterableIteratorSpec.php create mode 100644 spec/loophp/collection/Iterator/StringIteratorSpec.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 30809ecce..a0b61db8d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -50,7 +50,7 @@ jobs: run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Run Grumphp - run: vendor/bin/grumphp run --tasks=phpspec + run: vendor/bin/grumphp run --tasks=phpspec,coverage_clover - name: Send Scrutinizer data run: | diff --git a/grumphp.yml b/grumphp.yml index 3edeee144..274e15800 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -55,7 +55,7 @@ parameters: verbose: true clover_coverage: clover_file: build/logs/clover.xml - level: 90 + level: 99 infection: threads: 10 test_framework: phpspec diff --git a/spec/loophp/collection/CollectionSpec.php b/spec/loophp/collection/CollectionSpec.php index 90099d16a..ed1575afe 100644 --- a/spec/loophp/collection/CollectionSpec.php +++ b/spec/loophp/collection/CollectionSpec.php @@ -2069,7 +2069,8 @@ public function it_can_matching(): void $criteria = Criteria::create() ->andWhere(Criteria::expr()->eq('is_admin', true)) - ->orderBy(['age' => 'ASC']); + ->orderBy(['age' => 'ASC']) + ->setMaxResults(1); $this::fromIterable($users) ->matching($criteria) @@ -2080,11 +2081,6 @@ public function it_can_matching(): void 'age' => 7, 'is_admin' => true, ], - 0 => [ - 'name' => 'Pol', - 'age' => 39, - 'is_admin' => true, - ], ] ); } diff --git a/spec/loophp/collection/Iterator/MultipleIterableIteratorSpec.php b/spec/loophp/collection/Iterator/MultipleIterableIteratorSpec.php new file mode 100644 index 000000000..6e11b1dc8 --- /dev/null +++ b/spec/loophp/collection/Iterator/MultipleIterableIteratorSpec.php @@ -0,0 +1,60 @@ +beConstructedWith([1, 2, 3]); + + $this->getInnerIterator()->shouldIterateAs([1, 2, 3]); + } + + public function it_can_iterate_with_multiple_iterables(): void + { + $this->beConstructedWith([1, 2, 3], new ArrayIterator([4, 5, 6])); + + $expected = static function (): Generator { + yield 0 => 1; + + yield 1 => 2; + + yield 2 => 3; + + yield 0 => 4; + + yield 1 => 5; + + yield 2 => 6; + }; + + $this->getInnerIterator()->shouldIterateAs($expected()); + } + + public function it_is_initializable_with_a_single_iterable(): void + { + $this->beConstructedWith([1, 2, 3]); + + $this->shouldHaveType(MultipleIterableIterator::class); + } + + public function it_is_initializable_with_multiple_iterables(): void + { + $this->beConstructedWith([1, 2, 3], new ArrayIterator([4, 5, 6])); + + $this->shouldHaveType(MultipleIterableIterator::class); + } +} diff --git a/spec/loophp/collection/Iterator/StringIteratorSpec.php b/spec/loophp/collection/Iterator/StringIteratorSpec.php new file mode 100644 index 000000000..4065c967c --- /dev/null +++ b/spec/loophp/collection/Iterator/StringIteratorSpec.php @@ -0,0 +1,44 @@ +beConstructedWith('A string.'); + + $this->getInnerIterator()->shouldIterateAs(['A', ' ', 's', 't', 'r', 'i', 'n', 'g', '.']); + } + + public function it_can_iterate_with_given_delimiter(): void + { + $this->beConstructedWith('I am a string.', ' '); + + $this->getInnerIterator()->shouldIterateAs(['I', 'am', 'a', 'string.']); + } + + public function it_is_initializable_with_default_delimiter(): void + { + $this->beConstructedWith('I am a string.'); + + $this->shouldHaveType(StringIterator::class); + } + + public function it_is_initializable_with_given_delimiter(): void + { + $this->beConstructedWith('I am a string.', ' '); + + $this->shouldHaveType(StringIterator::class); + } +} diff --git a/src/Iterator/MultipleIterableIterator.php b/src/Iterator/MultipleIterableIterator.php index 3f5e0dce3..f8ceb8fca 100644 --- a/src/Iterator/MultipleIterableIterator.php +++ b/src/Iterator/MultipleIterableIterator.php @@ -23,14 +23,14 @@ final class MultipleIterableIterator extends ProxyIterator { /** - * @param iterable $iterators + * @param iterable $iterables */ - public function __construct(iterable ...$iterators) + public function __construct(iterable ...$iterables) { $appendIterator = new AppendIterator(); - foreach ($iterators as $iterator) { - $appendIterator->append(new NoRewindIterator(new IterableIterator($iterator))); + foreach ($iterables as $iterable) { + $appendIterator->append(new NoRewindIterator(new IterableIterator($iterable))); } $this->iterator = $appendIterator;