-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: override push, also write tests for pull/push
- Loading branch information
Artem Pakhomov
committed
Aug 28, 2021
1 parent
3a1f62c
commit a869648
Showing
5 changed files
with
244 additions
and
37 deletions.
There are no files selected for viewing
File renamed without changes.
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
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,65 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Codeception\Test\Unit; | ||
use Setnemo\Asterisk; | ||
|
||
/** | ||
* Class PullTest | ||
*/ | ||
class PullTest extends Unit | ||
{ | ||
/** | ||
* @dataProvider pullWithStar() | ||
*/ | ||
public function testGet(array $example): void | ||
{ | ||
$asterisk = new Asterisk($example['constructor']); | ||
|
||
$this->assertEquals($example['expected_pull'], $asterisk->pull($example['keys'])); | ||
$this->assertEquals($example['expected_all'], $asterisk->all()); | ||
} | ||
|
||
public function pullWithStar(): array | ||
{ | ||
return [ | ||
/* #0 */ [[ | ||
'constructor' => ['1' => ['second' => 'value'],'2' => ['second' => 'value']], | ||
'expected_pull' => ['1.second' => 'value', '2.second' => 'value',], | ||
'expected_all' => ['1' => [], '2' => [], ], | ||
'keys' => '*.second', | ||
]], | ||
/* #1 */ [[ | ||
'constructor' => ['1' => ['first' => ['value' => 42]],'2' => ['second' => 'value'],'3' => ['third' => ['value' => 42]]], | ||
'expected_pull' => ['1.first.value' => 42, '3.third.value' => 42,], | ||
'expected_all' => ['1' => ['first' => []], '2' => ['second' => 'value'], '3' => ['third' => []], ], | ||
'keys' => '*.*.value', | ||
]], | ||
/* #2 */ [[ | ||
'constructor' => ['1' => ['first' => ['value' => 42]],'2' => ['second' => 'value'],'3' => ['third' => ['value' => 42]]], | ||
'expected_pull' => 42, | ||
'expected_all' => ['1' => ['first' => ['value' => 42]],'2' => ['second' => 'value'],'3' => ['third' => []]], | ||
'keys' => '3.third.value', | ||
]], | ||
/* #3 */ [[ | ||
'constructor' => ['user1' => ['name' => 'John', 'job' => 'warrior'], 'user2' => ['name' => 'Robin', 'job' => 'archer'],], | ||
'expected_pull' => null, | ||
'expected_all' => ['user1' => ['name' => 'John', 'job' => 'warrior'], 'user2' => ['name' => 'Robin', 'job' => 'archer'],], | ||
'keys' => '3.third.value', | ||
]], | ||
/* #4 */ [[ | ||
'constructor' => ['user1' => ['name' => 'John', 'job' => 'warrior'], 'user2' => ['name' => 'Robin', 'job' => 'archer'],], | ||
'expected_pull' => ['user1.name' => 'John', 'user2.name' => 'Robin'], | ||
'expected_all' => ['user1' => ['job' => 'warrior'], 'user2' => ['job' => 'archer'],], | ||
'keys' => '*.name', | ||
]], | ||
/* #5 */ [[ | ||
'constructor' => ['user1' => ['name' => 'John', 'job' => 'warrior'], 'user2' => ['name' => 'Robin', 'job' => 'archer'],], | ||
'expected_pull' => null, | ||
'expected_all' => ['user1' => ['name' => 'John', 'job' => 'warrior'], 'user2' => ['name' => 'Robin', 'job' => 'archer'],], | ||
'keys' => '*.spouse', | ||
]], | ||
]; | ||
} | ||
} |
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,79 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Codeception\Test\Unit; | ||
use Setnemo\Asterisk; | ||
|
||
/** | ||
* Class PushTest | ||
*/ | ||
class PushTest extends Unit | ||
{ | ||
/** | ||
* @dataProvider pushWithStar() | ||
*/ | ||
public function testSet(array $example): void | ||
{ | ||
$asterisk = new Asterisk($example['constructor']); | ||
$asterisk->push($example['keys'], $example['value']); | ||
|
||
$this->assertEquals($example['expected'], $asterisk->all()); | ||
} | ||
|
||
public function pushWithStar(): array | ||
{ | ||
return [ | ||
/* #0 */ [['constructor' => [], 'expected' => [ | ||
'*' => ['second' => ['VALUE']], | ||
], 'keys' => '*.second', 'value' => 'VALUE']], | ||
/* #1 */ [['constructor' => [ | ||
'first_one' => ['second' => 'value'], | ||
'first_two' => ['second' => 'value'] | ||
], 'expected' => [ | ||
'first_one' => ['second' => ['value','VALUE']], | ||
'first_two' => ['second' => ['value','VALUE']] | ||
], 'keys' => '*.second', 'value' => 'VALUE']], | ||
/* #2 */ [['constructor' => [ | ||
'first_one' => ['second2' => 'value'], | ||
'first_two' => ['second' => 'value'] | ||
], 'expected' => [ | ||
'first_one' => ['second2' => 'value', 'second' => ['VALUE']], | ||
'first_two' => ['second' => ['value','VALUE']] | ||
], 'keys' => '*.second', 'value' => 'VALUE']], | ||
/* #3 */ [['constructor' => [ | ||
'first_one' => ['second' => [ | ||
'third_one' => ['fourth' => ['value']], | ||
'third_two' => ['fourth' => ['value']], | ||
], 'second2' => [ | ||
'third_one' => ['fourth' => 'value'], | ||
'third_two' => ['fourth' => 'value'], | ||
], | ||
], | ||
'first_two' => ['second' => [ | ||
'third_one' => [], | ||
'third_two' => ['fourth' => 'value'], | ||
], 'second2' => [ | ||
'third_one' => ['fourth2' => 'value'], | ||
], | ||
], | ||
], 'expected' => [ | ||
'first_one' => ['second' => [ | ||
'third_one' => ['fourth' => ['value','VALUE']], | ||
'third_two' => ['fourth' => ['value','VALUE']], | ||
], 'second2' => [ | ||
'third_one' => ['fourth' => 'value'], | ||
'third_two' => ['fourth' => 'value'], | ||
], | ||
], | ||
'first_two' => ['second' => [ | ||
'third_one' => [], | ||
'third_two' => ['fourth' => ['value','VALUE']], | ||
], 'second2' => [ | ||
'third_one' => ['fourth2' => 'value'], | ||
], | ||
], | ||
], 'keys' => '*.second.*.fourth', 'value' => 'VALUE']], | ||
]; | ||
} | ||
} |