Skip to content

Commit 6333610

Browse files
committed
new tests added, error test renamed.
1 parent 5c71355 commit 6333610

File tree

2 files changed

+74
-5
lines changed

2 files changed

+74
-5
lines changed

tests/unit/ArrayView/NonSequentialErrorTest.php renamed to tests/unit/ArrayView/ErrorsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Smoren\ArrayView\Exceptions\ValueError;
66
use Smoren\ArrayView\Views\ArrayView;
77

8-
class NonSequentialErrorTest extends \Codeception\Test\Unit
8+
class ErrorsTest extends \Codeception\Test\Unit
99
{
1010
/**
1111
* @dataProvider dataProviderForNonSequentialError

tests/unit/ArrayView/WriteTest.php

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
namespace Smoren\ArrayView\Tests\Unit\ArrayView;
44

5-
use Smoren\ArrayView\Exceptions\ValueError;
65
use Smoren\ArrayView\Selectors\IndexListSelector;
76
use Smoren\ArrayView\Selectors\MaskSelector;
87
use Smoren\ArrayView\Selectors\SliceSelector;
98
use Smoren\ArrayView\Structs\Slice;
10-
use Smoren\ArrayView\Views\ArrayIndexListView;
11-
use Smoren\ArrayView\Views\ArrayMaskView;
12-
use Smoren\ArrayView\Views\ArraySliceView;
139
use Smoren\ArrayView\Views\ArrayView;
1410

1511
class WriteTest extends \Codeception\Test\Unit
@@ -132,6 +128,21 @@ public function testWriteBySlice(array $source, callable $viewGetter, $toWrite,
132128
$this->assertSame($expected, $source);
133129
}
134130

131+
/**
132+
* @dataProvider dataProviderForApply
133+
*/
134+
public function testApply(array $source, callable $viewGetter, callable $mapper, array $expected)
135+
{
136+
// Given
137+
$view = $viewGetter($source);
138+
139+
// When
140+
$view->apply($mapper);
141+
142+
// Then
143+
$this->assertSame($expected, $source);
144+
}
145+
135146
public function dataProviderForArrayWrite(): array
136147
{
137148
return [
@@ -257,4 +268,62 @@ public function dataProviderForWriteCombine(): array
257268
],
258269
];
259270
}
271+
272+
public function dataProviderForApply(): array
273+
{
274+
return [
275+
[
276+
[],
277+
fn (array &$source) => ArrayView::toView($source),
278+
fn (int $item) => $item + 1,
279+
[],
280+
],
281+
[
282+
[1],
283+
fn (array &$source) => ArrayView::toView($source),
284+
fn (int $item) => $item + 1,
285+
[2],
286+
],
287+
[
288+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
289+
fn (array &$source) => ArrayView::toView($source),
290+
fn (int $item) => $item,
291+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
292+
],
293+
[
294+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
295+
fn (array &$source) => ArrayView::toView($source),
296+
fn (int $item) => $item + 1,
297+
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
298+
],
299+
[
300+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
301+
fn (array &$source) => ArrayView::toView($source),
302+
fn (int $item, int $index) => $item + $index,
303+
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19],
304+
],
305+
[
306+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
307+
fn (array &$source) => ArrayView::toView($source)
308+
->subview('::2'),
309+
fn (int $item, int $index) => $item + $index,
310+
[1, 2, 4, 4, 7, 6, 10, 8, 13, 10],
311+
],
312+
[
313+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
314+
fn (array &$source) => ArrayView::toView($source)
315+
->subview('1::2'),
316+
fn (int $item) => $item * 2,
317+
[1, 4, 3, 8, 5, 12, 7, 16, 9, 20],
318+
],
319+
[
320+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
321+
fn (array &$source) => ArrayView::toView($source)
322+
->subview('1::2')
323+
->subview(new IndexListSelector([0, 1, 2])),
324+
fn (int $item) => $item * 2,
325+
[1, 4, 3, 8, 5, 12, 7, 8, 9, 10],
326+
],
327+
];
328+
}
260329
}

0 commit comments

Comments
 (0)