Skip to content

Commit

Permalink
Dependency update
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerdweight committed Jul 19, 2019
1 parent e24e8b4 commit 90a642e
Show file tree
Hide file tree
Showing 4 changed files with 543 additions and 819 deletions.
4 changes: 2 additions & 2 deletions RA.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ public function reduce(callable $callback, $initial = null)
*/
public function replaceRecursive(...$args): self
{
return new self(array_replace_recursive($this->data, ...$this->convertArgumentsToPlainArrays($args)));
return new self((array)array_replace_recursive($this->data, ...$this->convertArgumentsToPlainArrays($args)));
}

/**
Expand All @@ -859,7 +859,7 @@ public function replaceRecursive(...$args): self
*/
public function replace(...$args): self
{
return new self(array_replace($this->data, ...$this->convertArgumentsToPlainArrays($args)));
return new self((array)array_replace($this->data, ...$this->convertArgumentsToPlainArrays($args)));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Tests/ArrayAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testToArray(): void
'c' => ['test3', 'test4', ['test5', 'test6']],
], RA::RECURSIVE);

$this->assertInternalType('array', $regularRa['c']);
$this->assertIsArray($regularRa['c']);
$this->assertSame(RA::class, get_class($recursiveRa['c']));
$this->assertSame(
[
Expand Down
194 changes: 134 additions & 60 deletions Tests/ArrayMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,62 +344,84 @@ public function testMap(): void
public function testMergeRecursive(): void
{
$ra1 = new RA([
'a' => ['aa' => [
'a' => [
'aa' => [
'aaa' => 1,
'aab' => 2,
], [
],
[
'a0a' => 1,
'a0b' => 2,
]],
],
],
'b' => 1,
'c',
]);
$ra2 = new RA([
'a' => ['aa' => [
'a' => [
'aa' => [
'aab' => 3,
'aac' => 3,
], [
],
[
'a0a' => 2,
'a0c' => 3,
]],
'b' => ['bb' => 3],
],
],
'b' => [
'bb' => 3,
],
'd',
]);
$merged1 = $ra1->mergeRecursive($ra2);
$merged2 = $ra2->mergeRecursive($ra1);
$this->assertSame(
[
'a' => ['aa' => [
'a' => [
'aa' => [
'aaa' => 1,
'aab' => [2, 3],
'aac' => 3,
], [
],
[
'a0a' => 1,
'a0b' => 2,
], [
],
[
'a0a' => 2,
'a0c' => 3,
]],
'b' => [1, 'bb' => 3],
],
],
'b' => [
1,
'bb' => 3,
],
'c',
'd',
],
$merged1->toArray()
);
$this->assertSame(
[
'a' => ['aa' => [
'a' => [
'aa' => [
'aab' => [3, 2],
'aac' => 3,
'aaa' => 1,
], [
],
[
'a0a' => 2,
'a0c' => 3,
], [
],
[
'a0a' => 1,
'a0b' => 2,
]],
'b' => ['bb' => 3, 1],
],
],
'b' => [
'bb' => 3,
1,
],
'd',
'c',
],
Expand All @@ -410,53 +432,69 @@ public function testMergeRecursive(): void
public function testMerge(): void
{
$ra1 = new RA([
'a' => ['aa' => [
'a' => [
'aa' => [
'aaa' => 1,
'aab' => 2,
], [
],
[
'a0a' => 1,
'a0b' => 2,
]],
],
],
'b' => 1,
'c',
]);
$ra2 = new RA([
'a' => ['aa' => [
'a' => [
'aa' => [
'aab' => 3,
'aac' => 3,
], [
],
[
'a0a' => 2,
'a0c' => 3,
]],
'b' => ['bb' => 3],
],
],
'b' => [
'bb' => 3,
],
'd',
]);
$merged1 = $ra1->merge($ra2);
$merged2 = $ra2->merge($ra1);
$this->assertSame(
[
'a' => ['aa' => [
'a' => [
'aa' => [
'aab' => 3,
'aac' => 3,
], [
],
[
'a0a' => 2,
'a0c' => 3,
]],
'b' => ['bb' => 3],
],
],
'b' => [
'bb' => 3,
],
'c',
'd',
],
$merged1->toArray()
);
$this->assertSame(
[
'a' => ['aa' => [
'a' => [
'aa' => [
'aaa' => 1,
'aab' => 2,
], [
],
[
'a0a' => 1,
'a0b' => 2,
]],
],
],
'b' => 1,
'd',
'c',
Expand Down Expand Up @@ -511,56 +549,72 @@ public function testReduce(): void
public function testReplaceRecursive(): void
{
$ra1 = new RA([
'a' => ['aa' => [
'a' => [
'aa' => [
'aaa' => 1,
'aab' => 2,
], [
],
[
'a0a' => 1,
'a0b' => 2,
]],
],
],
'b' => 1,
'c',
]);
$ra2 = new RA([
'a' => ['aa' => [
'a' => [
'aa' => [
'aab' => 3,
'aac' => 3,
], [
],
[
'a0a' => 2,
'a0c' => 3,
]],
'b' => ['bb' => 3],
],
],
'b' => [
'bb' => 3,
],
'd',
]);
$replaced1 = $ra1->replaceRecursive($ra2);
$replaced2 = $ra2->replaceRecursive($ra1);
$this->assertSame(
[
'a' => ['aa' => [
'a' => [
'aa' => [
'aaa' => 1,
'aab' => 3,
'aac' => 3,
], [
],
[
'a0a' => 2,
'a0b' => 2,
'a0c' => 3,
]],
'b' => ['bb' => 3],
],
],
'b' => [
'bb' => 3,
],
'd',
],
$replaced1->toArray()
);
$this->assertSame(
[
'a' => ['aa' => [
'a' => [
'aa' => [
'aab' => 2,
'aac' => 3,
'aaa' => 1,
], [
],
[
'a0a' => 1,
'a0c' => 3,
'a0b' => 2,
]],
],
],
'b' => 1,
'c',
],
Expand All @@ -571,52 +625,68 @@ public function testReplaceRecursive(): void
public function testReplace(): void
{
$ra1 = new RA([
'a' => ['aa' => [
'a' => [
'aa' => [
'aaa' => 1,
'aab' => 2,
], [
],
[
'a0a' => 1,
'a0b' => 2,
]],
],
],
'b' => 1,
'c',
]);
$ra2 = new RA([
'a' => ['aa' => [
'a' => [
'aa' => [
'aab' => 3,
'aac' => 3,
], [
],
[
'a0a' => 2,
'a0c' => 3,
]],
'b' => ['bb' => 3],
],
],
'b' => [
'bb' => 3,
],
'd',
]);
$replaced1 = $ra1->replace($ra2);
$replaced2 = $ra2->replace($ra1);
$this->assertSame(
[
'a' => ['aa' => [
'a' => [
'aa' => [
'aab' => 3,
'aac' => 3,
], [
],
[
'a0a' => 2,
'a0c' => 3,
]],
'b' => ['bb' => 3],
],
],
'b' => [
'bb' => 3,
],
'd',
],
$replaced1->toArray()
);
$this->assertSame(
[
'a' => ['aa' => [
'a' => [
'aa' => [
'aaa' => 1,
'aab' => 2,
], [
],
[
'a0a' => 1,
'a0b' => 2,
]],
],
],
'b' => 1,
'c',
],
Expand Down Expand Up @@ -808,7 +878,11 @@ public function testValues(): void

public function testWalkRecursive(): void
{
$ra = new RA(['a', 'b', 'c' => ['test1', 'test2']]);
$ra = new RA([
'a',
'b',
'c' => ['test1', 'test2'],
]);
$output = new RA();
$ra->walkRecursive(function ($entry, $key, $payload) use ($output) {
$output->push($entry . $payload . $key);
Expand Down
Loading

0 comments on commit 90a642e

Please sign in to comment.