-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from stellarwp/bugfix/undot
Fix & Add Tests for Arr::undot()
- Loading branch information
Showing
2 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
use StellarWP\Arrays\Arr; | ||
use StellarWP\Arrays\Tests\ArraysTestCase; | ||
|
||
class UndotTest extends ArraysTestCase | ||
{ | ||
|
||
public function setUp() | ||
{ | ||
// before | ||
parent::setUp(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_properly_expands_array() | ||
{ | ||
$dotted = [ | ||
'one.two.three.five.eight' => 'fibonacci', | ||
]; | ||
|
||
$expected = [ | ||
'one' => [ | ||
'two' => [ | ||
'three' => [ | ||
'five' => [ | ||
'eight' => 'fibonacci' | ||
] | ||
] | ||
] | ||
], | ||
]; | ||
|
||
$this->assertSame($expected, Arr::undot($dotted)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_expands_array_with_leaves() | ||
{ | ||
$dotted = [ | ||
'one.first_leaf' => true, | ||
'one.two.second_leaf' => true, | ||
'one.two.three.third_leaf' => true, | ||
'one.two.three.five.fifth_leaf' => true, | ||
'one.two.three.five.eight' => 'fibonacci', | ||
]; | ||
|
||
$expected = [ | ||
'one' => [ | ||
'first_leaf' => true, | ||
'two' => [ | ||
'second_leaf' => true, | ||
'three' => [ | ||
'third_leaf' => true, | ||
'five' => [ | ||
'fifth_leaf' => true, | ||
'eight' => 'fibonacci' | ||
] | ||
] | ||
] | ||
], | ||
]; | ||
|
||
$this->assertSame($expected, Arr::undot($dotted)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_expands_nested_arrays_with_numerical_keys() | ||
{ | ||
$dotted = [ | ||
'first_array.0' => 'bacon', | ||
'first_array.1' => 'ham', | ||
'first_array.2' => 'cheese', | ||
'second_array.0' => 'bacon', | ||
'second_array.1' => 'egg', | ||
'second_array.2' => 'cheese', | ||
]; | ||
|
||
$expected = [ | ||
'first_array' => [ | ||
'bacon', | ||
'ham', | ||
'cheese', | ||
], | ||
'second_array' => [ | ||
'bacon', | ||
'egg', | ||
'cheese' | ||
] | ||
]; | ||
|
||
$this->assertSame($expected, Arr::undot($dotted)); | ||
} | ||
} |