forked from codeigniter4/CodeIgniter4
-
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.
fix: multiple check column/keys from array
- Loading branch information
Showing
6 changed files
with
160 additions
and
93 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
D:/Project/laragon/www/ci4/app/Common.php |
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 @@ | ||
D:/Project/laragon/www/ci4/app/Language |
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 |
---|---|---|
|
@@ -24,45 +24,65 @@ final class ArrayHelperDuplicateCheckTest extends CIUnitTestCase | |
{ | ||
private array $array = [ | ||
[ | ||
'name' => 'Fred Flinstone', | ||
'age' => 20, | ||
'provider_name' => 'Rumah Sakit Siloam', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.71', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'name' => 'Brad Pierce', | ||
'age' => 30, | ||
'provider_name' => 'Rumah Sakit Silorm', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.72', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'name' => 'Fred Flinstone', | ||
'age' => 70, | ||
'provider_name' => 'Rumah Sakit Siloam', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.71', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'name' => 'Michelle Stone', | ||
'age' => 30, | ||
'provider_name' => 'Rumah Sakit Siloum', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.74', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'name' => 'Michael Bram', | ||
'age' => 40, | ||
'provider_name' => 'Rumah Sakit Siloem', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.75', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'provider_name' => 'Rumah Sakit Silosm', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.76', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
]; | ||
|
||
public function testSingleColumn(): void | ||
{ | ||
$this->assertSame([ | ||
2 => [ | ||
'name' => 'Fred Flinstone', | ||
'provider_name' => 'Rumah Sakit Siloam', | ||
], | ||
], ArrayHelper::arrayDuplicatesBy('name', $this->array)); | ||
], ArrayHelper::duplicatesBy('provider_name', $this->array)); | ||
} | ||
|
||
public function testMultipleColumn(): void | ||
{ | ||
$this->assertSame([ | ||
2 => [ | ||
'name' => 'Fred Flinstone', | ||
], | ||
3 => [ | ||
'age' => 30, | ||
'provider_name' => 'Rumah Sakit Siloam', | ||
'provider_region' => '31.71', | ||
], | ||
], ArrayHelper::arrayDuplicatesBy(['name', 'age'], $this->array)); | ||
], ArrayHelper::duplicatesBy(['provider_name', 'provider_region'], $this->array)); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -1291,73 +1291,119 @@ public static function provideArrayGroupByExcludeEmpty(): iterable | |
/** | ||
* @dataProvider provideArrayDuplicate | ||
* | ||
* @param mixed $column | ||
* @param array|string $key Key(s) to Check | ||
*/ | ||
public function testArrayDuplicate($column, array $data, array $expected): void | ||
public function testArrayDuplicate($key, array $data, array $expected): void | ||
{ | ||
$this->assertSame($expected, array_duplicate_by($column, $data)); | ||
$this->assertSame($expected, array_duplicate_by($key, $data)); | ||
} | ||
|
||
public static function provideArrayDuplicate(): iterable | ||
{ | ||
yield 'single and multiple' => [ | ||
'name', // Single | ||
[ | ||
[ | ||
'name' => 'Fred Flinstone', | ||
'age' => 20, | ||
], | ||
[ | ||
'name' => 'Brad Pierce', | ||
'age' => 30, | ||
], | ||
[ | ||
'name' => 'Fred Flinstone', | ||
'age' => 70, | ||
], | ||
yield from [ | ||
'single' => [ | ||
'provider_name', // Single | ||
[ | ||
'name' => 'Michelle Stone', | ||
'age' => 30, | ||
[ | ||
'provider_name' => 'Rumah Sakit Siloam', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.71', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'provider_name' => 'Rumah Sakit Silorm', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.72', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'provider_name' => 'Rumah Sakit Siloam', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.71', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'provider_name' => 'Rumah Sakit Siloum', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.74', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'provider_name' => 'Rumah Sakit Siloem', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.75', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'provider_name' => 'Rumah Sakit Silosm', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.76', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
], | ||
[ | ||
'name' => 'Michael Bram', | ||
'age' => 40, | ||
], | ||
], | ||
[ | ||
2 => [ | ||
'name' => 'Fred Flinstone', | ||
2 => [ | ||
'provider_name' => 'Rumah Sakit Siloam', | ||
], | ||
], | ||
], | ||
['name', 'age'], // Multiple | ||
[ | ||
'multiple' => [ | ||
['provider_name', 'provider_region'], // Multiple | ||
[ | ||
'name' => 'Fred Flinstone', | ||
'age' => 20, | ||
], | ||
[ | ||
'name' => 'Brad Pierce', | ||
'age' => 30, | ||
], | ||
[ | ||
'name' => 'Fred Flinstone', | ||
'age' => 70, | ||
], | ||
[ | ||
'name' => 'Michelle Stone', | ||
'age' => 30, | ||
[ | ||
'provider_name' => 'Rumah Sakit Siloam', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.71', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'provider_name' => 'Rumah Sakit Silorm', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.72', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'provider_name' => 'Rumah Sakit Siloam', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.71', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'provider_name' => 'Rumah Sakit Siloum', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.74', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'provider_name' => 'Rumah Sakit Siloem', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.75', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
[ | ||
'provider_name' => 'Rumah Sakit Silosm', | ||
'provider_email' => '[email protected]', | ||
'provider_website' => 'example.com', | ||
'provider_region' => '31.76', | ||
'provider_address' => 'wwaasawdasa', | ||
], | ||
], | ||
[ | ||
'name' => 'Michael Bram', | ||
'age' => 40, | ||
], | ||
], | ||
[ | ||
2 => [ | ||
'name' => 'Fred Flinstone', | ||
], | ||
3 => [ | ||
'age' => 30, | ||
2 => [ | ||
'provider_name' => 'Rumah Sakit Siloam', | ||
'provider_region' => '31.71', | ||
], | ||
], | ||
], | ||
]; | ||
|