Skip to content

Commit

Permalink
Added dump and dd methods to field class
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkla committed Jun 23, 2023
1 parent 3a3d816 commit 0d41707
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 13.5.0

- Added `dump` and `dd` methods to field class

## 13.4.0

- Added automatically conversion of `choices` list to associative array
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"php": "^8.1"
},
"require-dev": {
"symfony/var-dumper": "^6.3",
"phpunit/phpunit": "^10.1"
},
"minimum-stability": "dev",
Expand All @@ -40,12 +41,12 @@
"tests/helpers.php"
]
},
"config": {
"preferred-install": "dist"
"suggest": {
"symfony/var-dumper": "Required to use the dump method (^6.3)."
},
"extra": {
"branch-alias": {
"dev-master": "13.4-dev"
"dev-master": "13.5-dev"
}
}
}
10 changes: 10 additions & 0 deletions src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ public function withSettings(array $settings): static
return $this;
}

public function dump(...$args)
{
dump($this->get(), ...$args);
}

public function dd(...$args)
{
dd($this->get(), ...$args);
}

/** @internal */
public function get(string|null $parentKey = null): array
{
Expand Down
16 changes: 16 additions & 0 deletions tests/Fields/TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Extended\ACF\Fields\Text;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Symfony\Component\VarDumper\VarDumper;

class TextTest extends TestCase
{
Expand Down Expand Up @@ -144,4 +145,19 @@ public function testAppend()
$field = Text::make('Append')->append('suffix')->get();
$this->assertSame('suffix', $field['append']);
}

public function testDump()
{
$log = [];

VarDumper::setHandler(function ($value) use (&$log) {
$log[] = $value;
});

Text::make('Dump')->dump(1, 2);

$this->assertSame([['label' => 'Dump', 'name' => 'dump', 'type' => 'text', 'key' => 'field_076f7d8c'], 1, 2], $log);

VarDumper::setHandler(null);
}
}

0 comments on commit 0d41707

Please sign in to comment.