forked from statamic/cms
-
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.
- Loading branch information
1 parent
e207d98
commit 163e985
Showing
2 changed files
with
44 additions
and
21 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
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,44 @@ | ||
<?php | ||
|
||
namespace Modifiers; | ||
|
||
use PHPUnit\Framework\Attributes\Group; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Modifiers\Modify; | ||
use Statamic\Support\Arr; | ||
use Tests\TestCase; | ||
|
||
#[Group('array')] | ||
class WhereInTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_filters_data_by_key_and_multiple_values(): void | ||
{ | ||
$collection = [ | ||
['product' => 'Desk', 'price' => 200], | ||
['product' => 'Chair', 'price' => 100], | ||
['product' => 'Bookcase', 'price' => 150], | ||
['product' => 'Door', 'price' => 100], | ||
]; | ||
$modified = $this->modify($collection, ['price', [150, 200]]); | ||
$this->assertEquals(['Desk', 'Bookcase'], Arr::pluck($modified, 'product')); | ||
} | ||
|
||
#[Test] | ||
public function it_filters_data_by_key_and_single_value(): void | ||
{ | ||
$collection = [ | ||
['product' => 'Desk', 'price' => 200], | ||
['product' => 'Chair', 'price' => 100], | ||
['product' => 'Bookcase', 'price' => 150], | ||
['product' => 'Door', 'price' => 100], | ||
]; | ||
$modified = $this->modify($collection, ['price', 100]); | ||
$this->assertEquals(['Chair', 'Door'], Arr::pluck($modified, 'product')); | ||
} | ||
|
||
private function modify($value, array $params) | ||
{ | ||
return Modify::value($value)->whereIn($params)->fetch(); | ||
} | ||
} |