Skip to content
Permalink
Browse files

Add FluentArray.getDuplicates() and FluentArray.getDuplicatesAssoc()

  • Loading branch information...
Danon committed Nov 3, 2019
1 parent 77880b7 commit 8066d8799eda99561c4dc9814f2b958b1e35ac6f
Showing with 43 additions and 1 deletion.
  1. +12 −0 src/Ouzo/Goodies/Utilities/FluentArray.php
  2. +31 −1 test/src/Ouzo/Goodies/Utilities/FluentArrayTest.php
@@ -164,4 +164,16 @@ public function skip($number)
$this->_array = array_slice($this->_array, $number);
return $this;
}
public function getDuplicates()
{
$this->_array = Arrays::getDuplicates($this->_array);
return $this;
}
public function getDuplicatesAssoc()
{
$this->_array = Arrays::getDuplicatesAssoc($this->_array);
return $this;
}
}
@@ -10,7 +10,7 @@
use Ouzo\Utilities\FluentArray;
use Ouzo\Utilities\Functions;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestCase;
class FluentArrayTest extends TestCase
{
@@ -318,4 +318,34 @@ public function shouldExecuteForEach()
//then
$this->assertEquals(['a' , 'b' , 'c' ], $newArray);
}
/**
* @test
*/
public function shouldGetDuplicates()
{
//given
$array = ['a', 'b', 'c', 'b', 'c', 'b'];
//when
$result = FluentArray::from($array)->getDuplicates()->toArray();
//then
$this->assertEquals(['b', 'c'], $result);
}
/**
* @test
*/
public function shouldGetDuplicatesAssoc()
{
//given
$array = ['a', 'b', 'd', 'c', 'b', 'c', 'b'];
//when
$result = FluentArray::from($array)->getDuplicatesAssoc()->toArray();
//then
$this->assertEquals([1 => 'b', 3 => 'c'], $result);
}
}

0 comments on commit 8066d87

Please sign in to comment.
You can’t perform that action at this time.