Skip to content

Commit

Permalink
add dump & dd methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gwleuverink committed Aug 26, 2024
1 parent e400365 commit 972c5f4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ $this->group('a')->validate(); // validates all properties in a group
$this->group(['a', 'b']); // operations can be applied to any number of groups
$this->group(['a', 'b'])->validate(); // especially handy when validating

$this->group('a')->dump();
$this->group('a')->dd();
```

## Development
Expand Down
20 changes: 20 additions & 0 deletions src/PropertyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
use ArrayIterator;
use IteratorAggregate;
use Livewire\Component;
use Illuminate\Support\Traits\Dumpable;

class PropertyCollection implements ArrayAccess, IteratorAggregate
{
use Dumpable;

final public function __construct(
private readonly Component $component,
private array $items = []
Expand Down Expand Up @@ -79,6 +82,23 @@ public function validate()
return $this->component->validate($rules);
}

/*
|--------------------------------------------------------------------------
| dump & dd
|--------------------------------------------------------------------------
*/
public function dump(): self
{
dump($this->items);

return $this;
}

public function dd(): never
{
dd($this->items);
}

/*
|--------------------------------------------------------------------------
| ArrayAccess/Iterator methods
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/MacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Tests\TestComponent;
use Leuverink\PropertyAttribute\Group;
use Leuverink\PropertyAttribute\PropertyCollection;

use function Leuverink\PropertyAttribute\group;

Expand Down Expand Up @@ -94,3 +95,8 @@

expect($result)->toBeArray();
});

arch('it is dumpable')
->expect(PropertyCollection::class)
->toHaveMethod('dump')
->toHaveMethod('dd');

0 comments on commit 972c5f4

Please sign in to comment.