-
-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jason Varga <[email protected]>
- Loading branch information
1 parent
d6c6395
commit 9745141
Showing
2 changed files
with
44 additions
and
0 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,31 @@ | ||
<?php | ||
|
||
namespace Tests\Modifiers; | ||
|
||
use PHPUnit\Framework\Attributes\Group; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Modifiers\Modify; | ||
use Tests\TestCase; | ||
|
||
#[Group('array')] | ||
class FilterEmptyTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_removes_null_values_from_an_array(): void | ||
{ | ||
$modified = $this->modify(['one' => 'one', null, 'two' => 'two', 'three' => null, 'four' => 'four']); | ||
$this->assertEquals(['one' => 'one', 'two' => 'two', 'four' => 'four'], $modified); | ||
} | ||
|
||
#[Test] | ||
public function it_removes_null_values_from_a_collection(): void | ||
{ | ||
$modified = $this->modify(collect(['one' => 'one', null, 'two' => 'two', 'three' => null, 'four' => 'four'])); | ||
$this->assertEquals(['one' => 'one', 'two' => 'two', 'four' => 'four'], $modified->all()); | ||
} | ||
|
||
private function modify($value, $params = []) | ||
{ | ||
return Modify::value($value)->filterEmpty($params)->fetch(); | ||
} | ||
} |