Skip to content

Commit

Permalink
Update code style using latest version of drupol/drupal-conventions.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Aug 15, 2019
1 parent b78b672 commit ad60162
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 61 deletions.
126 changes: 78 additions & 48 deletions spec/drupol/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function it_can_append_items(): void
public function it_can_apply(): void
{
$this
->beConstructedThrough('with', [range(1, 10)]);
->beConstructedThrough('with', [\range(1, 10)]);

$this
->apply(static function ($item) {
Expand All @@ -48,7 +48,9 @@ public function it_can_apply(): void
})
->shouldReturn($this);

$callback = static function (): void {throw new \Exception('foo'); };
$callback = static function (): void {
throw new \Exception('foo');
};

$this
->shouldThrow(\Exception::class)
Expand Down Expand Up @@ -98,18 +100,20 @@ public function it_can_apply(): void
return $item;
};

$this::withArray(range(1, 20))
$this::withArray(\range(1, 20))
->apply($applyCallback1)
->walk($walkCallback2)
->filter(static function ($item) {return false !== $item; })
->filter(static function ($item) {
return false !== $item;
})
->all()
->shouldReturn($context);
}

public function it_can_be_constructed_from_array(): void
{
$this
->beConstructedThrough('withArray', [range('A', 'E')]);
->beConstructedThrough('withArray', [\range('A', 'E')]);

$this
->all()
Expand All @@ -129,7 +133,9 @@ public function it_can_be_constructed_from_empty(): void
public function it_can_be_constructed_with_a_closure(): void
{
$this
->beConstructedThrough('with', [static function () {yield from range(1, 3); }]);
->beConstructedThrough('with', [static function () {
yield from \range(1, 3);
}]);
$this->shouldImplement(CollectionInterface::class);
}

Expand Down Expand Up @@ -181,11 +187,13 @@ public function it_can_be_returned_as_an_array(): void
public function it_can_chunk(): void
{
$this
->beConstructedThrough('with', [range('A', 'F')]);
->beConstructedThrough('with', [\range('A', 'F')]);

$this
->chunk(2)
->map(static function (CollectionInterface $item) {return implode('', iterator_to_array($item)); })
->map(static function (CollectionInterface $item) {
return \implode('', \iterator_to_array($item));
})
->all()
->shouldReturn(['AB', 'CD', 'EF']);

Expand All @@ -196,15 +204,17 @@ public function it_can_chunk(): void

$this
->chunk(1)
->map(static function (CollectionInterface $item) {return implode('', iterator_to_array($item)); })
->map(static function (CollectionInterface $item) {
return \implode('', \iterator_to_array($item));
})
->all()
->shouldReturn(['A', 'B', 'C', 'D', 'E', 'F']);
}

public function it_can_collapse(): void
{
$this
->beConstructedThrough('with', [range('A', 'J')]);
->beConstructedThrough('with', [\range('A', 'J')]);

$this
->chunk(2)
Expand All @@ -216,14 +226,14 @@ public function it_can_collapse(): void
public function it_can_combine(): void
{
$this
->beConstructedThrough('with', [range('A', 'E')]);
->beConstructedThrough('with', [\range('A', 'E')]);

$this
->combine(range('e', 'a'))
->combine(\range('e', 'a'))
->shouldIterateAs(['e' => 'A', 'd' => 'B', 'c' => 'C', 'b' => 'D', 'a' => 'E']);

$this
->combine(range(1, 100))
->combine(\range(1, 100))
->shouldThrow(\Exception::class)
->during('all');
}
Expand All @@ -240,7 +250,7 @@ public function it_can_convert_use_a_string_as_parameter(): void
public function it_can_count_its_items(): void
{
$this
->beConstructedThrough('with', [range('A', 'C')]);
->beConstructedThrough('with', [\range('A', 'C')]);

$this
->count()
Expand All @@ -249,12 +259,14 @@ public function it_can_count_its_items(): void

public function it_can_filter_its_element(): void
{
$input = array_merge([0, false], range(1, 10));
$input = \array_merge([0, false], \range(1, 10));

$this
->beConstructedThrough('with', [$input]);

$callable = static function ($item) {return $item % 2; };
$callable = static function ($item) {
return $item % 2;
};

$this
->filter($callable)
Expand Down Expand Up @@ -287,15 +299,15 @@ public function it_can_flatten(): void
$input[] = $items;
}

$input = array_pad([], 5, $input);
$input = \array_pad([], 5, $input);

$this
->beConstructedThrough('with', [$input]);

$output = [];

for ($i = 0; 5 > $i; ++$i) {
$output = array_merge($output, range(0, 9));
$output = \array_merge($output, \range(0, 9));
}

$this
Expand Down Expand Up @@ -323,7 +335,7 @@ public function it_can_flatten(): void
public function it_can_flip(): void
{
$this
->beConstructedThrough('with', [range('A', 'E')]);
->beConstructedThrough('with', [\range('A', 'E')]);

$this
->flip()
Expand All @@ -334,7 +346,7 @@ public function it_can_flip(): void
public function it_can_forget(): void
{
$this
->beConstructedThrough('with', [range('A', 'E')]);
->beConstructedThrough('with', [\range('A', 'E')]);

$this
->forget(0, 4)
Expand All @@ -346,7 +358,7 @@ public function it_can_forget(): void
public function it_can_get(): void
{
$this
->beConstructedThrough('with', [range('A', 'E')]);
->beConstructedThrough('with', [\range('A', 'E')]);

$this
->get(4)
Expand All @@ -360,7 +372,7 @@ public function it_can_get(): void
public function it_can_get_items_with_only_specific_keys(): void
{
$this
->beConstructedThrough('with', [range('A', 'E')]);
->beConstructedThrough('with', [\range('A', 'E')]);

$this
->only(0, 1, 3)
Expand All @@ -376,7 +388,7 @@ public function it_can_get_items_with_only_specific_keys(): void
public function it_can_get_its_first_value(): void
{
$this
->beConstructedThrough('with', [range(1, 10)]);
->beConstructedThrough('with', [\range(1, 10)]);

$this
->first()
Expand Down Expand Up @@ -407,17 +419,17 @@ static function ($value) {
public function it_can_keys(): void
{
$this
->beConstructedThrough('with', [range('A', 'E')]);
->beConstructedThrough('with', [\range('A', 'E')]);

$this
->keys()
->shouldIterateAs(range(0, 4));
->shouldIterateAs(\range(0, 4));
}

public function it_can_limit(): void
{
$this
->beConstructedThrough('with', [range('A', 'F')]);
->beConstructedThrough('with', [\range('A', 'F')]);

$this
->limit(3)
Expand All @@ -430,23 +442,27 @@ public function it_can_limit(): void

public function it_can_map(): void
{
$input = array_combine(range('A', 'E'), range('A', 'E'));
$input = \array_combine(\range('A', 'E'), \range('A', 'E'));

$this
->beConstructedThrough('with', [$input]);

$this
->map(static function (string $item) {return $item . $item; })
->map(static function (string $item) {
return $item . $item;
})
->all()
->shouldReturn([0 => 'AA', 1 => 'BB', 2 => 'CC', 3 => 'DD', 4 => 'EE']);
}

public function it_can_merge(): void
{
$this
->beConstructedThrough('with', [range('A', 'E')]);
->beConstructedThrough('with', [\range('A', 'E')]);

$collection = Collection::with(static function () {yield from range('F', 'J'); });
$collection = Collection::with(static function () {
yield from \range('F', 'J');
});

$this
->merge($collection->all())
Expand All @@ -458,7 +474,7 @@ public function it_can_merge(): void
public function it_can_nth(): void
{
$this
->beConstructedThrough('with', [range(0, 70)]);
->beConstructedThrough('with', [\range(0, 70)]);

$this
->nth(7)
Expand All @@ -471,7 +487,7 @@ public function it_can_nth(): void

public function it_can_pad(): void
{
$input = array_combine(range('A', 'E'), range('A', 'E'));
$input = \array_combine(\range('A', 'E'), \range('A', 'E'));

$this
->beConstructedThrough('with', [$input]);
Expand All @@ -485,7 +501,7 @@ public function it_can_pad(): void
public function it_can_prepend(): void
{
$this
->beConstructedThrough('with', [range('D', 'F')]);
->beConstructedThrough('with', [\range('D', 'F')]);

$this
->prepend('A', 'B', 'C')
Expand All @@ -497,10 +513,12 @@ public function it_can_prepend(): void
public function it_can_reduce(): void
{
$this
->beConstructedThrough('with', [range(1, 100)]);
->beConstructedThrough('with', [\range(1, 100)]);

$this
->reduce(static function ($carry, $item) {return $carry + $item; }, 0)
->reduce(static function ($carry, $item) {
return $carry + $item;
}, 0)
->shouldReturn(5050);
}

Expand All @@ -518,7 +536,7 @@ public function it_can_run_an_operation(Operation $operation): void
public function it_can_skip(): void
{
$this
->beConstructedThrough('with', [range('A', 'F')]);
->beConstructedThrough('with', [\range('A', 'F')]);

$this
->skip(3)
Expand All @@ -534,7 +552,7 @@ public function it_can_skip(): void
public function it_can_slice(): void
{
$this
->beConstructedThrough('with', [range(0, 10)]);
->beConstructedThrough('with', [\range(0, 10)]);

$this
->slice(5)
Expand Down Expand Up @@ -582,7 +600,9 @@ public function it_can_use_range_with_value_1(): void
public function it_can_use_times_with_a_callback(): void
{
$this
->beConstructedThrough('times', [2, static function () {return range(1, 5); }]);
->beConstructedThrough('times', [2, static function () {
return \range(1, 5);
}]);

$a = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]];

Expand All @@ -598,7 +618,7 @@ public function it_can_use_times_without_a_callback(): void

$this
->all()
->shouldReturn(range(1, 10));
->shouldReturn(\range(1, 10));

$this::times(-5)
->all()
Expand All @@ -611,30 +631,40 @@ public function it_can_use_times_without_a_callback(): void

public function it_can_walk(): void
{
$input = array_combine(range('A', 'E'), range('A', 'E'));
$input = \array_combine(\range('A', 'E'), \range('A', 'E'));

$this
->beConstructedThrough('with', [$input]);

$this
->walk(static function (string $item) {return $item . $item; })
->walk(static function (string $item) {
return $item . $item;
})
->all()
->shouldReturn(['A' => 'AA', 'B' => 'BB', 'C' => 'CC', 'D' => 'DD', 'E' => 'EE']);

$this::withArray(range(1, 10))
->walk(static function ($item) {return $item * 2; }, static function ($item) {return $item + 1; })
$this::withArray(\range(1, 10))
->walk(static function ($item) {
return $item * 2;
}, static function ($item) {
return $item + 1;
})
->all()
->shouldReturn(range(3, 21, 2));
->shouldReturn(\range(3, 21, 2));

$this::withArray(range(1, 10))
->walk(static function ($item) {return $item; }, static function ($item) {return $item; })
->shouldIterateAs(range(1, 10));
$this::withArray(\range(1, 10))
->walk(static function ($item) {
return $item;
}, static function ($item) {
return $item;
})
->shouldIterateAs(\range(1, 10));
}

public function it_can_zip(): void
{
$this
->beConstructedThrough('with', [range('A', 'C')]);
->beConstructedThrough('with', [\range('A', 'C')]);

$this
->zip('D', 'E', 'F')
Expand Down
Loading

0 comments on commit ad60162

Please sign in to comment.